From 8755afd390196f96bf1a4bddacd34927f9fecbdc Mon Sep 17 00:00:00 2001 From: David Maas Date: Fri, 5 Jul 2024 09:53:41 -0500 Subject: [PATCH] Make package comparison in CI optional for the sake of forks Forks won't always have the `latest` tag (and even if they do it might be very stale), so don't bother with package comparison unless the fork explicitly enables it --- .github/workflows/Bonsai.yml | 5 ++++- .github/workflows/create-build-matrix.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Bonsai.yml b/.github/workflows/Bonsai.yml index ec5a982a..7ae6a4f1 100644 --- a/.github/workflows/Bonsai.yml +++ b/.github/workflows/Bonsai.yml @@ -45,6 +45,9 @@ jobs: - name: Create build matrix id: create-matrix run: python .github/workflows/create-build-matrix.py + env: + enable_package_comparison: ${{vars.ENABLE_PACKAGE_COMPARISON}} + will_publish_packages: ${{github.event.inputs.will_publish_packages}} # ===================================================================================================================================================================== # Build, test, and package @@ -184,7 +187,7 @@ jobs: runs-on: ubuntu-latest # We technically only need the dummy build jobs, but GitHub Actions lacks the ability to depend on specific jobs in a matrix needs: build-and-test - if: github.event_name != 'pull_request' + if: github.event_name != 'pull_request' && vars.ENABLE_PACKAGE_COMPARISON == 'true' steps: # ----------------------------------------------------------------------- Checkout - name: Checkout diff --git a/.github/workflows/create-build-matrix.py b/.github/workflows/create-build-matrix.py index eacd2b98..08fa1702 100755 --- a/.github/workflows/create-build-matrix.py +++ b/.github/workflows/create-build-matrix.py @@ -43,10 +43,19 @@ def add_dummy(name: str, artifacts_suffix: str): dummy['artifacts-suffix'] = artifacts_suffix return dummy -if os.getenv('GITHUB_EVENT_NAME') != 'pull_request': +enable_package_comparison = os.getenv('enable_package_comparison') == 'true' +github_event_name = os.getenv('GITHUB_EVENT_NAME') + +if github_event_name != 'pull_request' and enable_package_comparison: add_dummy('Previous Dummy', '-dummy-prev')['checkout-ref'] = 'refs/tags/latest' add_dummy('Next Dummy', '-dummy-next') +# Fail early if we won't be able to do package comparison and the run must publish packages to make logical sense +# Package comparison requires the `latest` tag to exist, but it will usually either be missing or invalid for forks so we require it to be opt-in +if not enable_package_comparison: + if github_event_name == 'release' or (github_event_name == 'workflow_dispatch' and os.getenv('will_publish_packages') == 'true'): + gha.print_error('Release aborted. We would not be able to determine which packages need to be released as this repository is not configured for package comparison.') + # Output matrix_json = json.dumps({ "include": matrix }, indent=2) print(matrix_json)