Skip to content

Commit

Permalink
Make package comparison steps optional in CI for the sake of forks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
PathogenDavid committed Jul 5, 2024
1 parent ec6b9b6 commit f9428fa
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 f9428fa

Please sign in to comment.