ci: try to have cooldown use verified commits

This commit is contained in:
Wez Furlong committed 2026-08-04 08:53:33 +01:00
1 parent 2326b21dc8
commit d1b7c0c90a
1 file changed
+57 -27
+57 -27
View File
@@ -8,10 +8,11 @@ on:
env:
CARGO_TERM_COLOR: always
COOLDOWN_BRANCH: cargo-cooldown/update
# The default GITHUB_TOKEN is used only for checkout; the branch push and PR
# creation use the App token generated below, which has its own
# installation permissions.
# The default GITHUB_TOKEN is used only for checkout; the branch update and PR
# creation use the App token generated below, which has its own installation
# permissions.
permissions:
contents: read
@@ -33,7 +34,17 @@ jobs:
- name: Run cooldown update
run: ./ci/update-cargo-deps-with-cooldown.sh 2>&1 | tee "$RUNNER_TEMP/cooldown.log"
- name: Detect Cargo.lock changes
id: detect
run: |
if git diff --quiet -- Cargo.lock; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Compose pull request body
if: steps.detect.outputs.changed == 'true'
run: |
{
echo 'Automated dependency update produced by'
@@ -54,39 +65,58 @@ jobs:
echo '</details>'
} > "$RUNNER_TEMP/pr-body.md"
# Mint a short-lived token for the App installed on this repo. Using it
# rather than the default GITHUB_TOKEN makes the resulting PR trigger the
# build and format workflows.
# Mint a short-lived token for the App installed on this repo. Commits
# created through the API with this token are attributed to the App bot
# and signed by GitHub, and the PR it opens triggers the build workflows.
- name: Generate app token
if: steps.detect.outputs.changed == 'true'
id: app-token
uses: actions/create-github-app-token@v3.2.0
with:
app-id: ${{ secrets.COOLDOWN_APP_ID }}
private-key: ${{ secrets.COOLDOWN_APP_PRIVATE_KEY }}
# The App token controls who pushes the branch and opens the PR, but the
# commit author and committer are separate trailers. Look up the App
# bot's numeric user id to build its noreply address, so the commit is
# attributed to the bot rather than to whoever triggered the run.
- name: Look up app bot user id
id: bot-user
# Point the update branch at the current commit before committing onto it,
# so each run produces a single clean commit on top of the default branch
# rather than stacking onto a stale prior run.
- name: Reset update branch to base
if: steps.detect.outputs.changed == 'true'
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)
echo "id=$id" >> "$GITHUB_OUTPUT"
base=$(git rev-parse HEAD)
ref="heads/$COOLDOWN_BRANCH"
if gh api "repos/$GITHUB_REPOSITORY/git/refs/$ref" >/dev/null 2>&1; then
gh api --method PATCH "repos/$GITHUB_REPOSITORY/git/refs/$ref" \
-f sha="$base" -F force=true
else
gh api --method POST "repos/$GITHUB_REPOSITORY/git/refs" \
-f ref="refs/$ref" -f sha="$base"
fi
- name: Create pull request
uses: peter-evans/create-pull-request@v8.1.1
env:
BOT_IDENTITY: "${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.bot-user.outputs.id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>"
- name: Commit Cargo.lock via API
if: steps.detect.outputs.changed == 'true'
uses: planetscale/ghcommit-action@v0.2.22
with:
token: ${{ steps.app-token.outputs.token }}
branch: cargo-cooldown/update
add-paths: Cargo.lock
commit-message: "deps: update Cargo.lock via cooldown"
author: ${{ env.BOT_IDENTITY }}
committer: ${{ env.BOT_IDENTITY }}
title: "deps: update Cargo.lock via cooldown"
body-path: ${{ runner.temp }}/pr-body.md
delete-branch: true
commit_message: "deps: update Cargo.lock via cooldown"
repo: ${{ github.repository }}
branch: ${{ env.COOLDOWN_BRANCH }}
file_pattern: Cargo.lock
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Open or update pull request
if: steps.detect.outputs.changed == 'true'
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
title="deps: update Cargo.lock via cooldown"
if gh pr view "$COOLDOWN_BRANCH" --repo "$GITHUB_REPOSITORY" \
--json state --jq .state 2>/dev/null | grep -qx OPEN; then
gh pr edit "$COOLDOWN_BRANCH" --repo "$GITHUB_REPOSITORY" \
--body-file "$RUNNER_TEMP/pr-body.md"
else
gh pr create --repo "$GITHUB_REPOSITORY" \
--base main --head "$COOLDOWN_BRANCH" \
--title "$title" --body-file "$RUNNER_TEMP/pr-body.md"
fi