From 9ed5b1c4fb2128a0d44938d837624f97c08c3111 Mon Sep 17 00:00:00 2001 From: Rakshith B <79500257+Rakshithb1@users.noreply.github.com> Date: Fri, 12 Jan 2024 15:24:37 +0530 Subject: [PATCH] Update add-checks.yml Signed-off-by: Rakshith B <79500257+Rakshithb1@users.noreply.github.com> --- .github/workflows/add-checks.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/workflows/add-checks.yml b/.github/workflows/add-checks.yml index 5958d1da30d..80ab3379bd1 100644 --- a/.github/workflows/add-checks.yml +++ b/.github/workflows/add-checks.yml @@ -13,7 +13,29 @@ jobs: - name: Checkout code uses: actions/checkout@v2 + - name: Add branch protection rule + run: | + TOKEN=$GITHUB_TOKEN + REPO_OWNER=${{ github.repository_owner }} + REPO_NAME=${{ github.event.repository.name }} + BRANCH_NAME=${{ github.event.ref }} + + # Create a branch protection rule + curl -X PUT \ + -H "Authorization: Bearer $TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/branches/$BRANCH_NAME/protection \ + -d '{ + "required_status_checks": { + "contexts": ["your-check-name"] + }, + "enforce_admins": true, + "required_pull_request_reviews": null, + "restrictions": null + }' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Add branch protection rule run: |