From 98032430bbfe66da2476f480477f0b3809b6ffb1 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Tue, 5 Nov 2024 22:05:39 -0800 Subject: [PATCH] ci: Fix workflow events (#189) This was found by auditing workflows based on research published here: https://github.com/joeyparrish/workflow-cheat-sheet The research was prompted by this repo's PR workflow testing the wrong ref. --- .github/workflows/build-and-test.yaml | 6 +++--- .github/workflows/publish-docs.yaml | 2 +- .github/workflows/release-please.yaml | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index 7a23c0e..b4f00b6 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -26,7 +26,7 @@ defaults: # old one. If a PR is updated and a new test run is started, the old test run # will be cancelled automatically to conserve resources. concurrency: - group: ${{ github.workflow }}-${{ github.event.number || github.run_id }} + group: ${{ github.workflow }}-${{ github.event.number || inputs.ref }} cancel-in-progress: true jobs: @@ -43,7 +43,7 @@ jobs: - uses: actions/checkout@v4 with: path: repo-src - ref: ${{ inputs.ref || github.event.pull_request.merge_commit_sha || github.event.push.head }} + ref: inputs.ref || (github.event.number && format('refs/pull/{0}/merge', github.event.number)) - name: Configure Build Matrix id: configure @@ -95,7 +95,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - ref: ${{ inputs.ref || github.event.pull_request.merge_commit_sha || github.event.push.head }} + ref: inputs.ref || (github.event.number && format('refs/pull/{0}/merge', github.event.number)) - name: Set Python version uses: actions/setup-python@v5 diff --git a/.github/workflows/publish-docs.yaml b/.github/workflows/publish-docs.yaml index b5b2aba..4368757 100644 --- a/.github/workflows/publish-docs.yaml +++ b/.github/workflows/publish-docs.yaml @@ -31,7 +31,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - ref: ${{ inputs.ref || github.event.push.head }} + ref: ${{ inputs.ref || github.ref }} - name: Set Python version uses: actions/setup-python@v5 diff --git a/.github/workflows/release-please.yaml b/.github/workflows/release-please.yaml index 13c3155..47b981e 100644 --- a/.github/workflows/release-please.yaml +++ b/.github/workflows/release-please.yaml @@ -38,6 +38,7 @@ jobs: steps: - uses: actions/checkout@v4 with: + ref: refs/tags/${{ needs.release.outputs.tag_name }} fetch-depth: 0 persist-credentials: false