workflows/get-merge-commit: return targetSha

We can fetch the targetSha directly with the mergedSha from the API.
This avoids a checkout with fetch-depth: 2 for a small performance
improvement.

Changed files
+18 -21
.github
ci
+5 -15
.github/workflows/eval.yml
···
runs-on: ubuntu-24.04-arm
needs: get-merge-commit
if: needs.get-merge-commit.outputs.mergedSha
-
outputs:
-
targetSha: ${{ steps.targetSha.outputs.targetSha }}
steps:
- name: Check out the PR at the test merge commit
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ needs.get-merge-commit.outputs.mergedSha }}
-
fetch-depth: 2
path: nixpkgs
-
-
- name: Determine target commit
-
if: github.event_name == 'pull_request_target'
-
id: targetSha
-
run: |
-
targetSha=$(git -C nixpkgs rev-parse HEAD^1)
-
echo "targetSha=$targetSha" >> "$GITHUB_OUTPUT"
- name: Install Nix
uses: cachix/install-nix-action@526118121621777ccd86f79b04685a9319637641 # v31
···
path: prResult/*
- name: Get target run id
-
if: needs.attrs.outputs.targetSha
+
if: needs.get-merge-commit.outputs.targetSha
id: targetRunId
run: |
# Get the latest eval.yml workflow run for the PR's target commit
···
echo "targetRunId=$runId" >> "$GITHUB_OUTPUT"
env:
REPOSITORY: ${{ github.repository }}
-
TARGET_SHA: ${{ needs.attrs.outputs.targetSha }}
+
TARGET_SHA: ${{ needs.get-merge-commit.outputs.targetSha }}
GH_TOKEN: ${{ github.token }}
- uses: actions/download-artifact@v4
···
- name: Compare against the target branch
if: steps.targetRunId.outputs.targetRunId
run: |
-
git -C nixpkgs worktree add ../target ${{ needs.attrs.outputs.targetSha }}
-
git -C nixpkgs diff --name-only ${{ needs.attrs.outputs.targetSha }} \
+
git -C nixpkgs worktree add ../target ${{ needs.get-merge-commit.outputs.targetSha }}
+
git -C nixpkgs diff --name-only ${{ needs.get-merge-commit.outputs.targetSha }} \
| jq --raw-input --slurp 'split("\n")[:-1]' > touched-files.json
# Use the target branch to get accurate maintainer info
···
- name: Check out Nixpkgs at the base commit
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
-
ref: ${{ needs.attrs.outputs.targetSha }}
+
ref: ${{ needs.get-merge-commit.outputs.targetSha }}
path: base
sparse-checkout: ci
+7 -3
.github/workflows/get-merge-commit.yml
···
mergedSha:
description: "The merge commit SHA"
value: ${{ jobs.resolve-merge-commit.outputs.mergedSha }}
+
targetSha:
+
description: "The target commit SHA"
+
value: ${{ jobs.resolve-merge-commit.outputs.targetSha }}
systems:
description: "The supported systems"
value: ${{ jobs.resolve-merge-commit.outputs.systems }}
···
runs-on: ubuntu-24.04-arm
outputs:
mergedSha: ${{ steps.merged.outputs.mergedSha }}
+
targetSha: ${{ steps.merged.outputs.targetSha }}
systems: ${{ steps.systems.outputs.systems }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
···
echo "mergedSha=${{ github.sha }}" >> "$GITHUB_OUTPUT"
;;
pull_request_target)
-
if mergedSha=$(base/ci/get-merge-commit.sh ${{ github.repository }} ${{ github.event.number }}); then
-
echo "Checking the merge commit $mergedSha"
-
echo "mergedSha=$mergedSha" >> "$GITHUB_OUTPUT"
+
if commits=$(base/ci/get-merge-commit.sh ${{ github.repository }} ${{ github.event.number }}); then
+
echo "Checking the commits:\n$commits"
+
echo "$commits" >> "$GITHUB_OUTPUT"
else
# Skipping so that no notifications are sent
echo "Skipping the rest..."
+2 -2
ci/README.md
···
## `get-merge-commit.sh GITHUB_REPO PR_NUMBER`
Check whether a PR is mergeable and return the test merge commit as
-
[computed by GitHub](https://docs.github.com/en/rest/guides/using-the-rest-api-to-interact-with-your-git-database?apiVersion=2022-11-28#checking-mergeability-of-pull-requests).
+
[computed by GitHub](https://docs.github.com/en/rest/guides/using-the-rest-api-to-interact-with-your-git-database?apiVersion=2022-11-28#checking-mergeability-of-pull-requests) and its parent.
Arguments:
- `GITHUB_REPO`: The repository of the PR, e.g. `NixOS/nixpkgs`
- `PR_NUMBER`: The PR number, e.g. `1234`
Exit codes:
-
- 0: The PR can be merged, the test merge commit hash is returned on stdout
+
- 0: The PR can be merged, the hashes of the test merge commit and the target commit are returned on stdout
- 1: The PR cannot be merged because it's not open anymore
- 2: The PR cannot be merged because it has a merge conflict
- 3: The merge commit isn't being computed, GitHub is likely having internal issues, unknown if the PR is mergeable
+4 -1
ci/get-merge-commit.sh
···
if [[ "$mergeable" == "true" ]]; then
log "The PR can be merged"
-
jq -r .merge_commit_sha <<< "$prInfo"
+
mergedSha="$(jq -r .merge_commit_sha <<< "$prInfo")"
+
echo "mergedSha=$mergedSha"
+
targetSha="$(gh api "/repos/$repo/commits/$mergedSha" --jq '.parents[0].sha')"
+
echo "targetSha=$targetSha"
else
log "The PR has a merge conflict"
exit 2