|
4 | 4 | schedule: |
5 | 5 | # Top of every hour. |
6 | 6 | - cron: "0 * * * *" |
| 7 | + # Allow the job to be triggered manually from the Actions tab. |
7 | 8 | workflow_dispatch: |
8 | 9 |
|
9 | 10 | permissions: |
10 | 11 | contents: write |
11 | 12 | pull-requests: write |
12 | 13 |
|
| 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 | + |
13 | 22 | jobs: |
14 | 23 | refresh: |
15 | | - name: Fetch and open PR on diff |
| 24 | + name: Fetch and update refresh PR |
16 | 25 | runs-on: ubuntu-latest |
17 | 26 | steps: |
18 | | - - name: Checkout |
| 27 | + - name: Checkout main |
19 | 28 | 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" |
20 | 55 |
|
21 | 56 | - name: Fetch latest /v3/languages responses |
22 | 57 | env: |
23 | 58 | DEEPL_AUTH_KEY: ${{ secrets.DEEPL_API_KEY }} |
24 | 59 | run: python3 scripts/fetch_v3_languages.py |
25 | 60 |
|
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