Преглед изворни кода

ci: refresh contrib.rocks cache workflow (#8083)

Hannes Rudolph пре 6 месеци
родитељ
комит
c943ba7875
1 измењених фајлова са 48 додато и 27 уклоњено
  1. 48 27
      .github/workflows/update-contributors.yml

+ 48 - 27
.github/workflows/update-contributors.yml

@@ -1,46 +1,67 @@
-name: Update Contributors
+name: Update Contributors # Refresh contrib.rocks image cache
 
 on:
-  push:
-    branches:
-      - main
   workflow_dispatch:
 
+permissions:
+  contents: write
+  pull-requests: write
+
 jobs:
-  update-contributors:
+  refresh-contrib-cache:
     runs-on: ubuntu-latest
-    permissions:
-      contents: write  # Needed for pushing changes.
-      pull-requests: write  # Needed for creating PRs.
     steps:
-      - name: Checkout code
+      - name: Checkout
         uses: actions/checkout@v4
-      - name: Setup Node.js and pnpm
-        uses: ./.github/actions/setup-node-pnpm
-      - name: Disable Husky
+
+      - name: Bump cacheBust in all README files
         run: |
-          echo "HUSKY=0" >> $GITHUB_ENV
-          git config --global core.hooksPath /dev/null
-      - name: Update contributors and format
+          set -euo pipefail
+          TS="$(date +%s)"
+          # Target only the root README.md and localized READMEs under locales/*/README.md
+          mapfile -t FILES < <(git ls-files README.md 'locales/*/README.md' || true)
+
+          if [ "${#FILES[@]}" -eq 0 ]; then
+            echo "No target README files found." >&2
+            exit 1
+          fi
+
+          UPDATED=0
+          for f in "${FILES[@]}"; do
+            if grep -q 'cacheBust=' "$f"; then
+              # Use portable sed in GNU environment of ubuntu-latest
+              sed -i -E "s/cacheBust=[0-9]+/cacheBust=${TS}/g" "$f"
+              echo "Updated cacheBust in $f"
+              UPDATED=1
+            else
+              echo "Warning: cacheBust parameter not found in $f" >&2
+            fi
+          done
+
+          if [ "$UPDATED" -eq 0 ]; then
+            echo "No files were updated. Ensure READMEs embed contrib.rocks with cacheBust param." >&2
+            exit 1
+          fi
+
+      - name: Detect changes
+        id: changes
         run: |
-          pnpm update-contributors
-          npx prettier --write README.md locales/*/README.md
-          if git diff --quiet; then echo "changes=false" >> $GITHUB_OUTPUT; else echo "changes=true" >> $GITHUB_OUTPUT; fi
-        id: check-changes
-        env:
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          if git diff --quiet; then
+            echo "changed=false" >> $GITHUB_OUTPUT
+          else
+            echo "changed=true" >> $GITHUB_OUTPUT
+          fi
+
       - name: Create Pull Request
-        if: steps.check-changes.outputs.changes == 'true'
+        if: steps.changes.outputs.changed == 'true'
         uses: peter-evans/create-pull-request@v7
         with:
           token: ${{ secrets.GITHUB_TOKEN }}
           commit-message: "docs: update contributors list [skip ci]"
           committer: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
-          branch: update-contributors
+          branch: refresh-contrib-cache
           delete-branch: true
-          title: "Update contributors list"
+          title: "Refresh contrib.rocks image cache (all READMEs)"
           body: |
-            Automated update of contributors list and related files
-
-            This PR was created automatically by a GitHub Action workflow and includes all changed files.
+            Automated refresh of the contrib.rocks image cache by bumping the cacheBust parameter in README.md and locales/*/README.md.
           base: main