Skip to content

Commit

Permalink
Skip tests when merging an up-to-date branch
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Jan 29, 2024
1 parent bda2f6c commit f9bfe65
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,37 @@ env:
CARGO_TERM_COLOR: always

jobs:
maybe-expedite:
runs-on: ubuntu-latest

outputs:
value: ${{ steps.expedite.outputs.value }}

steps:
- name: Log github refs
run: |
echo '```' >> "$GITHUB_STEP_SUMMARY"
echo 'github.ref: ${{ github.ref }}' >> "$GITHUB_STEP_SUMMARY"
echo 'github.sha: ${{ github.sha }}' >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check if merging an up-to-date branch
id: expedite
if: ${{ github.action == 'merge_group' }}
run: |
if git merge-base --is-ancestor origin/master ${{ github.event.pull_request.head.sha }}; then
echo "value=1" >> "$GITHUB_OUTPUT"
fi
test:
needs: [maybe-expedite]

if: ${{ ! needs.maybe-expedite.outputs.value }}

strategy:
fail-fast: ${{ github.event_name == 'merge_group' }}
matrix:
Expand All @@ -32,13 +62,6 @@ jobs:
GROUP_RUNNER: target.'cfg(all())'.runner = 'group-runner'

steps:
- name: Log github refs
run: |
echo '```' >> "$GITHUB_STEP_SUMMARY"
echo 'github.ref: ${{ github.ref }}' >> "$GITHUB_STEP_SUMMARY"
echo 'github.sha: ${{ github.sha }}' >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
- uses: actions/checkout@v4

- uses: actions/cache@v4
Expand Down Expand Up @@ -94,14 +117,14 @@ jobs:
all-checks:
needs: [test]

runs-on: ubuntu-latest

# smoelius: From "Defining prerequisite jobs"
# (https://docs.github.com/en/actions/using-jobs/using-jobs-in-a-workflow#defining-prerequisite-jobs):
# > If you would like a job to run even if a job it is dependent on did not succeed, use the
# > `always()` conditional expression in `jobs.<job_id>.if`.
if: ${{ always() }}

runs-on: ubuntu-latest

steps:
- name: Check results
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
Expand Down

0 comments on commit f9bfe65

Please sign in to comment.