Weekly clone stats #13
Workflow file for this run
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: Weekly Clone Stats Email | |
on: | |
schedule: | |
- cron: '0 8 * * 1' # Every Monday at 08:00 UTC | |
pull_request: | |
branches: | |
- main | |
permissions: | |
contents: read | |
jobs: | |
fetch-clone-stats: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Fetch Clone Stats | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
run: | | |
REPO="${{ github.repository }}" | |
curl -L \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $GITHUB_TOKEN" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/repos/$REPO/traffic/clones > clone_stats.json | |
- name: Upload Clone Stats | |
uses: actions/upload-artifact@v4 | |
with: | |
name: clone-stats | |
path: clone_stats.json | |
print-stats: | |
needs: fetch-clone-stats | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Download Clone Stats | |
uses: actions/download-artifact@v4 | |
with: | |
name: clone-stats | |
path: . | |
- name: Print raw JSON | |
run: cat clone_stats.json | |
- name: Parse clone stats | |
id: parse | |
run: | | |
COUNT=$(jq '.count' clone_stats.json) | |
UNIQUES=$(jq '.uniques' clone_stats.json) | |
echo "count=$COUNT" >> "$GITHUB_OUTPUT" | |
echo "uniques=$UNIQUES" >> "$GITHUB_OUTPUT" | |
- name: Send email | |
uses: dawidd6/action-send-mail@v3 | |
with: | |
# Replace with your SMTP server, port, and credentials | |
server_address: smtp.sendgrid.net | |
server_port: 587 | |
username: ${{ secrets.SMTP_USERNAME }} | |
password: ${{ secrets.SMTP_PASSWORD }} | |
subject: "📊 Weekly GitHub Clone Stats for ${{ github.repository }}" | |
to: ${{ vars.EMAIL_TO }} | |
from: ${{ vars.EMAIL_FROM }} | |
# "text/html" is optional if you want to send as HTML | |
content_type: text/plain | |
secure: true | |
body: | | |
Hi, | |
Here are the clone stats for *${{ github.repository }}* this week: | |
🔁 Total Clones: ${{ steps.parse.outputs.count }} | |
👤 Unique Cloners: ${{ steps.parse.outputs.uniques }} | |
– GitHub Bot |