diff --git a/.github/workflows/eval.yml b/.github/workflows/eval.yml index 95130ec85d6b..024e7b823b62 100644 --- a/.github/workflows/eval.yml +++ b/.github/workflows/eval.yml @@ -24,23 +24,13 @@ jobs: 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 with: @@ -143,7 +133,7 @@ jobs: 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 @@ -172,7 +162,7 @@ jobs: 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 @@ -186,8 +176,8 @@ jobs: - 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 @@ -241,7 +231,7 @@ jobs: - 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 diff --git a/.github/workflows/get-merge-commit.yml b/.github/workflows/get-merge-commit.yml index 7ce1d53b0249..7d8dd03fbf66 100644 --- a/.github/workflows/get-merge-commit.yml +++ b/.github/workflows/get-merge-commit.yml @@ -6,6 +6,9 @@ on: 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 }} @@ -17,6 +20,7 @@ jobs: 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 @@ -35,9 +39,9 @@ jobs: 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..." diff --git a/ci/README.md b/ci/README.md index a1b327de4e5d..6ef665e8b099 100644 --- a/ci/README.md +++ b/ci/README.md @@ -44,14 +44,14 @@ Why not just build the tooling right from the PRs Nixpkgs version? ## `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 diff --git a/ci/get-merge-commit.sh b/ci/get-merge-commit.sh index c62bb56dd993..c233f7f91691 100755 --- a/ci/get-merge-commit.sh +++ b/ci/get-merge-commit.sh @@ -55,7 +55,10 @@ done 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