From 98eb99cce31ba83fb052d616cfe77ebae6441c32 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Fri, 20 Oct 2023 15:15:21 -0500 Subject: [PATCH] Use recipe/conda_build_config.yaml for labels for more fine-grained control --- conda_smithy/configure_feedstock.py | 64 ++++++++++++------- .../templates/github-actions.yml.tmpl | 6 +- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/conda_smithy/configure_feedstock.py b/conda_smithy/configure_feedstock.py index 08e9789b3..ed36f32a6 100644 --- a/conda_smithy/configure_feedstock.py +++ b/conda_smithy/configure_feedstock.py @@ -367,6 +367,7 @@ def _collapse_subpackage_variants( "channel_targets", "docker_image", "build_number_decrement", + "github_actions_labels", # The following keys are required for some of our aarch64 builds # Added in https://github.com/conda-forge/conda-forge-pinning-feedstock/pull/180 "cdt_arch", @@ -1285,10 +1286,6 @@ def _github_actions_specific_setup( "os": "ubuntu", "self_hosted_labels": ("linux", "ARM64"), }, - "linux-ppc64le": { - "os": "ubuntu", - "self_hosted_labels": ("linux", ""), - }, "win-64": { "os": "windows", "self_hosted_labels": ("windows", "x64"), @@ -1307,14 +1304,34 @@ def _github_actions_specific_setup( # This avoid potential collisions with other CI providers :crossed_fingers: data["gha_os"] = runs_on[data["build_platform"]]["os"] data["gha_with_gpu"] = False + + self_hosted_default = list( + runs_on[data["build_platform"]]["self_hosted_labels"] + ) + self_hosted_default += ["self-hosted"] + hosted_default = [data["gha_os"] + "-latest"] + + labels_default = ( + ["hosted"] + if forge_config["github_actions"]["self_hosted"] + else ["self-hosted"] + ) + labels = list( + data["config"].get("github_actions_labels", labels_default) + ) + + if len(labels) == 1 and labels[0] == "hosted": + labels = hosted_default + elif len(labels) == 1 and labels[0] in "self-hosted": + labels = self_hosted_default + else: + # Prepend the required ones + labels += self_hosted_default + if forge_config["github_actions"]["self_hosted"]: - data["gha_runs_on"] = [ - "self-hosted", - # default, per-platform labels - *runs_on[data["build_platform"]]["self_hosted_labels"], - ] + data["gha_runs_on"] = [] # labels provided in conda-forge.yml - for label in forge_config["github_actions"]["self_hosted_labels"]: + for label in labels: if label.startswith("cirun-"): label += ( "--${{ github.run_id }}-" + data["short_config_name"] @@ -1323,7 +1340,7 @@ def _github_actions_specific_setup( data["gha_with_gpu"] = True data["gha_runs_on"].append(label) else: - data["gha_runs_on"] = data["gha_os"] + "-latest" + data["gha_runs_on"] = hosted_default build_setup = _get_build_setup_line(forge_dir, platform, forge_config) @@ -1380,13 +1397,6 @@ def render_github_actions( logger.debug("github platforms retrieved") - if forge_config["github_actions"]["self_hosted"]: - forge_config["github_actions"]["triggers"] = forge_config[ - "github_actions" - ]["self_hosted_triggers"] - else: - forge_config["github_actions"]["triggers"] = ["push", "pull_request"] - remove_file_or_dir(target_path) return _render_ci_provider( "github_actions", @@ -1904,10 +1914,9 @@ def _load_forge_config(forge_dir, exclusive_config_file, forge_yml=None): }, "github_actions": { "self_hosted": False, - "self_hosted_labels": [], - "self_hosted_triggers": ["push"], - "self_hosted_timeout_minutes": 360, - "cancel_in_progress": False, + "triggers": "default", + "timeout_minutes": 360, + "cancel_in_progress": "default", # Set maximum parallel jobs "max_parallel": None, # Toggle creating artifacts for conda build_artifacts dir @@ -2065,6 +2074,17 @@ def _load_forge_config(forge_dir, exclusive_config_file, forge_yml=None): if config["test"] is None: config["test"] = "all" + if config["github_actions"]["cancel_in_progress"] == "default": + config["github_actions"]["cancel_in_progress"] = config[ + "github_actions" + ]["self_hosted"] + + if config["github_actions"]["triggers"] == "default": + self_hosted = config["github_actions"]["self_hosted"] + config["github_actions"]["triggers"] = ( + ["push"] if self_hosted else ["push", "pull_request"] + ) + # An older conda-smithy used to have some files which should no longer exist, # remove those now. old_files = [ diff --git a/conda_smithy/templates/github-actions.yml.tmpl b/conda_smithy/templates/github-actions.yml.tmpl index 08a7ac328..1e9a8addb 100644 --- a/conda_smithy/templates/github-actions.yml.tmpl +++ b/conda_smithy/templates/github-actions.yml.tmpl @@ -13,7 +13,7 @@ name: Build conda package on: {{ github_actions.triggers }} -{%- if github_actions.cancel_in_progress or github_actions.self_hosted %} +{%- if github_actions.cancel_in_progress %} concurrency: group: {% raw %}${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}{% endraw %} cancel-in-progress: true @@ -23,9 +23,7 @@ jobs: build: name: {% raw %}${{ matrix.CONFIG }}{% endraw %} runs-on: {% raw %}${{ matrix.runs_on }}{% endraw %} - {%- if github_actions.self_hosted and github_actions.self_hosted_timeout_minutes %} - timeout-minutes: {{ github_actions.self_hosted_timeout_minutes }} - {%- endif %} + timeout-minutes: {{ github_actions.timeout_minutes }} strategy: fail-fast: false {%- if github_actions.max_parallel %}