ci: update-flake: handle existing PRs and avoid silent errors

Co-authored-by: Matt Sturgeon <matt@sturgeon.me.uk>
This commit is contained in:
NAHO 2025-11-20 16:58:34 +01:00
parent 0ef1d62a31
commit 91075d1635
No known key found for this signature in database
GPG key ID: BFB5D5E3F4C95185

View file

@ -75,15 +75,32 @@ jobs:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
base_branch: ${{ matrix.branch }}
body: "This is an automated update triggered by the [workflow run #${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})." # yamllint disable-line rule:line-length
label: "topic: dependencies"
pr_branch: update_flake_lock_action_${{ matrix.branch }}
title: "${{ startsWith(matrix.branch, 'release') && format('[{0}] ', matrix.branch) || '' }}flake: update public and dev inputs" # yamllint disable-line rule:line-length
run: |
git switch --create "$pr_branch"
git push origin "$pr_branch" --force --set-upstream
gh pr create \
--base "$base_branch" \
--body "$body" \
--label "topic: dependencies" \
--title "$title" ||
echo "Failed to create PR"
pr_count="$(
gh api \
--method GET \
"/repos/$GITHUB_REPOSITORY/pulls" \
--field per_page=1 \
--raw-field head="$GITHUB_REPOSITORY_OWNER:$pr_branch" \
--jq length
)"
if ((pr_count)); then
gh pr edit \
--body "$body" \
--label "$label" \
--title "$title"
else
gh pr create \
--base "$base_branch" \
--body "$body" \
--label "$label" \
--title "$title"
fi