Skip to content

Commit

Permalink
move labels config to configure_feedstock
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp committed Oct 17, 2023
1 parent af967c9 commit 9405540
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 71 deletions.
64 changes: 64 additions & 0 deletions conda_smithy/configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,64 @@ def _github_actions_specific_setup(
jinja_env, forge_config, forge_dir, platform
):

# Handle GH-hosted and self-hosted runners runs-on config
# Do it before the deepcopy below so these changes can be used by the
# .github/worfkflows/conda-build.yml template
runs_on = {
'osx-64': {
'os': 'macos',
'self_hosted_labels': ('macOS', 'x64'),
},
'osx-arm64': {
'os': 'macos',
'self_hosted_labels': ('macOS', 'arm64'),
},
'linux-64': {
'os': 'ubuntu',
'self_hosted_labels': ('linux', 'x64'),
},
'linux-aarch64': {
'os': 'ubuntu',
'self_hosted_labels': ('linux', 'ARM64'),
},
'linux-ppc64le': {
'os': 'ubuntu',
'self_hosted_labels': ('linux', ''),
},
'win-64': {
'os': 'windows',
'self_hosted_labels': ('windows', 'x64'),
},
'win-arm64': {
'os': 'windows',
'self_hosted_labels': ('windows', 'ARM64'),
},
}
for data in forge_config["configs"]:
if not data["build_platform"].startswith(platform):
continue
# This Github Actions specific configs are prefixed with "gha_"
# because we are not deepcopying the data dict intentionally
# so it can be used in the general "render_github_actions" function
# This avoid potential collisions with other CI providers :crossed_fingers:
data["gha_os"] = runs_on[data["build_platform"]]["os"]
data["gha_with_gpu"] = False
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"],
]
# labels provided in conda-forge.yml
for label in forge_config["github_actions"]["self_hosted_labels"]:
if label.startswith("cirun-"):
label += "--${{ github.run_id }}-" + data["short_config_name"]
if "gpu" in label.lower():
data["gha_with_gpu"] = True
data["gha_runs_on"].append(label)
else:
data["gha_runs_on"] = data["gha_os"] + "-latest"

build_setup = _get_build_setup_line(forge_dir, platform, forge_config)

if platform == "linux":
Expand Down Expand Up @@ -1320,6 +1378,12 @@ 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",
Expand Down
77 changes: 6 additions & 71 deletions conda_smithy/templates/github-actions.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,20 @@
{%- endfor %}

name: Build conda package
{%- if github_actions.self_hosted %}
on: {{ github_actions.self_hosted_triggers }}
{%- else %}
on: [push, pull_request]
{%- endif %}
on: {{ github_actions.triggers }}

{%- if github_actions.cancel_in_progress or github_actions.self_hosted %}
concurrency:
group: {% raw %}${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}{% endraw %}
cancel-in-progress: true
{%- endif %}

{%- set platform_vars = {
'osx-64': {
'os': 'macos',
'self_hosted_label_os': 'macOS',
'self_hosted_label_arch': 'x64',
},
'osx-arm64': {
'os': 'macos',
'self_hosted_label_os': 'macOS',
'self_hosted_label_arch': 'arm64',
},
'linux-64': {
'os': 'ubuntu',
'self_hosted_label_os': 'linux',
'self_hosted_label_arch': 'x64',
},
'linux-aarch64': {
'os': 'ubuntu',
'self_hosted_label_os': 'linux',
'self_hosted_label_arch': 'ARM64',
},
'linux-ppc64le': {
'os': 'ubuntu',
'self_hosted_label_os': 'linux',
'self_hosted_label_arch': '',
},
'win-64': {
'os': 'windows',
'self_hosted_label_os': 'windows',
'self_hosted_label_arch': 'x64',
},
'win-arm64': {
'os': 'windows',
'self_hosted_label_os': 'windows',
'self_hosted_label_arch': 'ARM64',
},
}
%}

jobs:
build:
name: {% raw %}${{ matrix.CONFIG }}{% endraw %}
{%- if github_actions.self_hosted %}
runs-on: {% raw %}${{ matrix.labels }}{% endraw %}
{%- if github_actions.self_hosted_timeout_minutes %}
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 %}
{%- else %}
runs-on: {% raw %}${{ matrix.os }}{% endraw %}-latest
{%- endif %}
strategy:
fail-fast: false
Expand All @@ -86,29 +39,11 @@ jobs:
SHORT_CONFIG: {{ data.short_config_name }}
{%- endif %}
UPLOAD_PACKAGES: {{ data.upload }}
os: {{ platform_vars[data.build_platform]['os'] }}
{#- namespace needed to handle jinja scoping rules #}
{%- set ns = namespace(gpu=False) %}
{%- if github_actions.self_hosted %}
labels:
- self-hosted
- {{ platform_vars[data.build_platform]['self_hosted_label_os'] }}
{%- if platform_vars[data.build_platform]['self_hosted_label_arch'] %}
- {{ platform_vars[data.build_platform]['self_hosted_label_arch'] }}
{%- endif %}
{%- for label in github_actions.self_hosted_labels %}
{%- if 'gpu' in label %}
{%- set ns.gpu = True %}
{%- endif %}
{%- if label.startswith('cirun-') %}
{%- set label = label ~ "--${{ github.run_id }}-" ~ data.short_config_name %}
{%- endif %}
- {{ label }}
{%- endfor %}
{%- endif %}
os: {{ data.gha_os }}
runs_on: {{ data.gha_runs_on }}
{%- if data.build_platform.startswith("linux") %}
DOCKER_IMAGE: {{ data.config["docker_image"][-1] }}
{%- if ns.gpu %}
{%- if data.gha_with_gpu %}
CONDA_FORGE_DOCKER_RUN_ARGS: "--gpus all"
{%- endif %}
{%- endif %}
Expand Down

0 comments on commit 9405540

Please sign in to comment.