Skip to content

Commit add5c86

Browse files
Daniel Jonesclaude
andcommitted
refactor(ci): append commits to refresh PR instead of force-pushing
Switches the refresh workflow off peter-evans/create-pull-request and onto native gh + git so we can: - Detect whether an open refresh PR already exists for branch chore/refresh-v3-languages. - If it does, check that branch out, fetch fresh responses, and append a new commit on top. Reviewer history (in-line comments, approvals) stays intact rather than being invalidated by a force-push each run. - If it does not, create the branch, commit, push, and open a new PR. - Skip cleanly when the fetched responses are identical to what is already on the branch. Also adds: - A concurrency group so cron and manual workflow_dispatch runs cannot race for the same branch. - A comment explaining the workflow_dispatch trigger. - A link back to the originating Actions run in each commit + PR body. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f8ab188 commit add5c86

1 file changed

Lines changed: 87 additions & 17 deletions

File tree

.github/workflows/refresh-v3-languages.yml

Lines changed: 87 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,107 @@ on:
44
schedule:
55
# Top of every hour.
66
- cron: "0 * * * *"
7+
# Allow the job to be triggered manually from the Actions tab.
78
workflow_dispatch:
89

910
permissions:
1011
contents: write
1112
pull-requests: write
1213

14+
concurrency:
15+
group: refresh-v3-languages
16+
cancel-in-progress: false
17+
18+
env:
19+
REFRESH_BRANCH: chore/refresh-v3-languages
20+
COMMIT_PATHS: data/v3-languages
21+
1322
jobs:
1423
refresh:
15-
name: Fetch and open PR on diff
24+
name: Fetch and update refresh PR
1625
runs-on: ubuntu-latest
1726
steps:
18-
- name: Checkout
27+
- name: Checkout main
1928
uses: actions/checkout@v5
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Detect existing refresh PR
33+
id: pr
34+
env:
35+
GH_TOKEN: ${{ github.token }}
36+
run: |
37+
number=$(gh pr list \
38+
--base main \
39+
--head "$REFRESH_BRANCH" \
40+
--state open \
41+
--json number \
42+
--jq '.[0].number // ""')
43+
echo "number=$number" >> "$GITHUB_OUTPUT"
44+
if [ -n "$number" ]; then
45+
echo "Existing refresh PR: #$number"
46+
else
47+
echo "No existing refresh PR"
48+
fi
49+
50+
- name: Check out existing refresh branch
51+
if: steps.pr.outputs.number != ''
52+
run: |
53+
git fetch origin "$REFRESH_BRANCH"
54+
git checkout -B "$REFRESH_BRANCH" "origin/$REFRESH_BRANCH"
2055
2156
- name: Fetch latest /v3/languages responses
2257
env:
2358
DEEPL_AUTH_KEY: ${{ secrets.DEEPL_API_KEY }}
2459
run: python3 scripts/fetch_v3_languages.py
2560

26-
- name: Open PR if responses changed
27-
uses: peter-evans/create-pull-request@v6
28-
with:
29-
branch: chore/refresh-v3-languages
30-
base: main
31-
commit-message: "chore(v3-languages): refresh vended responses"
32-
title: "chore(v3-languages): refresh vended responses"
33-
body: |
34-
Automated refresh of `data/v3-languages/` from `https://api.deepl.com/v3/languages`.
35-
36-
Triggered by the hourly `refresh-v3-languages` workflow.
37-
Merge this PR to update the vended data; downstream generators consume it.
38-
add-paths: data/v3-languages/**
39-
delete-branch: true
40-
labels: automated, v3-languages
61+
- name: Detect content changes
62+
id: diff
63+
run: |
64+
if git diff --quiet -- $COMMIT_PATHS; then
65+
echo "changed=false" >> "$GITHUB_OUTPUT"
66+
echo "No changes in $COMMIT_PATHS; nothing to commit."
67+
else
68+
echo "changed=true" >> "$GITHUB_OUTPUT"
69+
fi
70+
71+
- name: Configure git author
72+
if: steps.diff.outputs.changed == 'true'
73+
run: |
74+
git config user.name "github-actions[bot]"
75+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
76+
77+
- name: Append commit to existing refresh PR
78+
if: steps.diff.outputs.changed == 'true' && steps.pr.outputs.number != ''
79+
env:
80+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
81+
run: |
82+
git add -- $COMMIT_PATHS
83+
git commit -m "chore(v3-languages): refresh vended responses
84+
85+
Run: $RUN_URL"
86+
git push origin "$REFRESH_BRANCH"
87+
88+
- name: Create new refresh PR
89+
if: steps.diff.outputs.changed == 'true' && steps.pr.outputs.number == ''
90+
env:
91+
GH_TOKEN: ${{ github.token }}
92+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
93+
run: |
94+
git checkout -b "$REFRESH_BRANCH"
95+
git add -- $COMMIT_PATHS
96+
git commit -m "chore(v3-languages): refresh vended responses
97+
98+
Run: $RUN_URL"
99+
git push -u origin "$REFRESH_BRANCH"
100+
gh pr create \
101+
--base main \
102+
--head "$REFRESH_BRANCH" \
103+
--title "chore(v3-languages): refresh vended responses" \
104+
--body "Automated refresh of \`data/v3-languages/\` from \`https://api.deepl.com/v3/languages\`, opened by the \`refresh-v3-languages\` workflow.
105+
106+
Subsequent runs append new commits to this PR when the responses change again, so the diff against \`main\` represents the cumulative update. Review the latest state and merge when ready.
107+
108+
First run: $RUN_URL" \
109+
--label automated \
110+
--label v3-languages

0 commit comments

Comments
 (0)