diff --git a/.github/workflows/docker-pulls-history.yml b/.github/workflows/docker-pulls-history.yml new file mode 100644 index 0000000..6e8e0bd --- /dev/null +++ b/.github/workflows/docker-pulls-history.yml @@ -0,0 +1,76 @@ +name: Docker Pulls History + +on: + schedule: + - cron: "0 0 * * *" # 每天 UTC 00:00(台灣 08:00) + workflow_dispatch: + +jobs: + track: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Fetch Docker Hub pull count + run: | + set -e + DATE=$(date -u +"%Y-%m-%d") + PULLS=$(curl -s https://hub.docker.com/v2/repositories/convertx/convertx-cn/ | jq '.pull_count') + echo "$DATE,$PULLS" >> metrics/docker-pulls.csv + + - name: Generate SVG chart + run: | + node <<'EOF' + const fs = require('fs'); + + const csv = fs.readFileSync('metrics/docker-pulls.csv', 'utf8') + .trim() + .split('\n') + .slice(1); + + const dates = csv.map(r => r.split(',')[0]); + const pulls = csv.map(r => Number(r.split(',')[1])); + + const svg = ` + + + + + + + Docker Pull History – convertx/convertx-cn + + + ${pulls.map((v, i) => { + if (i === 0) return ''; + const x1 = 60 + (i - 1) * (680 / (pulls.length - 1)); + const y1 = 340 - (pulls[i - 1] / Math.max(...pulls)) * 260; + const x2 = 60 + i * (680 / (pulls.length - 1)); + const y2 = 340 - (v / Math.max(...pulls)) * 260; + return ``; + }).join('')} + + ${dates[0]} + ${dates[dates.length - 1]} + + ${Math.max(...pulls).toLocaleString()} + + `; + + fs.writeFileSync('metrics/docker-pulls-history.svg', svg); + EOF + + - name: Commit and push + run: | + git config user.name "github-actions" + git config user.email "actions@github.com" + git add metrics + git commit -m "chore(metrics): update docker pull history" || exit 0 + git push