diff --git a/.github/workflows/_meta.yml b/.github/workflows/_meta.yml index 9704ec3de4..1ad37f13ed 100644 --- a/.github/workflows/_meta.yml +++ b/.github/workflows/_meta.yml @@ -5,6 +5,9 @@ on: github-event-name: type: string required: true + github-event-json: + type: string + required: true outputs: build-tag: description: "Tag for the current workflow run" @@ -27,6 +30,9 @@ on: release-pr-run-id: description: "Only available if `run-kind in [storage-release, proxy-release, compute-release]`. Contains the run ID of the `Build and Test` workflow, assuming one with the current commit can be found." value: ${{ jobs.tags.outputs.release-pr-run-id }} + sha: + description: "github.event.pull_request.head.sha on release PRs, github.sha otherwise" + value: ${{ jobs.tags.outputs.sha }} permissions: {} @@ -45,6 +51,7 @@ jobs: storage: ${{ steps.previous-releases.outputs.storage }} run-kind: ${{ steps.run-kind.outputs.run-kind }} release-pr-run-id: ${{ steps.release-pr-run-id.outputs.release-pr-run-id }} + sha: ${{ steps.sha.outputs.sha }} permissions: contents: read steps: @@ -54,10 +61,6 @@ jobs: with: egress-policy: audit - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - fetch-depth: 0 - - name: Get run kind id: run-kind env: @@ -78,6 +81,23 @@ jobs: run: | echo "run-kind=$RUN_KIND" | tee -a $GITHUB_OUTPUT + - name: Get the right SHA + id: sha + env: + SHA: > + ${{ + contains(fromJSON('["storage-rc-pr", "proxy-rc-pr", "compute-rc-pr"]'), steps.run-kind.outputs.run-kind) + && fromJSON(inputs.github-event-json).pull_request.head.sha + || github.sha + }} + run: | + echo "sha=$SHA" | tee -a $GITHUB_OUTPUT + + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + fetch-depth: 0 + ref: ${{ steps.sha.outputs.sha }} + - name: Get build tag id: build-tag env: @@ -143,7 +163,7 @@ jobs: if: ${{ contains(fromJSON('["storage-release", "compute-release", "proxy-release"]'), steps.run-kind.outputs.run-kind) }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CURRENT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + CURRENT_SHA: ${{ github.sha }} run: | RELEASE_PR_RUN_ID=$(gh api "/repos/${GITHUB_REPOSITORY}/actions/runs?head_sha=$CURRENT_SHA" | jq '[.workflow_runs[] | select(.name == "Build and Test") | select(.head_branch | test("^rc/release(-(proxy|compute))?/[0-9]{4}-[0-9]{2}-[0-9]{2}$"; "s"))] | first | .id // ("Failed to find Build and Test run from RC PR!" | halt_error(1))') echo "release-pr-run-id=$RELEASE_PR_RUN_ID" | tee -a $GITHUB_OUTPUT diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 9ae4fc9d43..7d35066616 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -80,6 +80,7 @@ jobs: uses: ./.github/workflows/_meta.yml with: github-event-name: ${{ github.event_name }} + github-event-json: ${{ toJSON(github.event) }} build-build-tools-image: needs: [ check-permissions ] @@ -545,6 +546,7 @@ jobs: uses: ./.github/workflows/trigger-e2e-tests.yml with: github-event-name: ${{ github.event_name }} + github-event-json: ${{ toJSON(github.event) }} secrets: inherit neon-image-arch: @@ -568,6 +570,7 @@ jobs: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: submodules: true + ref: ${{ needs.meta.outputs.sha }} - uses: neondatabase/dev-actions/set-docker-config-dir@6094485bf440001c94a94a3f9e221e81ff6b6193 - uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0 @@ -677,6 +680,7 @@ jobs: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: submodules: true + ref: ${{ needs.meta.outputs.sha }} - uses: neondatabase/dev-actions/set-docker-config-dir@6094485bf440001c94a94a3f9e221e81ff6b6193 - uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0 diff --git a/.github/workflows/trigger-e2e-tests.yml b/.github/workflows/trigger-e2e-tests.yml index 18c4808020..ca4c465931 100644 --- a/.github/workflows/trigger-e2e-tests.yml +++ b/.github/workflows/trigger-e2e-tests.yml @@ -9,6 +9,9 @@ on: github-event-name: type: string required: true + github-event-json: + type: string + required: true defaults: run: @@ -48,6 +51,7 @@ jobs: uses: ./.github/workflows/_meta.yml with: github-event-name: ${{ inputs.github-event-name || github.event_name }} + github-event-json: ${{ inputs.github-event-json || toJSON(github.event) }} trigger-e2e-tests: needs: [ meta ]