Update Visits #980
This file contains 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 Visits | |
on: | |
push: | |
branches: | |
- main | |
schedule: | |
# Runs every 5 minutes | |
- cron: '*/5 * * * *' # Runs every 5 minutes | |
jobs: | |
update-visits: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Increment visit counter | |
id: increment | |
run: | | |
if [ ! -f visits.txt ]; then echo "0" > visits.txt; fi | |
visits=$(cat visits.txt) | |
visits=$((visits + 1)) | |
echo $visits > visits.txt | |
echo "::set-output name=visits::$visits" | |
- name: Update README.md | |
run: | | |
visits=${{ steps.increment.outputs.visits }} | |
badge="![Visits](https://img.shields.io/badge/Visits-$visits-blue)" | |
sed -i 's|!\[Visits\](https://img.shields.io/badge/Visits-.*-blue)|'"$badge"'|' README.md | |
- name: Commit changes | |
run: | | |
git config --local user.email "actions@github.com" | |
git config --local user.name "GitHub Actions" | |
git add visits.txt README.md | |
git commit -m 'Update visits count' | |
git push |