|
1 | 1 | name: Update README |
2 | 2 |
|
3 | 3 | on: |
4 | | - schedule: |
5 | | - # Run once a week on Monday at 00:00 UTC |
6 | | - - cron: "0 0 * * 1" |
7 | | - workflow_dispatch: # Allow manual triggering |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - "README_SOURCE.md" |
| 7 | + - "CONTRIBUTING.md" |
| 8 | + - ".github/pull_request_template.md" |
| 9 | + - ".github/workflows/update-readme.yml" |
| 10 | + - "scripts/**" |
8 | 11 | push: |
9 | 12 | branches: |
10 | 13 | - master |
11 | 14 | - test |
12 | 15 | paths: |
13 | | - - "CONTRIBUTE_README.md" |
| 16 | + - "README_SOURCE.md" |
| 17 | + - ".github/workflows/update-readme.yml" |
14 | 18 | - "scripts/**" |
| 19 | + schedule: |
| 20 | + - cron: "0 0 * * 1" |
| 21 | + workflow_dispatch: |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: read |
| 25 | + |
| 26 | +concurrency: |
| 27 | + group: update-readme-${{ github.ref }} |
| 28 | + cancel-in-progress: false |
15 | 29 |
|
16 | 30 | jobs: |
17 | | - update-readme: |
| 31 | + validate: |
| 32 | + if: github.event_name == 'pull_request' |
18 | 33 | runs-on: ubuntu-latest |
19 | | - |
20 | 34 | steps: |
21 | | - - name: Checkout repository |
22 | | - uses: actions/checkout@v4 |
| 35 | + - uses: actions/checkout@v6 |
| 36 | + - uses: actions/setup-java@v5 |
23 | 37 | with: |
24 | | - fetch-depth: 0 # Fetch all history for git operations |
| 38 | + distribution: temurin |
| 39 | + java-version: "25" |
| 40 | + - name: Validate source and generator |
| 41 | + run: | |
| 42 | + java scripts/generate_readme.java self-test |
| 43 | + java scripts/generate_readme.java check README_SOURCE.md |
25 | 44 |
|
26 | | - - name: Set up Java |
27 | | - uses: actions/setup-java@v4 |
| 45 | + update: |
| 46 | + if: github.event_name != 'pull_request' |
| 47 | + runs-on: ubuntu-latest |
| 48 | + permissions: |
| 49 | + contents: write |
| 50 | + steps: |
| 51 | + - uses: actions/checkout@v6 |
| 52 | + with: |
| 53 | + fetch-depth: 0 |
| 54 | + - uses: actions/setup-java@v5 |
28 | 55 | with: |
29 | | - distribution: "temurin" |
| 56 | + distribution: temurin |
30 | 57 | java-version: "25" |
31 | | - |
32 | | - - name: Restore stats cache |
| 58 | + - name: Restore statistics cache |
| 59 | + uses: actions/cache@v4 |
| 60 | + with: |
| 61 | + path: .cache/github-stats.tsv |
| 62 | + key: readme-stats-${{ github.ref_name }}-${{ github.run_id }} |
| 63 | + restore-keys: | |
| 64 | + readme-stats-${{ github.ref_name }}- |
| 65 | + - name: Validate source and generator |
33 | 66 | run: | |
34 | | - mkdir -p .tmp |
35 | | - # On scheduled runs, refresh all stats by not restoring cache |
36 | | - # On manual/push runs, use cache to avoid unnecessary API calls |
37 | | - if [ "${{ github.event_name }}" == "schedule" ]; then |
38 | | - echo "Scheduled run detected - will fetch fresh data for all repositories" |
39 | | - # Don't restore cache, let script fetch everything fresh |
40 | | - else |
41 | | - # Try to restore stats cache from previous run |
42 | | - if git show HEAD:.tmp/github-stats.txt > .tmp/github-stats.txt 2>/dev/null; then |
43 | | - echo "Restored existing stats cache from previous commit" |
44 | | - else |
45 | | - echo "No existing stats cache found, will fetch all data" |
46 | | - fi |
47 | | - fi |
48 | | -
|
49 | | - - name: Run README generation workflow |
| 67 | + java scripts/generate_readme.java self-test |
| 68 | + java scripts/generate_readme.java check README_SOURCE.md |
| 69 | + - name: Generate README |
50 | 70 | env: |
51 | 71 | PAT: ${{ secrets.PAT }} |
52 | 72 | run: | |
53 | | - java --enable-preview --source 25 scripts/run_workflow.java |
54 | | -
|
55 | | - - name: Commit updated README and stats cache |
| 73 | + args=() |
| 74 | + if [ "${{ github.event_name }}" = "schedule" ] || [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 75 | + args+=(--refresh-all) |
| 76 | + fi |
| 77 | + java scripts/generate_readme.java generate README_SOURCE.md README.md .cache/github-stats.tsv "${args[@]}" --branch "$GITHUB_REF_NAME" |
| 78 | + - name: Commit README |
56 | 79 | run: | |
57 | 80 | git config --local user.email "action@github.com" |
58 | 81 | git config --local user.name "GitHub Action" |
59 | | - git add -f README.md |
60 | | - # Always commit the stats cache so it persists for next run |
61 | | - git add -f .tmp/github-stats.txt || true |
| 82 | + git add README.md |
62 | 83 | if git diff --staged --quiet; then |
63 | | - echo "No changes to commit" |
| 84 | + echo "README is already current" |
64 | 85 | else |
65 | | - git commit -m "Update README with latest GitHub stats [skip ci]" |
| 86 | + git commit -m "Update README with latest GitHub stats" |
66 | 87 | git push |
67 | 88 | fi |
0 commit comments