From e2dc4219add64f4412b212c4c20c9012589b2392 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Mon, 30 Jan 2023 10:18:03 -0500 Subject: [PATCH] Post about merged PR going into production (#34095) --- .github/actions-scripts/find-past-built-pr.js | 44 +++++++++++++ .github/workflows/notify-about-deployment.yml | 63 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100755 .github/actions-scripts/find-past-built-pr.js create mode 100644 .github/workflows/notify-about-deployment.yml diff --git a/.github/actions-scripts/find-past-built-pr.js b/.github/actions-scripts/find-past-built-pr.js new file mode 100755 index 000000000000..b73448029749 --- /dev/null +++ b/.github/actions-scripts/find-past-built-pr.js @@ -0,0 +1,44 @@ +#!/usr/bin/env node +import got from 'got' + +import { setOutput } from '@actions/core' + +import github from '../../script/helpers/github.js' +import { getActionContext } from './lib/action-context.js' + +async function main() { + const sha = await getBuiltSHA() + console.log({ sha }) + + const actionContext = getActionContext() + const { owner, repo } = actionContext + + const octokit = github() + let number = '' + + const q = `${sha} repo:"${owner}/${repo}"` + const { data } = await octokit.rest.search.issuesAndPullRequests({ q }) + for (const issue of data.items) { + // console.log(issue) + console.log('ID:', issue.id) + console.log('Number:', issue.number) + console.log('URL:', issue.html_url) + number = issue.number + if (number) { + break + } + } + + setOutput('number', number) +} + +async function getBuiltSHA() { + const r = await got('https://docs.github.com/_build') + const sha = r.body.trim() + if (!/[a-f0-9]{40}/.test(sha)) { + throw new Error(`Response body does not look like a SHA ('${r.body.slice(0, 100)}'...)`) + } + return sha +} + +main() diff --git a/.github/workflows/notify-about-deployment.yml b/.github/workflows/notify-about-deployment.yml new file mode 100644 index 000000000000..6326acee7caa --- /dev/null +++ b/.github/workflows/notify-about-deployment.yml @@ -0,0 +1,63 @@ +name: Notify about production deployment + +# **What it does**: Posts a comment on the PR whose merge got into production. +# **Why we have it**: So that the PR author can be informed when their merged PR is in production. +# **Who does it impact**: Writers + +on: + workflow_dispatch: + workflow_run: + # Note, we could do this after the "Purge Fastly" finished + workflows: ['Azure Production - Build and Deploy'] + types: + - completed + +permissions: + contents: read + pull-requests: write + +jobs: + find-pr-and-post-comment: + runs-on: ubuntu-latest + steps: + - name: Check out repo + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + + - uses: ./.github/actions/node-npm-setup + + # The "Purge Fastly" action takes about 6 minutes to purge all + # languages. First does the language agnostic URLs, then English, + # then all the other languages. + # So it takes about ~30 seconds until it has sent the purge for + # all English docs. + - name: Sleep a little to give Fastly Purge a chance + run: sleep 30 + + - name: Find last PR + id: get-number + timeout-minutes: 3 + env: + GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }} + run: .github/actions-scripts/find-past-built-pr.js + + - name: Find content directory changes comment + if: ${{ steps.get-number.outputs.number != '' }} + uses: peter-evans/find-comment@f4499a714d59013c74a08789b48abe4b704364a0 + id: findComment + with: + issue-number: ${{ steps.get-number.outputs.number }} + comment-author: 'github-actions[bot]' + body-includes: '' + + - name: Update comment + if: ${{ steps.get-number.outputs.number != '' }} + uses: peter-evans/create-or-update-comment@c9fcb64660bc90ec1cc535646af190c992007c32 + with: + comment-id: ${{ steps.findComment.outputs.comment-id }} + issue-number: ${{ steps.get-number.outputs.number }} + body: | + + 🚀 **This pull request has gone into production!** + + The SHA of https://docs.github.com/_build matches the merge commit in this PR. + edit-mode: replace