Skip to content

Commit f27c521

Browse files
hectorsectorCopilotheiskrEbonsignori
authored
Use review server URL for content changes table (#53812)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com> Co-authored-by: Evan Bonsignori <ebonsignori@github.com>
1 parent 3714cfb commit f27c521

File tree

3 files changed

+114
-26
lines changed

3 files changed

+114
-26
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Code changes comment
2+
3+
# **What it does**: When a PR is opened in docs-internal or docs containing code, it comments with instructions on how to deploy and preview the changes.
4+
# **Why we have it**: To help Docs contributors understand how to preview their changes.
5+
# **Who does it impact**: docs-internal and docs maintainers and contributors
6+
7+
on:
8+
# Required in lieu of `pull_request` so that the comment can be posted to PRs opened from a fork.
9+
pull_request_target:
10+
types:
11+
- opened
12+
- synchronize
13+
# this applies to any non-content files, this workflow will run for all changed files unless it's ONLY these content-related changes
14+
paths-ignore:
15+
- 'content/**'
16+
- 'data/reusables/**'
17+
- 'assets/images/**'
18+
19+
permissions:
20+
contents: read
21+
pull-requests: write
22+
23+
# This allows a subsequently queued workflow run to interrupt previous runs
24+
concurrency:
25+
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
26+
cancel-in-progress: true
27+
28+
jobs:
29+
postOnCodeChanges:
30+
if: ${{ github.event.pull_request.user.login != 'docs-bot' && (github.repository == 'github/docs-internal' || github.repository == 'github/docs') }}
31+
runs-on: ubuntu-latest
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
steps:
35+
- name: check out repo content
36+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
37+
38+
- name: Find code changes comment
39+
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e
40+
id: findComment
41+
with:
42+
issue-number: ${{ github.event.pull_request.number }}
43+
comment-author: 'github-actions[bot]'
44+
body-includes: '<!-- CODE_CHANGES_COMMENT -->'
45+
46+
# TODO: We'll update this comment at a later time with permament-ish links to deployment instructions.
47+
- name: Comment on code changes
48+
if: ${{ !steps.findComment.outputs.comment-id }}
49+
run: |
50+
if [[ "${{ github.repository }}" == "github/docs" ]]; then
51+
COMMENT_BODY="<!-- CODE_CHANGES_COMMENT -->
52+
## 🚀 Manual Deployment Required
53+
54+
It looks like this pull request contains code changes. To preview these changes, an internal Hubber will need to manually deploy the changes to one of our staging servers.
55+
56+
Thank you for your contribution!"
57+
else
58+
COMMENT_BODY="<!-- CODE_CHANGES_COMMENT -->
59+
## 🚀 Manual Deployment Required
60+
61+
It looks like this pull request contains code changes. To preview these changes, you will need to deploy them manually.
62+
63+
Thank you for your contribution!"
64+
fi
65+
66+
gh pr comment ${{ github.event.pull_request.number }} --body "$COMMENT_BODY"

.github/workflows/content-changes-table-comment.yml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ on:
2828
paths:
2929
- 'content/**'
3030
- 'data/reusables/**'
31+
- 'assets/images/**'
3132

3233
permissions:
3334
contents: read
@@ -48,21 +49,28 @@ jobs:
4849
- name: check out repo content
4950
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
5051

51-
- name: Get preview app info
52-
env:
53-
APP_NAME_SEED: ${{ secrets.PREVIEW_ENV_NAME_SEED }}
54-
run: src/workflows/get-preview-app-info.sh
55-
5652
- uses: ./.github/actions/node-npm-setup
5753

54+
# We're setting the URLs manually until we merge in-progress work. We can utilize review server and its helper functions in a later iteration.
55+
- name: Set APP_URL
56+
run: |
57+
if [[ "${{ github.repository }}" == "github/docs-internal" ]]; then
58+
echo "APP_URL=https://docs-review.github.com" >> $GITHUB_ENV
59+
elif [[ "${{ github.repository }}" == "github/docs" ]]; then
60+
echo "APP_URL=https://os-docs-review.github.com" >> $GITHUB_ENV
61+
fi
62+
5863
- name: Get changes table
5964
id: changes
6065
timeout-minutes: 30
6166
env:
6267
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
REVIEW_SERVER_ACCESS_TOKEN: ${{ secrets.REVIEW_SERVER_ACCESS_TOKEN }}
6369
APP_URL: ${{ env.APP_URL }}
6470
BASE_SHA: ${{ github.event.pull_request.base.sha || inputs.BASE_SHA }}
6571
HEAD_SHA: ${{ github.event.pull_request.head.sha || inputs.HEAD_SHA }}
72+
# HEAD_BRANCH isn't necessary for the table comment, but lets us list the branch in the review server menu bar
73+
HEAD_BRANCH: ${{ github.event.pull_request.head.ref }}
6674
run: npm run content-changes-table-comment
6775

6876
- name: Find content directory changes comment
@@ -81,10 +89,10 @@ jobs:
8189
issue-number: ${{ github.event.pull_request.number || inputs.PR_NUMBER }}
8290
body: |
8391
<!-- MODIFIED_CONTENT_LINKING_COMMENT -->
84-
## Automatically generated comment ℹ️
85-
**This comment is automatically generated and will be overwritten every time changes are committed to this branch.**
92+
## 👓 Previews for changed content
93+
**This comment is 🤖 automatically generated and will be overwritten every time changes are committed to this branch.**
8694
87-
The table contains an overview of files in the `content` directory that have been changed in this pull request. It's provided to make it easy to review your changes on the staging site. Please note that changes to the `data` directory will not show up in this table.
95+
The table contains an overview of files in the `content` directory that have been changed in this pull request. It's provided to make it easy to review your changes on the review server. Please note that changes to the `data` directory will not show up in this table.
8896
8997
---
9098
@@ -93,7 +101,6 @@ jobs:
93101
${{ steps.changes.outputs.changesTable }}
94102
95103
---
96-
fpt: Free, Pro, Team
97-
ghec: GitHub Enterprise Cloud
98-
ghes: GitHub Enterprise Server
104+
Key: **fpt**: Free, Pro, Team; **ghec**: GitHub Enterprise Cloud; **ghes**: GitHub Enterprise Server
105+
_This table is posted from the [${{ github.workflow }}](https://github.com/${{ github.repository }}/blob/${{ github.sha }}/.github/workflows/content-changes-table-comment.yml) workflow._
99106
edit-mode: replace

src/workflows/content-changes-table-comment.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env node
2-
31
/**
42
* Hi there! 👋
53
* To test this code locally, outside of Actions, you need to run
@@ -23,11 +21,10 @@ import { getContents } from './git-utils.js'
2321
import getApplicableVersions from '@/versions/lib/get-applicable-versions.js'
2422
import nonEnterpriseDefaultVersion from '@/versions/lib/non-enterprise-default-version.js'
2523
import { allVersionShortnames } from '@/versions/lib/all-versions.js'
26-
import { waitUntilUrlIsHealthy } from './wait-until-url-is-healthy.js'
2724
import readFrontmatter from '@/frame/lib/read-frontmatter.js'
2825
import { inLiquid } from './lib/in-liquid'
2926

30-
const { GITHUB_TOKEN, APP_URL } = process.env
27+
const { GITHUB_TOKEN, REVIEW_SERVER_ACCESS_TOKEN, APP_URL } = process.env
3128
const context = github.context
3229

3330
// the max size of the comment (in bytes)
@@ -44,13 +41,8 @@ if (import.meta.url.endsWith(process.argv[1])) {
4441
const baseSHA = process.env.BASE_SHA || context.payload.pull_request!.base.sha
4542
const headSHA = process.env.HEAD_SHA || context.payload.pull_request!.head.sha
4643

47-
const isHealthy = await waitUntilUrlIsHealthy(new URL('/healthz', APP_URL).toString())
48-
if (!isHealthy) {
49-
core.setFailed(`Timeout waiting for preview environment: ${APP_URL}`)
50-
} else {
51-
const markdownTable = await main(owner, repo, baseSHA, headSHA)
52-
core.setOutput('changesTable', markdownTable)
53-
}
44+
const markdownTable = await main(owner, repo, baseSHA, headSHA)
45+
core.setOutput('changesTable', markdownTable)
5446
}
5547

5648
async function main(owner: string, repo: string, baseSHA: string, headSHA: string) {
@@ -60,10 +52,30 @@ async function main(owner: string, repo: string, baseSHA: string, headSHA: strin
6052
if (!APP_URL) {
6153
throw new Error(`APP_URL environment variable not set`)
6254
}
55+
const headBranch = process.env.HEAD_BRANCH
56+
6357
const RetryingOctokit = Octokit.plugin(retry)
6458
const octokit = new RetryingOctokit({
6559
auth: `token ${GITHUB_TOKEN}`,
6660
})
61+
62+
// we'll attach the branch or sha right after this
63+
const searchParams = new URLSearchParams({
64+
'review-server-repository': `${owner}/${repo}`,
65+
})
66+
67+
// this token will be available in the internal repo only, skip it for the open source repo
68+
if (REVIEW_SERVER_ACCESS_TOKEN)
69+
searchParams.append('review-server-access-token', REVIEW_SERVER_ACCESS_TOKEN)
70+
71+
// this script compares with SHAs only, so this allows us
72+
// to surface the branch name for the review server bar
73+
headBranch
74+
? searchParams.append('review-server-branch', headBranch)
75+
: searchParams.append('review-server-sha', headSHA)
76+
77+
const queryParams = `?${searchParams.toString()}`
78+
6779
// get the list of file changes from the PR
6880
const response = await octokit.rest.repos.compareCommitsWithBasehead({
6981
owner,
@@ -134,7 +146,7 @@ async function main(owner: string, repo: string, baseSHA: string, headSHA: strin
134146
return
135147
}
136148

137-
return makeRow({ file, fileName, sourceUrl, fileUrl, data })
149+
return makeRow({ file, fileName, sourceUrl, fileUrl, queryParams, data })
138150
}),
139151
)
140152

@@ -149,6 +161,7 @@ async function main(owner: string, repo: string, baseSHA: string, headSHA: strin
149161
fileName,
150162
sourceUrl: file.blob_url,
151163
fileUrl,
164+
queryParams,
152165
data,
153166
fromReusable: true,
154167
})
@@ -194,13 +207,15 @@ type File = {
194207
function makeRow({
195208
file,
196209
fileUrl,
210+
queryParams,
197211
fileName,
198212
sourceUrl,
199213
data,
200214
fromReusable,
201215
}: {
202216
file: File
203217
fileUrl: string
218+
queryParams: string
204219
fileName: string
205220
sourceUrl: string
206221
data: any
@@ -235,12 +250,12 @@ function makeRow({
235250
if (versions.toString() === nonEnterpriseDefaultVersion) {
236251
// omit version from fpt url
237252

238-
previewCell += `[${plan}](${APP_URL}/${fileUrl})<br>`
253+
previewCell += `[${plan}](${APP_URL}/${fileUrl}${queryParams})<br>`
239254
prodCell += `[${plan}](${PROD_URL}/${fileUrl})<br>`
240255
} else {
241256
// for non-versioned releases (ghec) use full url
242257

243-
previewCell += `[${plan}](${APP_URL}/${versions}/${fileUrl})<br>`
258+
previewCell += `[${plan}](${APP_URL}/${versions}/${fileUrl}${queryParams})<br>`
244259
prodCell += `[${plan}](${PROD_URL}/${versions}/${fileUrl})<br>`
245260
}
246261
} else if (versions.length) {
@@ -250,7 +265,7 @@ function makeRow({
250265
prodCell += `${plan}@ `
251266

252267
versions.forEach((version) => {
253-
previewCell += `[${version.split('@')[1]}](${APP_URL}/${version}/${fileUrl}) `
268+
previewCell += `[${version.split('@')[1]}](${APP_URL}/${version}/${fileUrl}${queryParams}) `
254269
prodCell += `[${version.split('@')[1]}](${PROD_URL}/${version}/${fileUrl}) `
255270
})
256271
previewCell += '<br>'

0 commit comments

Comments
 (0)