Merge pull request #25 from leeoades/copilot/secure-main-branch-settings #2
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: Apply Branch Protection | ||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: [main] | ||
| paths: ['.github/workflows/branch-protection.yml'] | ||
| permissions: | ||
| contents: read | ||
| administration: write | ||
| jobs: | ||
| protect-main: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Apply main branch protection rules | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| await github.rest.repos.updateBranchProtection({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| branch: 'main', | ||
| required_status_checks: null, | ||
| enforce_admins: true, | ||
| required_pull_request_reviews: { | ||
| required_approving_review_count: 1, | ||
| dismiss_stale_reviews: true, | ||
| require_code_owner_reviews: true, | ||
| }, | ||
| restrictions: null, | ||
| allow_force_pushes: false, | ||
| allow_deletions: false, | ||
| }); | ||
| console.log('Branch protection rules applied to main.'); | ||