Skip to content

Create release PR

Create release PR #34

name: Create release PR
on:
workflow_run:
workflows: ["Update and test"]
types: [completed]
workflow_dispatch:
inputs:
run_id:
description: 'Workflow run ID to process'
required: true
type: string
permissions:
contents: write
pull-requests: write
jobs:
create-pr:
runs-on: [self-hosted, Linux]
if: github.event.workflow_run.head_branch == 'main' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v6
- name: Install Nix
uses: cachix/install-nix-action@v31
- name: Install devenv
run: nix profile install github:cachix/devenv/latest
- name: Get nixpkgs revision
id: nixpkgs
run: |
SHORT=$(nix flake metadata --json | jq -r '.locks.nodes["nixpkgs-src"].locked.rev' | cut -c1-7)
echo "short=$SHORT" >> "$GITHUB_OUTPUT"
- name: Generate test summary
shell: devenv shell bash -- -e {0}
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
RUN_ID="${{ inputs.run_id }}"
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/$RUN_ID"
else
RUN_ID="${{ github.event.workflow_run.id }}"
RUN_URL="${{ github.event.workflow_run.html_url }}"
fi
test-summary --run-id "$RUN_ID" --run-url "$RUN_URL" --repo "${{ github.repository }}" --output-path test-summary.md
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Read test summary
id: summary
run: |
{
echo 'body<<SUMMARY_EOF'
echo "Promotes main to rolling with nixpkgs ${{ steps.nixpkgs.outputs.short }}."
echo ""
echo "## Test Results"
echo ""
cat test-summary.md
echo ""
echo "---"
echo "Auto-generated release PR."
echo 'SUMMARY_EOF'
} >> "$GITHUB_OUTPUT"
- name: Ensure rolling branch exists
run: |
if ! git ls-remote --exit-code origin rolling; then
git push origin main:rolling
fi
- name: Create or update release PR
run: |
TITLE="Release nixpkgs ${{ steps.nixpkgs.outputs.short }}"
# Hidden marker that identifies the per-run history comments we post.
HISTORY_MARKER="<!-- release-run-history -->"
PR_URL=$(gh pr list --base rolling --head main --json url --jq '.[0].url')
if [ -z "$PR_URL" ]; then
# First run: open the PR with just the body.
gh pr create --base rolling --head main --title "$TITLE" --body "$BODY"
exit 0
fi
# Append a run summary as a history comment, tagged with the marker.
post_history_comment() {
printf '%s\n\n%s\n' "$HISTORY_MARKER" "$1" | gh pr comment "$PR_URL" --body-file -
}
# Subsequent runs: keep the body on the latest run and append one
# comment per run so the PR keeps a full history. The first run's
# summary only ever lived in the body, so the first time we add
# history we archive that body before overwriting it; after that every
# run already left its own comment.
PR_JSON=$(gh pr view "$PR_URL" --json body,comments)
if ! jq -r '.comments[].body' <<<"$PR_JSON" | grep -qF "$HISTORY_MARKER"; then
post_history_comment "$(jq -r '.body' <<<"$PR_JSON")"
fi
gh pr edit "$PR_URL" --title "$TITLE" --body "$BODY"
post_history_comment "$BODY"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BODY: ${{ steps.summary.outputs.body }}