-
-
Notifications
You must be signed in to change notification settings - Fork 224
Add support for Cirun on self-hosted GHA runners #1703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
e6dcdff
Add support for cirun on self-hosted GHA runners
jaimergp fd031cd
pre-commit
jaimergp 7836cce
add more labels and runners
jaimergp 2598d9a
produce .cirun.yml
jaimergp e6158f9
update runner config
jaimergp 5f96e5e
refactor os-matrix building in gha template
jaimergp a366a1f
update vm [ci skip]
jaimergp 4104525
default to gpu_large
jaimergp d6ae11a
support cancel_in_progress
jaimergp 9e01400
raw
jaimergp dfb99f2
Merge branch 'main' of github.com:conda-forge/conda-smithy into gha-s…
jaimergp adc5426
Merge branch 'main' of github.com:conda-forge/conda-smithy into gha-s…
jaimergp bc96c16
add stubs for opt-in ci registration
jaimergp d3258f9
TEMP
aktech f5dad75
add utilities to handle adding cirun
aktech eb8811e
move cirun stuff to cirun utils
aktech 8d4a674
Merge branch 'main' into gha-self-hosted-cirun
aktech f672f73
some cleanups
aktech 156e27d
undo conda-build version change
aktech 0a7bdd9
make precommit happy
aktech 7b0c3e3
add installation id
aktech fd37814
add policy args
aktech e72cb95
set installation id as environment variable
aktech 9126d1c
Merge branch 'main' into gha-self-hosted-cirun
aktech 832f85d
move conda-forge to environ variable
aktech d384958
use owner/org from cli instead of env var
aktech d084434
minor fixes
aktech 6355aa8
assert installation id
aktech 37d0252
add some more logging
aktech 94aac9e
log cirun response
aktech c2db57e
remove commented out code and cirun file json
aktech 63c566a
remove .cirun.yml template reference
aktech ce81aa2
pre-commit fixes
aktech 829201e
undo changes to github actions template
aktech c68e3b0
undo changes to configure feedstock
aktech 03b5cea
remove stub travis func
aktech d4a594c
undo mode change
aktech dee3843
Undo removal of github actions template
jaimergp c66aa34
Merge branch 'main' into gha-self-hosted-cirun
aktech 655aec2
pre-commit fixes
aktech cf9e9bf
not available for travis
aktech 589fb8a
add a note about getting installation id
aktech 117fc1e
cache cirun client
aktech c02cbdd
add type hints, docs
aktech e7257d7
set policy args to None by default
aktech 3876bbf
set default value for cirun_resources to iterable
aktech 85390fa
make polcy args as optional
aktech 2204933
precommit fixes
aktech 357e594
Update conda_smithy/cirun_utils.py
aktech 97456f4
remove reference to .cirun.yml template
aktech f42717c
add link to client docs
aktech ab740b8
remove cirun_runners from forge config
aktech 36e986d
Merge branch 'main' of github.com:conda-forge/conda-smithy into gha-s…
jaimergp 3472ee5
fix ppc64le name
jaimergp 84cc27f
add self hosted timeout minutes
jaimergp af967c9
add more platform labels
jaimergp 9405540
move labels config to configure_feedstock
jaimergp 4c4c898
pre-commit
jaimergp 98eb99c
Use recipe/conda_build_config.yaml for labels for more fine-grained c…
isuruf f480723
Merge branch 'main' of github.com:conda-forge/conda-smithy into gha-s…
isuruf 3c07948
Keep github_actions_labels only if self-hosted is turned on
isuruf c29e9cd
Bring back free_disk_space
isuruf 41d65b2
Support other orgs for cirun
isuruf d631fbd
pre-commit
isuruf 549d7b9
Move import to top-level
isuruf 83079c4
fix cirun installation id
isuruf fc4a0b0
formatting
isuruf 87f7004
Add news entry
isuruf a72ca1e
Fix default values
isuruf 20252d3
fix news
isuruf e50cf3a
list of lists for zipping
isuruf 9ac2df7
Merge branch 'main' of github.com:conda-forge/conda-smithy into gha-s…
isuruf 2bbcd4d
change default value of cancel_in_progress
isuruf 64e0e49
Merge branch 'main' of github.com:conda-forge/conda-smithy into gha-s…
isuruf 62d2a4b
pre-commit
isuruf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| """ | ||
| See http://py.cirun.io/api.html for cirun client docs | ||
| """ | ||
| import os | ||
| from functools import lru_cache | ||
| from typing import List, Dict, Any, Optional | ||
|
|
||
| from cirun import Cirun | ||
| from .github import gh_token, Github | ||
|
|
||
|
|
||
| @lru_cache | ||
| def get_cirun_installation_id(owner: str) -> int: | ||
| # This ID needs a token with admin: org privileges. | ||
| # Hard-code instead for easier use. | ||
| if owner == "conda-forge": | ||
| return 18453316 | ||
| else: | ||
| gh = Github(gh_token) | ||
| user = gh.get_user() | ||
| if user.login == owner: | ||
| user_or_org = user | ||
| else: | ||
| user_or_org = gh.get_organization(owner) | ||
| for inst in user_or_org.get_installations: | ||
| if inst.raw_data["app_slug"] == "cirun-application": | ||
| return inst.app_id | ||
| raise ValueError(f"cirun not found for owner {owner}") | ||
|
|
||
|
|
||
| def enable_cirun_for_project(owner: str, repo: str) -> Dict[str, Any]: | ||
| """Enable the cirun.io Github Application for a particular repository.""" | ||
| print(f"Enabling cirun for {owner}/{repo} ...") | ||
| cirun = _get_cirun_client() | ||
| return cirun.set_repo( | ||
| f"{owner}/{repo}", installation_id=get_cirun_installation_id(owner) | ||
| ) | ||
|
|
||
|
|
||
| def add_repo_to_cirun_resource( | ||
| owner: str, | ||
| repo: str, | ||
| resource: str, | ||
| cirun_policy_args: Optional[List[str]] = None, | ||
| ) -> Dict[str, Any]: | ||
| """Grant access to a cirun resource to a particular repository, with a particular policy.""" | ||
| cirun = _get_cirun_client() | ||
| policy_args: Optional[Dict[str, Any]] = None | ||
| if cirun_policy_args and "pull_request" in cirun_policy_args: | ||
| policy_args = {"pull_request": True} | ||
| print( | ||
| f"Adding repo {owner}/{repo} to resource {resource} with policy_args: {policy_args}" | ||
| ) | ||
| response = cirun.add_repo_to_resources( | ||
| owner, | ||
| repo, | ||
| resources=[resource], | ||
| teams=[repo], | ||
| policy_args=policy_args, | ||
| ) | ||
| print(f"response: {response} | {response.json().keys()}") | ||
| return response | ||
|
|
||
|
|
||
| def remove_repo_from_cirun_resource(owner: str, repo: str, resource: str): | ||
| """Revoke access to a cirun resource to a particular repository, with a particular policy.""" | ||
| cirun = _get_cirun_client() | ||
| print(f"Removing repo {owner}/{repo} from resource {resource}.") | ||
| response = cirun.remove_repo_from_resources(owner, repo, [resource]) | ||
| print(f"response: {response} | {response.json().keys()}") | ||
| return response | ||
|
|
||
|
|
||
| @lru_cache | ||
| def _get_cirun_client() -> Cirun: | ||
|
xhochy marked this conversation as resolved.
|
||
| try: | ||
| return Cirun() | ||
| except KeyError: | ||
| raise RuntimeError( | ||
| "You must have CIRUN_API_KEY defined to do Cirun CI registration. " | ||
| "This requirement can be overriden by specifying `--without-cirun`" | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -377,6 +377,9 @@ def _collapse_subpackage_variants( | |
| if not is_noarch: | ||
| always_keep_keys.add("target_platform") | ||
|
|
||
| if forge_config["github_actions"]["self_hosted"]: | ||
| always_keep_keys.add("github_actions_labels") | ||
|
|
||
| all_used_vars.update(always_keep_keys) | ||
| all_used_vars.update(top_level_vars) | ||
|
|
||
|
|
@@ -695,7 +698,6 @@ def _render_ci_provider( | |
| channel_target.startswith("conda-forge ") | ||
| and provider_name == "github_actions" | ||
| and not forge_config["github_actions"]["self_hosted"] | ||
| and os.path.basename(forge_dir) not in SERVICE_FEEDSTOCKS | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jaimergp why was this line removed?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want it to be self-hosted or in service |
||
| ): | ||
| raise RuntimeError( | ||
| "Using github_actions as the CI provider inside " | ||
|
|
@@ -1266,6 +1268,82 @@ def render_appveyor(jinja_env, forge_config, forge_dir, return_metadata=False): | |
| 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"), | ||
| }, | ||
| "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 | ||
|
|
||
| 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 = conda_build.utils.ensure_list( | ||
| data["config"].get("github_actions_labels", [labels_default])[0] | ||
| ) | ||
|
|
||
| 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"] = [] | ||
| # labels provided in conda-forge.yml | ||
| for label in 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"] = hosted_default | ||
|
|
||
| build_setup = _get_build_setup_line(forge_dir, platform, forge_config) | ||
|
|
||
| if platform == "linux": | ||
|
|
@@ -1288,11 +1366,13 @@ def _github_actions_specific_setup( | |
| ".scripts/run_win_build.bat", | ||
| ], | ||
| } | ||
| if forge_config["github_actions"]["store_build_artifacts"]: | ||
| for tmpls in platform_templates.values(): | ||
| tmpls.append(".scripts/create_conda_build_artifacts.sh") | ||
|
|
||
| template_files = platform_templates.get(platform, []) | ||
|
|
||
| # Templates for all platforms | ||
| if forge_config["github_actions"]["store_build_artifacts"]: | ||
| template_files.append(".scripts/create_conda_build_artifacts.sh") | ||
|
|
||
| _render_template_exe_files( | ||
| forge_config=forge_config, | ||
| jinja_env=jinja_env, | ||
|
|
@@ -1307,7 +1387,7 @@ def render_github_actions( | |
| target_path = os.path.join( | ||
| forge_dir, ".github", "workflows", "conda-build.yml" | ||
| ) | ||
| template_filename = "github-actions.tmpl" | ||
| template_filename = "github-actions.yml.tmpl" | ||
| fast_finish_text = "" | ||
|
|
||
| ( | ||
|
|
@@ -1317,7 +1397,7 @@ def render_github_actions( | |
| upload_packages, | ||
| ) = _get_platforms_of_provider("github_actions", forge_config) | ||
|
|
||
| logger.debug("github platforms retreived") | ||
| logger.debug("github platforms retrieved") | ||
|
|
||
| remove_file_or_dir(target_path) | ||
| return _render_ci_provider( | ||
|
|
@@ -1841,6 +1921,9 @@ def _load_forge_config(forge_dir, exclusive_config_file, forge_yml=None): | |
| }, | ||
| "github_actions": { | ||
| "self_hosted": False, | ||
| "triggers": [], | ||
| "timeout_minutes": 360, | ||
| "cancel_in_progress": True, | ||
| # Set maximum parallel jobs | ||
| "max_parallel": None, | ||
| # Toggle creating artifacts for conda build_artifacts dir | ||
|
|
@@ -2001,6 +2084,12 @@ def _load_forge_config(forge_dir, exclusive_config_file, forge_yml=None): | |
| if config["test"] is None: | ||
| config["test"] = "all" | ||
|
|
||
| if not config["github_actions"]["triggers"]: | ||
| 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 = [ | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.