diff --git a/.github/workflows/download_count.yaml b/.github/workflows/download_count.yaml new file mode 100644 index 000000000..b01476dce --- /dev/null +++ b/.github/workflows/download_count.yaml @@ -0,0 +1,47 @@ +name: Update Download Count + +on: + workflow_dispatch: + schedule: + - cron: "0 0 * * *" + +jobs: + update-downloads: + name: Update Download Count + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + + - name: Get download count + run: | + # check downloads + downloads=$(curl https://api.npmjs.org/downloads/point/1970-01-01:$(date -d '+1 day' +"%Y-%m-%d")/colorjs.io | jq -r .downloads) + echo "Latest download count: $downloads" + # into millions + downloads=$(( (downloads + 500000) / 1000000 )) + # try to find current download count in readme + readme=$( README.md + else + echo "New count ($downloads million) is less than or equal to current $current_downloads million; not doing anything." + fi + fi + echo Done! + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842 # v5.0.1 + with: + commit_message: Update README download count + file_pattern: README.md + # default github-actions user info as commit author + commit_author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>