From fd60757092e34e3a1b12cd20882dbbf8bfd80dbd Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Fri, 9 Jun 2023 15:45:27 -0700 Subject: [PATCH 1/5] CI: Fix the deprecation tracking bot --- .../workflows/deprecation-tracking-bot.yml | 48 ++++++++++++++++--- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deprecation-tracking-bot.yml b/.github/workflows/deprecation-tracking-bot.yml index c0d871ed54ed6..cb3186850d57a 100644 --- a/.github/workflows/deprecation-tracking-bot.yml +++ b/.github/workflows/deprecation-tracking-bot.yml @@ -1,11 +1,13 @@ +# This bot updates the issue with number DEPRECATION_TRACKER_ISSUE +# with the PR number that issued the deprecation. + +# It runs on commits to main, and will trigger if the PR linked to a merged commit has the "Deprecate" label name: Deprecations Bot on: - pull_request: + push: branches: - - main - types: - [closed] + - test permissions: @@ -15,12 +17,44 @@ jobs: deprecation_update: permissions: issues: write - if: >- - contains(github.event.pull_request.labels.*.name, 'Deprecate') && github.event.pull_request.merged == true runs-on: ubuntu-22.04 env: - DEPRECATION_TRACKER_ISSUE: 50578 + DEPRECATION_TRACKER_ISSUE: 35 steps: + - uses: actions/github-script@v6 + id: update-deprecation-issue + with: + script: | + body = github.rest.issues.get({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ${DEPRECATION_TRACKER_ISSUE}, + })["body"] + // Add the PR number to body + // (we always get the first linked PR) + linkedPR = github.rest.issues.get({ + owner: context.repo.owner, + repo: context.repo.repo, + commit_sha: ${{ GITHUB_SHA }} + })[0] + + isDeprecation = false + for (label in linkedPR["labels"]) { + if (label["name"] == "Deprecate") { + isDeprecation = true; + break; + } + } + + PR_NUMBER = linkedPR["number"]; + + body += ("- [ ] #" + PR_NUMBER); + github.rest.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ${DEPRECATION_TRACKER_ISSUE}, + body: body + }) - name: Checkout run: | echo "Adding deprecation PR number to deprecation tracking issue" From cb5e7bcbb4ca17ba3c25a295baa5583b9a92322f Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Fri, 9 Jun 2023 15:51:48 -0700 Subject: [PATCH 2/5] Update deprecation-tracking-bot.yml --- .github/workflows/deprecation-tracking-bot.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deprecation-tracking-bot.yml b/.github/workflows/deprecation-tracking-bot.yml index cb3186850d57a..e7f4cb007e298 100644 --- a/.github/workflows/deprecation-tracking-bot.yml +++ b/.github/workflows/deprecation-tracking-bot.yml @@ -28,14 +28,14 @@ jobs: body = github.rest.issues.get({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: ${DEPRECATION_TRACKER_ISSUE}, + issue_number: ${{ env.DEPRECATION_TRACKER_ISSUE }}, })["body"] // Add the PR number to body // (we always get the first linked PR) linkedPR = github.rest.issues.get({ owner: context.repo.owner, repo: context.repo.repo, - commit_sha: ${{ GITHUB_SHA }} + commit_sha: ${{ github.sha }} })[0] isDeprecation = false @@ -52,7 +52,7 @@ jobs: github.rest.issues.update({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: ${DEPRECATION_TRACKER_ISSUE}, + issue_number: ${{ env.DEPRECATION_TRACKER_ISSUE }}, body: body }) - name: Checkout From 2286bb6e7e051fcfc8ad3624b4d83e8c2623dc2a Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Fri, 9 Jun 2023 16:39:22 -0700 Subject: [PATCH 3/5] Update deprecation-tracking-bot.yml --- .github/workflows/deprecation-tracking-bot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deprecation-tracking-bot.yml b/.github/workflows/deprecation-tracking-bot.yml index e7f4cb007e298..4ea2ae89f73e0 100644 --- a/.github/workflows/deprecation-tracking-bot.yml +++ b/.github/workflows/deprecation-tracking-bot.yml @@ -35,7 +35,7 @@ jobs: linkedPR = github.rest.issues.get({ owner: context.repo.owner, repo: context.repo.repo, - commit_sha: ${{ github.sha }} + commit_sha: '${{ github.sha }}' })[0] isDeprecation = false From c8e065919f6ec622ed2d277dd8e190859d257f5c Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Sat, 10 Jun 2023 07:47:04 -0700 Subject: [PATCH 4/5] Updates --- .../workflows/deprecation-tracking-bot.yml | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/.github/workflows/deprecation-tracking-bot.yml b/.github/workflows/deprecation-tracking-bot.yml index 4ea2ae89f73e0..35c923d957024 100644 --- a/.github/workflows/deprecation-tracking-bot.yml +++ b/.github/workflows/deprecation-tracking-bot.yml @@ -25,41 +25,41 @@ jobs: id: update-deprecation-issue with: script: | - body = github.rest.issues.get({ + body = await github.rest.issues.get({ owner: context.repo.owner, repo: context.repo.repo, issue_number: ${{ env.DEPRECATION_TRACKER_ISSUE }}, - })["body"] - // Add the PR number to body - // (we always get the first linked PR) - linkedPR = github.rest.issues.get({ + }) + body = body["data"]["body"]; + linkedPRs = await github.rest.repos.listPullRequestsAssociatedWithCommit({ owner: context.repo.owner, repo: context.repo.repo, commit_sha: '${{ github.sha }}' - })[0] - - isDeprecation = false - for (label in linkedPR["labels"]) { - if (label["name"] == "Deprecate") { - isDeprecation = true; - break; + }) + linkedPRs = linkedPRs["data"]; + console.log(linkedPRs); + if (linkedPRs.length > 0) { + console.log("Found linked PR"); + linkedPR = linkedPRs[0] + isDeprecation = false + for (label of linkedPR["labels"]) { + if (label["name"] == "Deprecate") { + isDeprecation = true; + break; + } + } + + PR_NUMBER = linkedPR["number"]; + + body += ("\n- [ ] #" + PR_NUMBER); + if (isDeprecation) { + console.log("PR is a deprecation PR. Printing new body of issue"); + console.log(body); + github.rest.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ${{ env.DEPRECATION_TRACKER_ISSUE }}, + body: body + }) } } - - PR_NUMBER = linkedPR["number"]; - - body += ("- [ ] #" + PR_NUMBER); - github.rest.issues.update({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: ${{ env.DEPRECATION_TRACKER_ISSUE }}, - body: body - }) - - name: Checkout - run: | - echo "Adding deprecation PR number to deprecation tracking issue" - export PR=${{ github.event.pull_request.number }} - BODY=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/issues/${DEPRECATION_TRACKER_ISSUE} | - python3 -c "import sys, json, os; x = {'body': json.load(sys.stdin)['body']}; pr = os.environ['PR']; x['body'] += f'\n- [ ] #{pr}'; print(json.dumps(x))") - echo ${BODY} - curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -X PATCH -d "${BODY}" https://api.github.com/repos/${{ github.repository }}/issues/${DEPRECATION_TRACKER_ISSUE} From 9b959a285b23bafac5b9d75b8ba80e372eaf6c3a Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Sat, 10 Jun 2023 07:48:22 -0700 Subject: [PATCH 5/5] Update deprecation-tracking-bot.yml --- .github/workflows/deprecation-tracking-bot.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deprecation-tracking-bot.yml b/.github/workflows/deprecation-tracking-bot.yml index 35c923d957024..b3f9bcd840c68 100644 --- a/.github/workflows/deprecation-tracking-bot.yml +++ b/.github/workflows/deprecation-tracking-bot.yml @@ -7,7 +7,7 @@ name: Deprecations Bot on: push: branches: - - test + - main permissions: @@ -19,7 +19,7 @@ jobs: issues: write runs-on: ubuntu-22.04 env: - DEPRECATION_TRACKER_ISSUE: 35 + DEPRECATION_TRACKER_ISSUE: 50578 steps: - uses: actions/github-script@v6 id: update-deprecation-issue