| 
 | 1 | +name: Update usercount shields in READMEs, then sync to adamlui/ai-web-extensions  | 
 | 2 | + | 
 | 3 | +on:  | 
 | 4 | +  schedule:  | 
 | 5 | +    - cron: "33 2 * * 2" # every Tue @ 2:33 AM  | 
 | 6 | + | 
 | 7 | +permissions:  | 
 | 8 | +  contents: read  | 
 | 9 | + | 
 | 10 | +jobs:  | 
 | 11 | +  update-usercount-shields:  | 
 | 12 | +    runs-on: ubuntu-latest  | 
 | 13 | +    env:  | 
 | 14 | +      TZ: PST8PDT  | 
 | 15 | + | 
 | 16 | +    steps:  | 
 | 17 | +      - name: Checkout adamlui/perplexity-omnibox  | 
 | 18 | +        uses: actions/checkout@v4  | 
 | 19 | +        with:  | 
 | 20 | +          repository: adamlui/perplexity-omnibox  | 
 | 21 | +          path: adamlui/perplexity-omnibox  | 
 | 22 | + | 
 | 23 | +      - name: Checkout adamlui/ai-web-extensions  | 
 | 24 | +        uses: actions/checkout@v4  | 
 | 25 | +        with:  | 
 | 26 | +          token: ${{ secrets.REPO_SYNC_PAT }}  | 
 | 27 | +          repository: adamlui/ai-web-extensions  | 
 | 28 | +          path: adamlui/ai-web-extensions  | 
 | 29 | + | 
 | 30 | +      - name: Fetch/sum user counts  | 
 | 31 | +        run: |  | 
 | 32 | +          expand_num() { # expand nums abbreviated w/ 'k' or 'm' suffix to integers  | 
 | 33 | +            local num=$(echo "$1" | tr '[:upper:]' '[:lower:]') # convert to lowercase  | 
 | 34 | +            if [[ $num =~ k$ ]] ; then  | 
 | 35 | +              num="${num%k}" # remove 'k' suffix  | 
 | 36 | +              num=$(awk "BEGIN { printf \"%.0f\", $num * 1000 }") # multiply by 1000  | 
 | 37 | +            elif [[ $num =~ m$ ]] ; then  | 
 | 38 | +              num="${num%m}" # remove 'm' suffix  | 
 | 39 | +              num=$(awk "BEGIN { printf \"%.0f\", $num * 1000000 }") # multiply by 1000000  | 
 | 40 | +            fi ; echo "$num"  | 
 | 41 | +          }  | 
 | 42 | +
  | 
 | 43 | +          format_total() {  | 
 | 44 | +            local num=$1 ; first_digit="${num:0:1}" second_digit="${num:1:1}"  | 
 | 45 | +            second_digit_rounded=$(( second_digit < 5 ? 0 : 5 ))  | 
 | 46 | +            if (( num >= 1000000000 )) ; then # 1B+ w/ one decimal place  | 
 | 47 | +              formatted_num="$(( num / 1000000000 ))"  | 
 | 48 | +              remainder=$(( (num % 1000000000) / 100000000 ))  | 
 | 49 | +              if (( remainder != 0 )) ; then formatted_num+=".$remainder" ; fi  | 
 | 50 | +              formatted_num+="B+"  | 
 | 51 | +            elif (( num >= 10000000 )) ; then # abbr 10,000,000+ to 999,000,000+  | 
 | 52 | +              formatted_num=$(printf "%'.f+" $((( num / 1000000 ) * 1000000 )))  | 
 | 53 | +            elif (( num >= 1000000 )) ; then # abbr 1,000,000+ to 9,500,000+  | 
 | 54 | +              formatted_num="${first_digit},${second_digit}00,000+"  | 
 | 55 | +            elif (( num >= 100000 )) ; then # abbr 100,000+ to 950,000+  | 
 | 56 | +              formatted_num="${first_digit}${second_digit_rounded}0,000+"  | 
 | 57 | +            elif (( num >= 10000 )) ; then # abbr 10,000+ to 90,000+  | 
 | 58 | +              formatted_num="${first_digit}0,000+"  | 
 | 59 | +            elif (( num >= 1000 )) ; then # abbr 1K to 9.9K  | 
 | 60 | +              formatted_num="$(( num / 1000 ))"  | 
 | 61 | +              remainder=$(( (num % 1000) / 100 ))  | 
 | 62 | +              if (( remainder != 0 )) ; then formatted_num+=".$remainder" ; fi  | 
 | 63 | +              formatted_num+="K"  | 
 | 64 | +            else formatted_num="$num" ; fi # preserve <1K as is  | 
 | 65 | +            echo "$formatted_num"  | 
 | 66 | +          }  | 
 | 67 | +
  | 
 | 68 | +          # Fetch Chrome weekly user count  | 
 | 69 | +          base_url="https://img.shields.io/chrome-web-store/users/"  | 
 | 70 | +          app_id="ckhgddjdjkphbaediggjdddjdjgkalom"  | 
 | 71 | +          chrome_users=$(curl -s "$base_url$app_id" |  | 
 | 72 | +            sed -n 's/.*<title>users: \([0-9.k]\+\)*<\/title>.*/\1/Ip')  | 
 | 73 | +          chrome_users=$(expand_num "$chrome_users")  | 
 | 74 | +          echo -e "\nChrome users: $chrome_users"  | 
 | 75 | +
  | 
 | 76 | +          # Fetch Edge active user count  | 
 | 77 | +          base_url="https://microsoftedge.microsoft.com/addons/getproductdetailsbycrxid/"  | 
 | 78 | +          app_id="ffpccpmmcnampmlpdeioklmdjccfmpih"  | 
 | 79 | +          edge_users=$(curl -s "$base_url$app_id" |  | 
 | 80 | +            sed -n 's/.*"activeInstallCount":\([0-9]*\).*/\1/p')  | 
 | 81 | +          echo "Edge users: $edge_users"  | 
 | 82 | +
  | 
 | 83 | +          # Sum user counts  | 
 | 84 | +          total_users=$((chrome_users + edge_users))  | 
 | 85 | +          echo -e "\n-----\nTotal users: $total_users\n-----\n"  | 
 | 86 | +
  | 
 | 87 | +          # Format total  | 
 | 88 | +          formatted_total_users=$(format_total "$total_users")  | 
 | 89 | +          echo "Formatted total users: $formatted_total_users"  | 
 | 90 | +
  | 
 | 91 | +          # Expose total for update step next  | 
 | 92 | +          echo "TOTAL_USERS=$formatted_total_users" >> $GITHUB_ENV  | 
 | 93 | +
  | 
 | 94 | +      - name: Update README shields  | 
 | 95 | +        run: |  | 
 | 96 | +          cd ${{ github.workspace }}/adamlui/perplexity-omnibox  | 
 | 97 | +          TOTAL_USERS="${{ env.TOTAL_USERS }}"  | 
 | 98 | +          if [ "$TOTAL_USERS" == "0" ] ; then echo "Error getting total usercount"  | 
 | 99 | +          else # perform update  | 
 | 100 | +            for readme in $(find docs/ -name "README.md") ; do  | 
 | 101 | +              old_readme=$(<"$readme")  | 
 | 102 | +              sed -i "s/\(badge\/[^-]*-\)[0-9.,km+]\+-/\1$TOTAL_USERS-/gI" "$readme"  | 
 | 103 | +              new_readme=$(<"$readme")  | 
 | 104 | +              if [[ "$old_readme" != "$new_readme" && "$users_updated" != true ]]  | 
 | 105 | +                then users_updated=true ; fi  | 
 | 106 | +            done  | 
 | 107 | +            if [ "$users_updated" = true ] ; then echo "Usercount shields updated to $TOTAL_USERS"  | 
 | 108 | +            else echo "Usercount shields already up-to-date" ; fi  | 
 | 109 | +          fi  | 
 | 110 | +
  | 
 | 111 | +          # Set Updated flag to check in subseuqent steps  | 
 | 112 | +          if [ "$users_updated" = true ] ; then echo "USERS_UPDATED=true" >> $GITHUB_ENV ; fi  | 
 | 113 | +
  | 
 | 114 | +      - name: Sync ** to adamlui/ai-web-extensions/perplexity-omnibox/  | 
 | 115 | +        if: env.USERS_UPDATED == 'true'  | 
 | 116 | +        run: |  | 
 | 117 | +          rsync -avhr --delete --exclude={'.*','eslint*','package*json'} \  | 
 | 118 | +            ${{ github.workspace }}/adamlui/perplexity-omnibox/ \  | 
 | 119 | +            ${{ github.workspace }}/adamlui/ai-web-extensions/perplexity-omnibox/  | 
 | 120 | +        | 
 | 121 | +      - name: Config committer  | 
 | 122 | +        if: env.USERS_UPDATED == 'true'  | 
 | 123 | +        run: |  | 
 | 124 | +          gpg --batch --import <(echo "${{ secrets.GPG_PRIVATE_KEY }}")  | 
 | 125 | +          git config --global commit.gpgsign true  | 
 | 126 | +          git config --global user.name "kudo-sync-bot"  | 
 | 127 | +          git config --global user.email "[email protected]"  | 
 | 128 | +          git config --global user.signingkey "${{ secrets.GPG_PRIVATE_ID }}"  | 
 | 129 | +
  | 
 | 130 | +      - name: Push changes to adamlui/perplexity-omnibox  | 
 | 131 | +        if: env.USERS_UPDATED == 'true'  | 
 | 132 | +        run: |  | 
 | 133 | +          cd ${{ github.workspace }}/adamlui/perplexity-omnibox  | 
 | 134 | +          git add .  | 
 | 135 | +          git commit -n -m "Updated usercount shield counters in root READMEs" || true  | 
 | 136 | +          git push  | 
 | 137 | +
  | 
 | 138 | +      - name: Push changes to adamlui/ai-web-extensions  | 
 | 139 | +        if: env.USERS_UPDATED == 'true'  | 
 | 140 | +        run: |  | 
 | 141 | +          cd ${{ github.workspace }}/adamlui/ai-web-extensions  | 
 | 142 | +          git add .  | 
 | 143 | +          git commit -n -m "Updated usercount shield counters in ChatGPT Widescreen root READMEs" || true  | 
 | 144 | +          git push  | 
0 commit comments