-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rakshith B <79500257+Rakshithb1@users.noreply.github.com>
- Loading branch information
1 parent
4a72492
commit 6a21237
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Add Branch Protection | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
add-branch-protection: | ||
runs-on: ubuntu-latest | ||
env: | ||
G_TOKEN: ${{ secrets.SSTOKEN }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Read values from CSV | ||
id: read-values | ||
run: | | ||
CSV_CONTENT=$(tail -n +2 status_checks.csv) | ||
REPO_NAMES=($(echo "$CSV_CONTENT" | cut -d ',' -f 1)) | ||
BRANCH_NAMES=($(echo "$CSV_CONTENT" | cut -d ',' -f 2)) | ||
CHECKS=($(echo "$CSV_CONTENT" | cut -d ',' -f 3)) | ||
echo "::set-output name=repo_names::${REPO_NAMES[@]}" | ||
echo "::set-output name=branch_names::${BRANCH_NAMES[@]}" | ||
echo "::set-output name=checks::${CHECKS[@]}" | ||
- name: Add branch protection rule | ||
run: | | ||
REPO_NAMES=(${{ steps.read-values.outputs.repo_names | toJson }}) | ||
BRANCH_NAMES=(${{ steps.read-values.outputs.branch_names | toJson }}) | ||
CHECKS=(${{ steps.read-values.outputs.checks | toJson }}) | ||
for i in $(seq 0 $((${#REPO_NAMES[@]} - 1))); do | ||
REPO_NAME=${REPO_NAMES[$i]} | ||
BRANCH_NAME=${BRANCH_NAMES[$i]} | ||
CHECK=${CHECKS[$i]} | ||
# Create a branch protection rule | ||
curl -X PUT \ | ||
-H "Authorization: Bearer $G_TOKEN" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
https://api.github.com/repos/$REPO_NAME/$BRANCH_NAME/protection \ | ||
-d "{ | ||
\"required_status_checks\": { | ||
\"contexts\": [\"$CHECK\"] | ||
}, | ||
}" | ||
done |