diff --git a/.github/workflows/update-md-date.yml b/.github/workflows/update-md-date.yml index ac7a96d..ffc678c 100644 --- a/.github/workflows/update-md-date.yml +++ b/.github/workflows/update-md-date.yml @@ -18,6 +18,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + ref: ${{ github.head_ref || github.ref_name }} - name: Set up Python uses: actions/setup-python@v4 @@ -35,13 +36,23 @@ jobs: - name: Update last modified date in Markdown files run: python .github/workflows/update_date.py - - name: Commit changes + - name: Commit and merge changes env: - TOKEN: ${{ secrets.GITHUB_TOKEN }} + 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: | - git fetch origin ${{ github.event.pull_request.head.ref }} - git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo "No rebase needed" + # Ensure we're on the correct branch + git switch -c "$PR_BRANCH" || git switch "$PR_BRANCH" + + # Stage and commit changes if any git add -A - git commit -m "Update last modified date in Markdown files" || echo "No changes to commit" - git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }} - git push origin HEAD:${{ github.event.pull_request.head.ref }} + git diff --staged --quiet || git commit -m "Update last modified date in Markdown files" + + # Pull and merge existing changes + git pull origin "$PR_BRANCH" --no-rebase + + # Push all changes + git push origin "$PR_BRANCH" diff --git a/.github/workflows/use-visitor-counter.yml b/.github/workflows/use-visitor-counter.yml index 4aa2c96..973fb24 100644 --- a/.github/workflows/use-visitor-counter.yml +++ b/.github/workflows/use-visitor-counter.yml @@ -21,6 +21,7 @@ jobs: 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 @@ -57,38 +58,23 @@ jobs: git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" - - name: Commit and push changes (PR) - if: github.event_name == 'pull_request' + - name: Commit and merge changes env: - TOKEN: ${{ secrets.GITHUB_TOKEN }} + 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: | - git fetch origin - git checkout -b ${{ github.event.pull_request.head.ref }} origin/${{ github.event.pull_request.head.ref }} - git add "*.md" metrics.json - git commit -m "Update visitor count" || echo "No changes to commit" - git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }} - git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo "No rebase needed" - git push origin HEAD:${{ github.event.pull_request.head.ref }} - - - name: Commit and push changes (non-PR) - if: github.event_name != 'pull_request' - env: - TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - git fetch origin - git checkout ${{ github.event.pull_request.head.ref }} || git checkout -b ${{ github.event.pull_request.head.ref }} origin/${{ github.event.pull_request.head.ref }} - git add "*.md" metrics.json - git commit -m "Update visitor count" || echo "No changes to commit" - git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }} - git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo "No rebase needed" - git push origin HEAD:${{ github.event.pull_request.head.ref }} - - - name: Create Pull Request (non-PR) - if: github.event_name != 'pull_request' - uses: peter-evans/create-pull-request@v6 - with: - token: ${{ secrets.GITHUB_TOKEN }} - branch: update-visitor-count - title: "Update visitor count" - body: "Automated update of visitor count" - base: main + # Ensure we're on the correct branch + git switch -c "$PR_BRANCH" || git switch "$PR_BRANCH" + + # Stage and commit changes if any + git add -A + git diff --staged --quiet || git commit -m "Update visitor count" + + # Pull and merge existing changes + git pull origin "$PR_BRANCH" --no-rebase + + # Push all changes + git push origin "$PR_BRANCH" diff --git a/README.md b/README.md index bdfe19d..58ac866 100644 --- a/README.md +++ b/README.md @@ -447,7 +447,7 @@ Last updated: 2025-07-21
Refresh Date: 2025-07-21
Refresh Date: 2025-07-21