Skip to content

Commit

Permalink
Merge pull request #1887 from PathogenDavid/optional-package-comparison
Browse files Browse the repository at this point in the history
Make package comparison in CI optional for the sake of forks
  • Loading branch information
glopesdev authored Jul 5, 2024
2 parents 63630d0 + 8755afd commit 130de6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/Bonsai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/create-build-matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 130de6f

Please sign in to comment.