Implement Continuous Integration Workflow for Vercel Auto-Deployment #4
This file contains 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: Enforce Branch Naming and Protection | |
on: [push, pull_request] | |
jobs: | |
branch_protection: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.x' | |
- name: Install Dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install requests | |
- name: Protect master branch | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
import requests | |
import json | |
headers = { | |
'Authorization': 'token ' + os.environ['GITHUB_TOKEN'], | |
'Accept': 'application/vnd.github.v3+json', | |
} | |
data = { | |
'required_status_checks': { | |
'strict': True, | |
'contexts': [] | |
}, | |
'enforce_admins': True, | |
'required_pull_request_reviews': { | |
'required_approving_review_count': 1 | |
}, | |
'restrictions': None | |
} | |
response = requests.put( | |
'https://api.github.com/repos/${{ github.repository }}/branches/master/protection', | |
headers=headers, | |
data=json.dumps(data) | |
) | |
if response.status_code == 200: | |
print('Branch protection rules set successfully.') | |
else: | |
print('Failed to set branch protection rules. Status code:', response.status_code) | |