Update Badge Stats #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Badge Stats | |
| on: | |
| schedule: | |
| - cron: '0 6,14,22 * * *' | |
| workflow_dispatch: | |
| jobs: | |
| update-badges: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Fetch VS Code Marketplace stats | |
| id: vscode | |
| run: | | |
| RESPONSE=$(curl -s -X POST \ | |
| 'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery' \ | |
| -H 'Content-Type: application/json' \ | |
| -H 'Accept: application/json;api-version=7.2-preview.1' \ | |
| -d '{ | |
| "filters": [{ | |
| "criteria": [{"filterType": 7, "value": "pablodelucca.pixel-agents"}] | |
| }], | |
| "flags": 914 | |
| }') | |
| INSTALLS=$(echo "$RESPONSE" | jq '[.results[0].extensions[0].statistics[] | select(.statisticName == "install") | .value][0] // 0 | floor') | |
| DOWNLOADS=$(echo "$RESPONSE" | jq '[.results[0].extensions[0].statistics[] | select(.statisticName == "downloadCount") | .value][0] // 0 | floor') | |
| VERSION=$(echo "$RESPONSE" | jq -r '.results[0].extensions[0].versions[0].version // "unknown"') | |
| echo "installs=$INSTALLS" >> "$GITHUB_OUTPUT" | |
| echo "downloads=$DOWNLOADS" >> "$GITHUB_OUTPUT" | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Fetch Open VSX stats | |
| id: openvsx | |
| run: | | |
| DOWNLOADS=$(curl -s 'https://open-vsx.org/api/pablodelucca/pixel-agents' | jq '.downloadCount // 0') | |
| echo "downloads=$DOWNLOADS" >> "$GITHUB_OUTPUT" | |
| - name: Format install count | |
| id: format | |
| run: | | |
| TOTAL=$(( ${{ steps.vscode.outputs.installs }} + ${{ steps.vscode.outputs.downloads }} + ${{ steps.openvsx.outputs.downloads }} )) | |
| if [ "$TOTAL" -ge 1000 ]; then | |
| MSG="$(awk "BEGIN {printf \"%.1f\", $TOTAL / 1000}")k installs" | |
| else | |
| MSG="$TOTAL installs" | |
| fi | |
| echo "message=$MSG" >> "$GITHUB_OUTPUT" | |
| - name: Update version badge in gist | |
| uses: schneegans/dynamic-badges-action@v1.7.0 | |
| with: | |
| auth: ${{ secrets.GIST_SECRET }} | |
| gistID: ${{ secrets.GIST_ID }} | |
| filename: version.json | |
| label: version | |
| message: v${{ steps.vscode.outputs.version }} | |
| color: '0183ff' | |
| namedLogo: visualstudiocode | |
| logoColor: white | |
| - name: Update installs badge in gist | |
| uses: schneegans/dynamic-badges-action@v1.7.0 | |
| with: | |
| auth: ${{ secrets.GIST_SECRET }} | |
| gistID: ${{ secrets.GIST_ID }} | |
| filename: installs.json | |
| label: marketplaces | |
| message: ${{ steps.format.outputs.message }} | |
| color: '0183ff' |