Skip to content

chore: align badges and workflows with org template #2

chore: align badges and workflows with org template

chore: align badges and workflows with org template #2

name: Use Visitor Counter Logic
on:
pull_request:
branches:
- main
workflow_dispatch:
concurrency:
group: pr-branch-maintenance-${{ github.event.pull_request.head.ref || github.ref_name }}
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
jobs:
update-visitor-count:
runs-on: ubuntu-latest
steps:
- name: Checkout current repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref || github.ref_name }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Run vendored visitor counter logic
env:
TRAFFIC_TOKEN: ${{ secrets.TRAFFIC_TOKEN }}
REPO: ${{ github.repository }}
run: node .github/scripts/update_visitor_counter.js
- name: Configure Git author
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit and merge changes
env:
PR_BRANCH: ${{ github.head_ref || github.ref_name }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_AUTHOR_NAME: github-actions[bot]
GIT_AUTHOR_EMAIL: github-actions[bot]@users.noreply.github.com
GIT_COMMITTER_NAME: github-actions[bot]
GIT_COMMITTER_EMAIL: github-actions[bot]@users.noreply.github.com
run: |
git switch -c "$PR_BRANCH" || git switch "$PR_BRANCH"
git add -A
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi
git commit -m "Update visitor count"
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
for attempt in 1 2 3; do
git fetch origin "$PR_BRANCH"
git rebase "origin/$PR_BRANCH"
if git push origin HEAD:"$PR_BRANCH"; then
exit 0
fi
done
echo "Failed to push branch updates after 3 attempts."
exit 1