Skip to content

Bug: Update contributors workflow fails due to branch protection #910

@SchoolyB

Description

@SchoolyB

Description

The "update contributors" GitHub Actions workflow fails because it attempts to push directly to the protected main branch.

Error Output

Run git config --local user.email "github-actions[bot]@users.noreply.github.com"
[main f4d101a] chore: update contributors in README
 1 file changed, 2 insertions(+)
remote: error: GH006: Protected branch update failed for refs/heads/main.        
remote: 
remote: - Changes must be made through a pull request.        
To https://github.com/SchoolyB/EZ
 ! [remote rejected] main -> main (protected branch hook declined)
error: failed to push some refs to 'https://github.com/SchoolyB/EZ'
Error: Process completed with exit code 1.

Cause

Branch protection rules on main require changes to be made through a pull request. The workflow currently commits and pushes directly to main (lines 101-108 in .github/workflows/update-contributors.yml).

Fix

Replace the "Commit changes" step (lines 101-108) with logic to create a branch and open a PR:

      - name: Create Pull Request
        if: steps.check.outputs.changed == 'true'
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          BRANCH="chore/update-contributors-$(date +%Y%m%d)"
          git config --local user.email "github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git checkout -b "$BRANCH"
          git add README.md
          git commit -m "chore: update contributors in README"
          git push -u origin "$BRANCH"
          gh pr create --title "chore: update contributors in README" --body "Automated PR to add new contributors to README." --base main

Also add pull-requests: write to the permissions block:

    permissions:
      contents: write
      pull-requests: write

Metadata

Metadata

Assignees

No one assigned

    Labels

    CI/CDContinuous Integration/Continuous DeploymentbugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions