Updated with Dev Metrics #49
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 README with WakaTime Stats | |
on: | |
schedule: | |
- cron: "0 0 * * *" | |
push: | |
branches: | |
- main | |
jobs: | |
update-readme: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Update Readme with matrices | |
uses: anmol098/waka-readme-stats@master | |
with: | |
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }} | |
GH_TOKEN: ${{ secrets.GH_PAT }} | |
SHOW_OS: "False" | |
SHOW_PROJECTS: "False" | |
- name: Install jq | |
run: sudo apt-get install -y jq | |
- name: Fetch WakaTime stats | |
id: wakatime | |
run: | | |
curl -s "https://wakatime.com/api/v1/users/current/stats/last_7_days?api_key=${{ secrets.WAKATIME_API_KEY }}" > wakatime.json | |
- name: Update README | |
run: | | |
wakatime_stats=$(jq -r '.data.languages | map("\(.name): \(.text)") | join("\n")' wakatime.json) | |
echo "## 📊 WakaTime Stats\n\n$wakatime_stats" > WAKATIME.md | |
awk 'NR==FNR{a[++d]=$0;next}/<!--START_SECTION:waka-->/{print;print "<!--WAKATIME_STATS_START-->";for(i=1;i<=d;i++)print a[i];print "<!--WAKATIME_STATS_END-->";next}1' WAKATIME.md README.md > README_tmp.md | |
mv README_tmp.md README.md | |
- name: Commit changes | |
run: | | |
git config --global user.name 'github-actions' | |
git config --global user.email 'github-actions@github.com' | |
git add README.md WAKATIME.md wakatime.json | |
git diff --quiet && git diff --staged --quiet || git commit -m 'Update README with WakaTime stats' | |
- name: Pull latest changes | |
run: git pull origin main --rebase | |
- name: Push changes | |
env: | |
GH_PAT: ${{ secrets.GH_PAT }} | |
run: | | |
git remote set-url origin https://${{ secrets.GH_PAT }}@github.com/${{ github.repository }}.git | |
git push origin main |