From 69309a1b9c7c279e0b44f7239f4d505bbea9dd63 Mon Sep 17 00:00:00 2001 From: Shantanu Wable <97496261+shxntanu@users.noreply.github.com> Date: Sun, 5 Jan 2025 00:18:01 +0530 Subject: [PATCH] Create update-visits.yml --- .github/workflows/update-visits.yml | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/update-visits.yml diff --git a/.github/workflows/update-visits.yml b/.github/workflows/update-visits.yml new file mode 100644 index 0000000..249d199 --- /dev/null +++ b/.github/workflows/update-visits.yml @@ -0,0 +1,39 @@ +name: Update Visits + +on: + push: + branches: + - main + schedule: + - 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 --global user.name 'github-actions' + git config --global user.email 'github-actions@github.com' + git add visits.txt README.md + git commit -m 'Update visits count' + git push