|
| 1 | +name: Update SCO downloads shields in readmes, then sync to adamlui/userscripts |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: "23 7 * * 3" # every Wed @ 7:23 AM |
| 7 | + |
| 8 | +jobs: |
| 9 | + update-root-downloads-shields: |
| 10 | + runs-on: ubuntu-24.04 |
| 11 | + permissions: |
| 12 | + contents: read |
| 13 | + env: |
| 14 | + TZ: PST8PDT |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout KudoAI/googlegpt |
| 18 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 19 | + with: |
| 20 | + token: ${{ secrets.REPO_SYNC_PAT }} |
| 21 | + path: KudoAI/googlegpt |
| 22 | + |
| 23 | + - name: Checkout adamlui/userscripts |
| 24 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 25 | + with: |
| 26 | + token: ${{ secrets.REPO_SYNC_PAT }} |
| 27 | + repository: adamlui/userscripts |
| 28 | + path: adamlui/userscripts |
| 29 | + |
| 30 | + - name: Fetch/sum downloads count |
| 31 | + run: | |
| 32 | + raw_sco_dls=$(curl -s https://scriptcat.org/en/script-show-page/6371 | \ |
| 33 | + grep -oP 'Total Installs.*?<span class="ant-statistic-content-value">\K[^<]+' | head -1) |
| 34 | + echo "Total SCO downloads (formatted): $raw_sco_dls" |
| 35 | + if [ -z "$raw_sco_dls" ] || [ "$raw_sco_dls" = "0" ] ; then |
| 36 | + echo "Error: couldn't get install count" |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | + echo "TOTAL_SCO_DLS=$raw_sco_dls" >> $GITHUB_ENV |
| 40 | +
|
| 41 | + - name: Update README shields |
| 42 | + run: | |
| 43 | + cd ${{ github.workspace }}/KudoAI/googlegpt |
| 44 | + TOTAL_SCO_DLS="${{ env.TOTAL_SCO_DLS }}" |
| 45 | + if [ -z "$TOTAL_SCO_DLS" ] || [ "$TOTAL_SCO_DLS" = "0" ] ; then |
| 46 | + echo "Error: couldn't get install count" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + shields_updated=false |
| 50 | + for readme in $(find greasemonkey/docs -name "README.md") ; do |
| 51 | + old_readme=$(<"$readme") |
| 52 | + sed -i "s/\(badge\/[^-]*-\)[0-9.,KMBkmb+]\+\(-af68ff\)/\1${TOTAL_SCO_DLS}\2/gI" "$readme" |
| 53 | + new_readme=$(<"$readme") |
| 54 | + if [[ "$old_readme" != "$new_readme" ]] ; then |
| 55 | + shields_updated=true ; echo "Updated: $readme" ; fi |
| 56 | + done |
| 57 | + if [ "$shields_updated" = true ] ; then |
| 58 | + echo "SHIELDS_UPDATED=true" >> $GITHUB_ENV |
| 59 | + else |
| 60 | + echo "Shields already up-to-date" |
| 61 | + fi |
| 62 | +
|
| 63 | + - name: Sync /greasemonkey to adamlui/userscripts/chatgpt/googlegpt/ |
| 64 | + run: | |
| 65 | + rsync -avhc --delete \ |
| 66 | + ${{ github.workspace }}/KudoAI/googlegpt/greasemonkey/ \ |
| 67 | + ${{ github.workspace }}/adamlui/userscripts/chatgpt/googlegpt/ |
| 68 | +
|
| 69 | + - name: Config committer |
| 70 | + if: env.SHIELDS_UPDATED == 'true' |
| 71 | + env: |
| 72 | + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} |
| 73 | + GPG_PRIVATE_ID: ${{ secrets.GPG_PRIVATE_ID }} |
| 74 | + run: | |
| 75 | + gpg --batch --import <(echo "$GPG_PRIVATE_KEY") |
| 76 | + git config --global commit.gpgsign true |
| 77 | + git config --global user.name "kudo-sync-bot" |
| 78 | + git config --global user.email "auto-sync@kudoai.com" |
| 79 | + git config --global user.signingkey "$GPG_PRIVATE_ID" |
| 80 | +
|
| 81 | + - name: Push changes to KudoAI/googlegpt |
| 82 | + if: env.SHIELDS_UPDATED == 'true' |
| 83 | + run: | |
| 84 | + cd ${{ github.workspace }}/KudoAI/googlegpt |
| 85 | + git add . && git commit -n -m "Updated downloads shield counters in Greasemonkey readmes" || true |
| 86 | + git pull --rebase |
| 87 | + git push |
| 88 | +
|
| 89 | + - name: Push changes to adamlui/userscripts |
| 90 | + if: env.SHIELDS_UPDATED == 'true' |
| 91 | + run: | |
| 92 | + cd ${{ github.workspace }}/adamlui/userscripts |
| 93 | + git add . && git commit -n -m \ |
| 94 | + "Updated downloads shield counters in Greasemonkey readmes \ |
| 95 | + ↞ [auto-sync from https://github.com/KudoAI/googlegpt]" || true |
| 96 | + git pull --rebase |
| 97 | + git push |
0 commit comments