workflows: rename baseSha to targetSha

We currently use two different "base" commits, but the same name. One of
them is the commit in which context the pull_request_target runs. The
other is the parent of the merge commit. Those are **not** necessarily
the same - see README introduced in the next commit for details.

Renaming one of them for clarity. Since the pull_request_target related
base commit is also called like that in GitHub Actions terminology, we
rename the other. The best I could come up with is "target".
This commit is contained in:
Wolfgang Walther
2025-01-08 21:16:34 +01:00
parent ba09688dc8
commit 3e9f5c05ea
4 changed files with 48 additions and 48 deletions

View File

@@ -31,13 +31,13 @@ jobs:
# Fetches the merge commit and its parents # Fetches the merge commit and its parents
fetch-depth: 2 fetch-depth: 2
- name: Checking out base branch - name: Checking out target branch
run: | run: |
base=$(mktemp -d) target=$(mktemp -d)
baseRev=$(git rev-parse HEAD^1) targetRev=$(git rev-parse HEAD^1)
git worktree add "$base" "$baseRev" git worktree add "$target" "$targetRev"
echo "baseRev=$baseRev" >> "$GITHUB_ENV" echo "targetRev=$targetRev" >> "$GITHUB_ENV"
echo "base=$base" >> "$GITHUB_ENV" echo "target=$target" >> "$GITHUB_ENV"
- name: Get Nixpkgs revision for nixfmt - name: Get Nixpkgs revision for nixfmt
run: | run: |
@@ -85,12 +85,12 @@ jobs:
esac esac
# Ignore files that weren't already formatted # Ignore files that weren't already formatted
if [[ -n "$source" ]] && ! nixfmt --check ${{ env.base }}/"$source" 2>/dev/null; then if [[ -n "$source" ]] && ! nixfmt --check ${{ env.target }}/"$source" 2>/dev/null; then
echo "Ignoring file $file because it's not formatted in the base commit" echo "Ignoring file $file because it's not formatted in the target commit"
elif ! nixfmt --check "$dest"; then elif ! nixfmt --check "$dest"; then
unformattedFiles+=("$dest") unformattedFiles+=("$dest")
fi fi
done < <(git diff -z --name-status ${{ env.baseRev }} -- '*.nix') done < <(git diff -z --name-status ${{ env.targetRev }} -- '*.nix')
if (( "${#unformattedFiles[@]}" > 0 )); then if (( "${#unformattedFiles[@]}" > 0 )); then
echo "Some new/changed Nix files are not properly formatted" echo "Some new/changed Nix files are not properly formatted"

View File

@@ -20,13 +20,13 @@ jobs:
# Fetches the merge commit and its parents # Fetches the merge commit and its parents
fetch-depth: 2 fetch-depth: 2
- name: Checking out base branch - name: Checking out target branch
run: | run: |
base=$(mktemp -d) target=$(mktemp -d)
baseRev=$(git rev-parse HEAD^1) targetRev=$(git rev-parse HEAD^1)
git worktree add "$base" "$baseRev" git worktree add "$target" "$targetRev"
echo "baseRev=$baseRev" >> "$GITHUB_ENV" echo "targetRev=$targetRev" >> "$GITHUB_ENV"
echo "base=$base" >> "$GITHUB_ENV" echo "target=$target" >> "$GITHUB_ENV"
- name: Get Nixpkgs revision for nixf - name: Get Nixpkgs revision for nixf
run: | run: |
@@ -91,8 +91,8 @@ jobs:
continue continue
esac esac
if [[ -n "$source" ]] && [[ "$(nixf_wrapper ${{ env.base }}/"$source")" != '[]' ]] 2>/dev/null; then if [[ -n "$source" ]] && [[ "$(nixf_wrapper ${{ env.target }}/"$source")" != '[]' ]] 2>/dev/null; then
echo "Ignoring file $file because it doesn't pass nixf-tidy in the base commit" echo "Ignoring file $file because it doesn't pass nixf-tidy in the target commit"
echo # insert blank line echo # insert blank line
else else
nixf_report="$(nixf_wrapper "$dest")" nixf_report="$(nixf_wrapper "$dest")"
@@ -119,7 +119,7 @@ jobs:
failedFiles+=("$dest") failedFiles+=("$dest")
fi fi
fi fi
done < <(git diff -z --name-status ${{ env.baseRev }} -- '*.nix') done < <(git diff -z --name-status ${{ env.targetRev }} -- '*.nix')
if [[ -n "$DONT_REPORT_ERROR" ]]; then if [[ -n "$DONT_REPORT_ERROR" ]]; then
echo "Edited the PR but didn't change the base branch, only the description/title." echo "Edited the PR but didn't change the base branch, only the description/title."

View File

@@ -26,7 +26,7 @@ jobs:
# Skip this and dependent steps if the PR can't be merged # Skip this and dependent steps if the PR can't be merged
if: needs.get-merge-commit.outputs.mergedSha if: needs.get-merge-commit.outputs.mergedSha
outputs: outputs:
baseSha: ${{ steps.baseSha.outputs.baseSha }} targetSha: ${{ steps.targetSha.outputs.targetSha }}
systems: ${{ steps.systems.outputs.systems }} systems: ${{ steps.systems.outputs.systems }}
steps: steps:
- name: Check out the PR at the test merge commit - name: Check out the PR at the test merge commit
@@ -36,12 +36,12 @@ jobs:
fetch-depth: 2 fetch-depth: 2
path: nixpkgs path: nixpkgs
- name: Determine base commit - name: Determine target commit
if: github.event_name == 'pull_request_target' if: github.event_name == 'pull_request_target'
id: baseSha id: targetSha
run: | run: |
baseSha=$(git -C nixpkgs rev-parse HEAD^1) targetSha=$(git -C nixpkgs rev-parse HEAD^1)
echo "baseSha=$baseSha" >> "$GITHUB_OUTPUT" echo "targetSha=$targetSha" >> "$GITHUB_OUTPUT"
- name: Install Nix - name: Install Nix
uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30 uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30
@@ -128,7 +128,7 @@ jobs:
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
needs: [ outpaths, attrs, get-merge-commit ] needs: [ outpaths, attrs, get-merge-commit ]
outputs: outputs:
baseRunId: ${{ steps.baseRunId.outputs.baseRunId }} targetRunId: ${{ steps.targetRunId.outputs.targetRunId }}
steps: steps:
- name: Download output paths and eval stats for all systems - name: Download output paths and eval stats for all systems
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
@@ -158,11 +158,11 @@ jobs:
name: result name: result
path: prResult/* path: prResult/*
- name: Get base run id - name: Get target run id
if: needs.attrs.outputs.baseSha if: needs.attrs.outputs.targetSha
id: baseRunId id: targetRunId
run: | run: |
# Get the latest eval.yml workflow run for the PR's base commit # Get the latest eval.yml workflow run for the PR's target commit
if ! run=$(gh api --method GET /repos/"$REPOSITORY"/actions/workflows/eval.yml/runs \ if ! run=$(gh api --method GET /repos/"$REPOSITORY"/actions/workflows/eval.yml/runs \
-f head_sha="$BASE_SHA" -f event=push \ -f head_sha="$BASE_SHA" -f event=push \
--jq '.workflow_runs | sort_by(.run_started_at) | .[-1]') \ --jq '.workflow_runs | sort_by(.run_started_at) | .[-1]') \
@@ -185,30 +185,30 @@ jobs:
exit 0 exit 0
fi fi
echo "baseRunId=$runId" >> "$GITHUB_OUTPUT" echo "targetRunId=$runId" >> "$GITHUB_OUTPUT"
env: env:
REPOSITORY: ${{ github.repository }} REPOSITORY: ${{ github.repository }}
BASE_SHA: ${{ needs.attrs.outputs.baseSha }} BASE_SHA: ${{ needs.attrs.outputs.targetSha }}
GH_TOKEN: ${{ github.token }} GH_TOKEN: ${{ github.token }}
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v4
if: steps.baseRunId.outputs.baseRunId if: steps.targetRunId.outputs.targetRunId
with: with:
name: result name: result
path: baseResult path: targetResult
github-token: ${{ github.token }} github-token: ${{ github.token }}
run-id: ${{ steps.baseRunId.outputs.baseRunId }} run-id: ${{ steps.targetRunId.outputs.targetRunId }}
- name: Compare against the base branch - name: Compare against the target branch
if: steps.baseRunId.outputs.baseRunId if: steps.targetRunId.outputs.targetRunId
run: | run: |
git -C nixpkgs worktree add ../base ${{ needs.attrs.outputs.baseSha }} git -C nixpkgs worktree add ../target ${{ needs.attrs.outputs.targetSha }}
git -C nixpkgs diff --name-only ${{ needs.attrs.outputs.baseSha }} \ git -C nixpkgs diff --name-only ${{ needs.attrs.outputs.targetSha }} \
| jq --raw-input --slurp 'split("\n")[:-1]' > touched-files.json | jq --raw-input --slurp 'split("\n")[:-1]' > touched-files.json
# Use the base branch to get accurate maintainer info # Use the target branch to get accurate maintainer info
nix-build base/ci -A eval.compare \ nix-build target/ci -A eval.compare \
--arg beforeResultDir ./baseResult \ --arg beforeResultDir ./targetResult \
--arg afterResultDir ./prResult \ --arg afterResultDir ./prResult \
--arg touchedFilesJson ./touched-files.json \ --arg touchedFilesJson ./touched-files.json \
-o comparison -o comparison
@@ -216,7 +216,7 @@ jobs:
cat comparison/step-summary.md >> "$GITHUB_STEP_SUMMARY" cat comparison/step-summary.md >> "$GITHUB_STEP_SUMMARY"
- name: Upload the combined results - name: Upload the combined results
if: steps.baseRunId.outputs.baseRunId if: steps.targetRunId.outputs.targetRunId
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0 uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with: with:
name: comparison name: comparison
@@ -227,7 +227,7 @@ jobs:
name: Tag name: Tag
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
needs: [ attrs, process ] needs: [ attrs, process ]
if: needs.process.outputs.baseRunId if: needs.process.outputs.targetRunId
permissions: permissions:
pull-requests: write pull-requests: write
statuses: write statuses: write
@@ -254,7 +254,7 @@ jobs:
- name: Check out Nixpkgs at the base commit - name: Check out Nixpkgs at the base commit
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with: with:
ref: ${{ needs.attrs.outputs.baseSha }} ref: ${{ needs.attrs.outputs.targetSha }}
path: base path: base
sparse-checkout: ci sparse-checkout: ci

View File

@@ -39,11 +39,11 @@ jobs:
# Fetches the merge commit and its parents # Fetches the merge commit and its parents
fetch-depth: 2 fetch-depth: 2
- name: Checking out base branch - name: Checking out target branch
run: | run: |
base=$(mktemp -d) target=$(mktemp -d)
git worktree add "$base" "$(git rev-parse HEAD^1)" git worktree add "$target" "$(git rev-parse HEAD^1)"
echo "base=$base" >> "$GITHUB_ENV" echo "target=$target" >> "$GITHUB_ENV"
- uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30 - uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30
@@ -65,7 +65,7 @@ jobs:
# Force terminal colors to be enabled. The library that `nixpkgs-vet` uses respects https://bixense.com/clicolors/ # Force terminal colors to be enabled. The library that `nixpkgs-vet` uses respects https://bixense.com/clicolors/
CLICOLOR_FORCE: 1 CLICOLOR_FORCE: 1
run: | run: |
if result/bin/nixpkgs-vet --base "$base" .; then if result/bin/nixpkgs-vet --base "$target" .; then
exit 0 exit 0
else else
exitCode=$? exitCode=$?