From b5379e0e57f71a3e8368600232fd8a1f83603fac Mon Sep 17 00:00:00 2001
From: Liz Baker <lbaker@newrelic.com>
Date: Thu, 24 Oct 2024 10:11:38 -0700
Subject: [PATCH] fix: Disable branch protection for publish

---
 .github/workflows/release.yml | 40 +++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 0a8af4013..5aa6c6349 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -34,6 +34,25 @@ jobs:
         run: |
           echo "//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN" > .npmrc
 
+      - name: Temporarily disable "required_pull_request_reviews" branch protection
+        id: disable-branch-protection
+        if: always()
+        uses: actions/github-script@v6
+        with:
+          github-token: ${{ secrets.DOCS_ENG_BOT_TOKEN }}
+          previews: luke-cage-preview
+          script: |
+            const result = await github.rest.repos.updateBranchProtection({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              branch: 'main',
+              required_status_checks: null,
+              restrictions: null,
+              enforce_admins: null,
+              required_pull_request_reviews: null
+            })
+            console.log("Result:", result)
+
       - name: Lerna Publish
         env:
           GIT_AUTHOR_NAME: ${{ env.BOT_NAME }}
@@ -42,3 +61,24 @@ jobs:
           GIT_COMMITTER_EMAIL: ${{ env.BOT_EMAIL }}
           GH_TOKEN: ${{ secrets.DOCS_ENG_BOT_TOKEN }}
         run: yarn release
+
+      - name: Re-enable "required_pull_request_reviews" branch protection
+        id: enable-branch-protection
+        if: always()
+        uses: actions/github-script@v6
+        with:
+          github-token: ${{ secrets.DOCS_ENG_BOT_TOKEN }}
+          previews: luke-cage-preview
+          script: |
+            const result = await github.rest.repos.updateBranchProtection({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              branch: 'main',
+              required_status_checks: null,
+              restrictions: null,
+              enforce_admins: true,
+              required_pull_request_reviews: {
+                required_approving_review_count: 0
+              }
+            })
+            console.log("Result:", result)