Skip to content

Commit de895bd

Browse files
authored
Merge pull request #2500 from mgorny/set_env_vars
Unified configuration format, `store_build_artifacts` part
2 parents c6596c8 + ce87d12 commit de895bd

14 files changed

+920
-59
lines changed

conda_smithy/configure_feedstock.py

Lines changed: 69 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
ensure_standard_strings,
6262
get_feedstock_about_from_meta,
6363
get_feedstock_name_from_meta,
64+
get_workflow_settings,
6465
)
6566
from conda_smithy.validate_schema import (
6667
CONDA_FORGE_YAML_DEFAULTS_FILE,
@@ -1821,6 +1822,20 @@ def render_appveyor(jinja_env, forge_config, forge_dir, return_metadata=False):
18211822

18221823

18231824
def _github_actions_specific_setup(jinja_env, forge_config, forge_dir, platform):
1825+
platform_templates = {
1826+
"linux": [
1827+
".scripts/run_docker_build.sh",
1828+
".scripts/build_steps.sh",
1829+
],
1830+
"osx": [
1831+
".scripts/run_osx_build.sh",
1832+
],
1833+
"win": [
1834+
".scripts/run_win_build.bat",
1835+
],
1836+
}
1837+
template_files = platform_templates.get(platform, [])
1838+
18241839
# Handle GH-hosted and self-hosted runners runs-on config
18251840
# Do it before the deepcopy below so these changes can be used by the
18261841
# .github/worfkflows/conda-build.yml template
@@ -1871,6 +1886,17 @@ def _github_actions_specific_setup(jinja_env, forge_config, forge_dir, platform)
18711886
data["gha_with_gpu"] = True
18721887
data["gha_runs_on"].append(label)
18731888

1889+
data.update(
1890+
get_workflow_settings(
1891+
forge_config["workflow_settings"], "github_actions", data["platform"]
1892+
)
1893+
)
1894+
if data["store_build_artifacts"]:
1895+
script_suffix = ".bat" if platform == "win" else ".sh"
1896+
template_files.append(
1897+
f".scripts/create_conda_build_artifacts{script_suffix}"
1898+
)
1899+
18741900
build_setup = _get_build_setup_line(forge_dir, platform, forge_config)
18751901

18761902
if platform == "linux":
@@ -1881,26 +1907,6 @@ def _github_actions_specific_setup(jinja_env, forge_config, forge_dir, platform)
18811907
forge_config = deepcopy(forge_config)
18821908
forge_config["build_setup"] = build_setup
18831909

1884-
platform_templates = {
1885-
"linux": [
1886-
".scripts/run_docker_build.sh",
1887-
".scripts/build_steps.sh",
1888-
],
1889-
"osx": [
1890-
".scripts/run_osx_build.sh",
1891-
],
1892-
"win": [
1893-
".scripts/run_win_build.bat",
1894-
],
1895-
}
1896-
1897-
template_files = platform_templates.get(platform, [])
1898-
1899-
# Templates for all platforms
1900-
if forge_config["github_actions"]["store_build_artifacts"]:
1901-
template_files.append(".scripts/create_conda_build_artifacts.sh")
1902-
template_files.append(".scripts/create_conda_build_artifacts.bat")
1903-
19041910
_render_template_exe_files(
19051911
forge_config=forge_config,
19061912
jinja_env=jinja_env,
@@ -1952,14 +1958,6 @@ def render_github_actions(jinja_env, forge_config, forge_dir, return_metadata=Fa
19521958
def _azure_specific_setup(jinja_env, forge_config, forge_dir, platform):
19531959
build_setup = _get_build_setup_line(forge_dir, platform, forge_config)
19541960

1955-
if platform == "linux":
1956-
yum_build_setup = generate_yum_requirements(forge_config, forge_dir)
1957-
if yum_build_setup:
1958-
forge_config["yum_build_setup"] = yum_build_setup
1959-
1960-
forge_config = deepcopy(forge_config)
1961-
forge_config["build_setup"] = build_setup
1962-
19631961
platform_templates = {
19641962
"linux": [
19651963
".scripts/run_docker_build.sh",
@@ -1975,12 +1973,16 @@ def _azure_specific_setup(jinja_env, forge_config, forge_dir, platform):
19751973
".scripts/run_win_build.bat",
19761974
],
19771975
}
1978-
if forge_config["azure"]["store_build_artifacts"]:
1979-
platform_templates["linux"].append(".scripts/create_conda_build_artifacts.sh")
1980-
platform_templates["osx"].append(".scripts/create_conda_build_artifacts.sh")
1981-
platform_templates["win"].append(".scripts/create_conda_build_artifacts.bat")
19821976
template_files = platform_templates.get(platform, [])
19831977

1978+
if platform == "linux":
1979+
yum_build_setup = generate_yum_requirements(forge_config, forge_dir)
1980+
if yum_build_setup:
1981+
forge_config["yum_build_setup"] = yum_build_setup
1982+
1983+
forge_config = deepcopy(forge_config)
1984+
forge_config["build_setup"] = build_setup
1985+
19841986
azure_settings = deepcopy(forge_config["azure"][f"settings_{platform}"])
19851987
azure_settings.pop("swapfile_size", None)
19861988
azure_settings.pop("install_atl", None)
@@ -2010,15 +2012,21 @@ def _azure_specific_setup(jinja_env, forge_config, forge_dir, platform):
20102012
# fmt: off
20112013
if "docker_image" in data["config"] and platform == "linux":
20122014
config_rendered["DOCKER_IMAGE"] = data["config"]["docker_image"][-1]
2013-
if forge_config["azure"]["store_build_artifacts"]:
2014-
config_rendered["SHORT_CONFIG"] = data["short_config_name"]
20152015
if platform == "osx":
20162016
if data["build_platform"] == "osx-64":
20172017
config_rendered["VMIMAGE"] = "macOS-15"
20182018
elif data["build_platform"] == "osx-arm64":
20192019
config_rendered["VMIMAGE"] = "macOS-15-arm64"
20202020
else:
20212021
raise ValueError(f"Unknown build platform: '{data['build_platform']}'")
2022+
2023+
workflow_settings = get_workflow_settings(forge_config["workflow_settings"], "azure", data["platform"])
2024+
data.update(workflow_settings)
2025+
config_rendered.update(workflow_settings)
2026+
if config_rendered["store_build_artifacts"]:
2027+
config_rendered["SHORT_CONFIG"] = data["short_config_name"]
2028+
script_suffix = ".bat" if platform == "win" else ".sh"
2029+
template_files.append(f".scripts/create_conda_build_artifacts{script_suffix}")
20222030
azure_settings["strategy"]["matrix"][data["config_name"]] = config_rendered
20232031
# fmt: on
20242032

@@ -2464,6 +2472,33 @@ def _read_forge_config(forge_dir, forge_yml=None):
24642472
# values.
24652473
config = _update_dict_within_dict(file_config.items(), default_config)
24662474

2475+
if "store_build_artifacts" in file_config.get("workflow_settings", {}):
2476+
# Check for conflicting old keys.
2477+
if "store_build_artifacts" in file_config.get("azure", {}):
2478+
raise ValueError(
2479+
"`store_build_artifacts` both in `workflow_settings` and `azure` "
2480+
"sections. Please remove the latter."
2481+
)
2482+
if "store_build_artifacts" in file_config.get("github_actions", {}):
2483+
raise ValueError(
2484+
"`store_build_artifacts` both in `workflow_settings` and "
2485+
"`github_actions` sections. Please remove the latter."
2486+
)
2487+
else:
2488+
# Convert old keys to new settings.
2489+
config["workflow_settings"]["store_build_artifacts"].append(
2490+
{
2491+
"provider": "azure",
2492+
"value": config["azure"]["store_build_artifacts"],
2493+
}
2494+
)
2495+
config["workflow_settings"]["store_build_artifacts"].append(
2496+
{
2497+
"provider": "github_actions",
2498+
"value": config["github_actions"]["store_build_artifacts"],
2499+
}
2500+
)
2501+
24672502
# check for conda-smithy 2.x matrix which we can't auto-migrate
24682503
# to conda_build_config
24692504
if file_config.get("matrix") and not os.path.exists(

conda_smithy/data/conda-forge.json

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@
147147
}
148148
],
149149
"default": false,
150-
"description": "Store the conda build_artifacts directory as an Azure pipeline artifact",
150+
"deprecated": true,
151+
"description": "Deprecated. Store the conda build_artifacts directory as an Azure pipeline artifact. Use `workflow_settings.store_build_artifacts` instead.",
151152
"title": "Store Build Artifacts"
152153
},
153154
"timeout_minutes": {
@@ -391,6 +392,84 @@
391392
"title": "CondaForgeDocker",
392393
"type": "object"
393394
},
395+
"ConditionalValue__class__bool__": {
396+
"properties": {
397+
"os": {
398+
"anyOf": [
399+
{
400+
"items": {
401+
"$ref": "#/$defs/PlatformsAliases"
402+
},
403+
"type": "array"
404+
},
405+
{
406+
"$ref": "#/$defs/PlatformsAliases"
407+
},
408+
{
409+
"$ref": "#/$defs/Nullable"
410+
},
411+
{
412+
"type": "null"
413+
}
414+
],
415+
"default": null,
416+
"description": "Operating systems to set environment variable on (default: all)",
417+
"title": "Os"
418+
},
419+
"platform": {
420+
"anyOf": [
421+
{
422+
"items": {
423+
"$ref": "#/$defs/Platforms"
424+
},
425+
"type": "array"
426+
},
427+
{
428+
"$ref": "#/$defs/Platforms"
429+
},
430+
{
431+
"$ref": "#/$defs/Nullable"
432+
},
433+
{
434+
"type": "null"
435+
}
436+
],
437+
"default": null,
438+
"description": "Platforms to set environment variable on (default: all)",
439+
"title": "Platform"
440+
},
441+
"provider": {
442+
"anyOf": [
443+
{
444+
"items": {
445+
"$ref": "#/$defs/CIservices"
446+
},
447+
"type": "array"
448+
},
449+
{
450+
"$ref": "#/$defs/CIservices"
451+
},
452+
{
453+
"$ref": "#/$defs/Nullable"
454+
},
455+
{
456+
"type": "null"
457+
}
458+
],
459+
"default": null,
460+
"description": "CI providers to set environment variable on (default: all)",
461+
"title": "Provider"
462+
},
463+
"value": {
464+
"default": false,
465+
"description": "Option value",
466+
"title": "Value",
467+
"type": "boolean"
468+
}
469+
},
470+
"title": "ConditionalValue_<class 'bool'>",
471+
"type": "object"
472+
},
394473
"DefaultTestPlatforms": {
395474
"enum": [
396475
"all",
@@ -509,7 +588,8 @@
509588
}
510589
],
511590
"default": false,
512-
"description": "Whether to store build artifacts",
591+
"deprecated": true,
592+
"description": "Deprecated. Whether to store build artifacts. Use `workflow_settings.store_build_artifacts` instead.",
513593
"title": "Store Build Artifacts"
514594
},
515595
"timeout_minutes": {
@@ -678,6 +758,15 @@
678758
"title": "Platforms",
679759
"type": "string"
680760
},
761+
"PlatformsAliases": {
762+
"enum": [
763+
"linux",
764+
"win",
765+
"osx"
766+
],
767+
"title": "PlatformsAliases",
768+
"type": "string"
769+
},
681770
"ShellCheck": {
682771
"additionalProperties": false,
683772
"properties": {
@@ -691,6 +780,34 @@
691780
"title": "ShellCheck",
692781
"type": "object"
693782
},
783+
"WorkflowSettings": {
784+
"properties": {
785+
"store_build_artifacts": {
786+
"anyOf": [
787+
{
788+
"type": "boolean"
789+
},
790+
{
791+
"items": {
792+
"$ref": "#/$defs/ConditionalValue__class__bool__"
793+
},
794+
"type": "array"
795+
},
796+
{
797+
"$ref": "#/$defs/Nullable"
798+
},
799+
{
800+
"type": "null"
801+
}
802+
],
803+
"default": [],
804+
"description": "Store the outputs of the build process as uploaded CI artifacts.",
805+
"title": "Store Build Artifacts"
806+
}
807+
},
808+
"title": "WorkflowSettings",
809+
"type": "object"
810+
},
694811
"build_platform": {
695812
"properties": {
696813
"emscripten_wasm32": {
@@ -2091,6 +2208,17 @@
20912208
"description": "The depth of the git clone.",
20922209
"title": "Clone Depth"
20932210
},
2211+
"workflow_settings": {
2212+
"anyOf": [
2213+
{
2214+
"$ref": "#/$defs/WorkflowSettings"
2215+
},
2216+
{
2217+
"type": "null"
2218+
}
2219+
],
2220+
"description": "Per-workflow settings.\n\n```yaml\nworkflow_settings:\n store_build_artifacts:\n # there can be at most one value for each workflow\n - provider: github_actions\n platform: linux_aarch64\n value: true\n - platform: [linux_64, win_64] # OR\n value: true\n```"
2221+
},
20942222
"travis": {
20952223
"anyOf": [
20962224
{

conda_smithy/data/conda-forge.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,5 @@ test: null
145145
test_on_native_only: false
146146
travis: {}
147147
woodpecker: {}
148+
workflow_settings:
149+
store_build_artifacts: []

0 commit comments

Comments
 (0)