From f9bfe65b5d5e37b60021bae0a9d83fa8a575c9af Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Sun, 28 Jan 2024 20:33:14 -0500 Subject: [PATCH] Skip tests when merging an up-to-date branch --- .github/workflows/ci.yml | 41 +++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dff429a2..8ca1b670 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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 @@ -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..if`. if: ${{ always() }} + runs-on: ubuntu-latest + steps: - name: Check results if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}