Update docs for Cloud2BR org rename #143
Workflow file for this run
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: Use Visitor Counter Logic | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_dispatch: # Allows manual triggering | |
| # schedule: | |
| # - cron: '0 0 * * *' # Runs daily at midnight | |
| 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: Shallow clone visitor counter logic | |
| run: git clone --depth=1 https://github.com/brown9804/github-visitor-counter.git | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install dependencies for github-visitor-counter | |
| run: | | |
| cd github-visitor-counter | |
| npm ci | |
| - name: Run visitor counter logic (updates markdown badges and metrics.json) | |
| run: node github-visitor-counter/update_repo_views_counter.js | |
| env: | |
| TRAFFIC_TOKEN: ${{ secrets.TRAFFIC_TOKEN }} | |
| REPO: ${{ github.repository }} | |
| - name: Move generated metrics.json to root | |
| run: mv github-visitor-counter/metrics.json . | |
| - name: List files for debugging | |
| run: | | |
| ls -l | |
| ls -l github-visitor-counter | |
| - name: Clean up visitor counter logic | |
| run: rm -rf github-visitor-counter | |
| - 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 }} | |
| 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: | | |
| set -euo pipefail | |
| # Ensure we're on the correct branch | |
| git switch -c "$PR_BRANCH" || git switch "$PR_BRANCH" | |
| # Rebase onto the latest remote branch state before creating a commit. | |
| git fetch origin "$PR_BRANCH" | |
| git rebase "origin/$PR_BRANCH" | |
| # Stage and commit changes if any. | |
| git add -A | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| exit 0 | |
| fi | |
| git commit -m "Update visitor count" | |
| # Retry the push after rebasing if another update lands first. | |
| for attempt in 1 2 3; do | |
| if git push origin HEAD:"$PR_BRANCH"; then | |
| exit 0 | |
| fi | |
| echo "Push rejected on attempt $attempt; fetching and rebasing" | |
| git fetch origin "$PR_BRANCH" | |
| git rebase "origin/$PR_BRANCH" | |
| done | |
| echo "Failed to push visitor count updates after 3 attempts" | |
| exit 1 |