Skip to content

Commit d1a5c55

Browse files
authored
Merge branch 'main' into patch-2
2 parents aecc5bc + c789ff1 commit d1a5c55

164 files changed

Lines changed: 1078 additions & 1709 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env node
2+
3+
import parsePrUrl from '../../script/deployment/parse-pr-url.js'
4+
import getOctokit from '../../script/helpers/github.js'
5+
import deployToStaging from '../../script/deployment/deploy-to-staging.js'
6+
7+
const { GITHUB_TOKEN, HEROKU_API_TOKEN } = process.env
8+
9+
// Exit if GitHub Actions PAT is not found
10+
if (!GITHUB_TOKEN) {
11+
throw new Error('You must supply a GITHUB_TOKEN environment variable!')
12+
}
13+
14+
// Exit if Heroku API token is not found
15+
if (!HEROKU_API_TOKEN) {
16+
throw new Error('You must supply a HEROKU_API_TOKEN environment variable!')
17+
}
18+
19+
// This helper uses the `GITHUB_TOKEN` implicitly!
20+
// We're using our usual version of Octokit vs. the provided `github`
21+
// instance to avoid versioning discrepancies.
22+
const octokit = getOctokit()
23+
24+
const { RUN_ID, PR_URL, SOURCE_BLOB_URL, CONTEXT_NAME, ACTIONS_RUN_LOG, HEAD_SHA } = process.env
25+
if (!RUN_ID) {
26+
throw new Error('$RUN_ID not set')
27+
}
28+
if (!PR_URL) {
29+
throw new Error('$PR_URL not set')
30+
}
31+
if (!SOURCE_BLOB_URL) {
32+
throw new Error('$SOURCE_BLOB_URL not set')
33+
}
34+
if (!CONTEXT_NAME) {
35+
throw new Error('$CONTEXT_NAME not set')
36+
}
37+
if (!ACTIONS_RUN_LOG) {
38+
throw new Error('$ACTIONS_RUN_LOG not set')
39+
}
40+
if (!HEAD_SHA) {
41+
throw new Error('$HEAD_SHA not set')
42+
}
43+
44+
const { owner, repo, pullNumber } = parsePrUrl(PR_URL)
45+
if (!owner || !repo || !pullNumber) {
46+
throw new Error(
47+
`'pullRequestUrl' input must match URL format 'https://github.com/github/(docs|docs-internal)/pull/123' but was '${PR_URL}'`
48+
)
49+
}
50+
51+
const { data: pullRequest } = await octokit.pulls.get({
52+
owner,
53+
repo,
54+
pull_number: pullNumber,
55+
})
56+
57+
await deployToStaging({
58+
octokit,
59+
pullRequest,
60+
forceRebuild: false,
61+
// These parameters will ONLY be set by Actions
62+
sourceBlobUrl: SOURCE_BLOB_URL,
63+
runId: RUN_ID,
64+
})
65+
66+
await octokit.repos.createCommitStatus({
67+
owner,
68+
repo,
69+
sha: HEAD_SHA,
70+
context: CONTEXT_NAME,
71+
state: 'success',
72+
description: 'Successfully deployed! See logs.',
73+
target_url: ACTIONS_RUN_LOG,
74+
})
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env node
2+
3+
import parsePrUrl from '../../script/deployment/parse-pr-url.js'
4+
import getOctokit from '../../script/helpers/github.js'
5+
import undeployFromStaging from '../../script/deployment/undeploy-from-staging.js'
6+
7+
const { GITHUB_TOKEN, HEROKU_API_TOKEN } = process.env
8+
9+
// Exit if GitHub Actions PAT is not found
10+
if (!GITHUB_TOKEN) {
11+
throw new Error('You must supply a GITHUB_TOKEN environment variable!')
12+
}
13+
14+
// Exit if Heroku API token is not found
15+
if (!HEROKU_API_TOKEN) {
16+
throw new Error('You must supply a HEROKU_API_TOKEN environment variable!')
17+
}
18+
19+
// This helper uses the `GITHUB_TOKEN` implicitly!
20+
// We're using our usual version of Octokit vs. the provided `github`
21+
// instance to avoid versioning discrepancies.
22+
const octokit = getOctokit()
23+
24+
const { RUN_ID, PR_URL } = process.env
25+
26+
if (!RUN_ID) {
27+
throw new Error('$RUN_ID not set')
28+
}
29+
if (!PR_URL) {
30+
throw new Error('$PR_URL not set')
31+
}
32+
33+
const { owner, repo, pullNumber } = parsePrUrl(PR_URL)
34+
if (!owner || !repo || !pullNumber) {
35+
throw new Error(
36+
`'pullRequestUrl' input must match URL format 'https://github.com/github/(docs|docs-internal)/pull/123' but was '${PR_URL}'`
37+
)
38+
}
39+
40+
const { data: pullRequest } = await octokit.pulls.get({
41+
owner,
42+
repo,
43+
pull_number: pullNumber,
44+
})
45+
46+
await undeployFromStaging({
47+
octokit,
48+
pullRequest: pullRequest,
49+
runId: RUN_ID,
50+
})

.github/workflows/create-translation-batch-pr.yml

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ jobs:
2727
include:
2828
- language: pt-BR
2929
language_code: pt
30-
# - language: zh-CN
31-
# language_code: cn
32-
# - language: ja-JP
33-
# language_code: ja
34-
# - language: es-ES
35-
# language_code: es
30+
- language: zh-CN
31+
language_code: cn
32+
- language: ja-JP
33+
language_code: ja
34+
- language: es-ES
35+
language_code: es
3636
steps:
3737
- name: Set branch name
3838
id: set-branch
@@ -89,7 +89,7 @@ jobs:
8989

9090
- name: Commit crowdin sync
9191
run: |
92-
git add .
92+
git add translations/${{ matrix.language }}
9393
git commit -m "Add crowdin translations" || echo "Nothing to commit"
9494
9595
- name: 'Setup node'
@@ -99,54 +99,62 @@ jobs:
9999

100100
- run: npm ci
101101

102-
- name: Reset files with broken liquid tags
103-
run: |
104-
node script/i18n/reset-files-with-broken-liquid-tags.js --language=${{ matrix.language_code }}
105-
git add . && git commit -m "run script/i18n/reset-files-with-broken-liquid-tags.js --language=${{ matrix.language_code }}" || echo "Nothing to commit"
106-
107-
# step 5 in docs-engineering/crowdin.md using script from docs-internal#22709
108-
- name: Reset known broken files
109-
run: |
110-
node script/i18n/reset-known-broken-translation-files.js
111-
git add . && git commit -m "run script/i18n/reset-known-broken-translation-files.js" || echo "Nothing to commit"
112-
env:
113-
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}
114-
115102
# step 6 in docs-engineering/crowdin.md
116103
- name: Homogenize frontmatter
117104
run: |
118105
node script/i18n/homogenize-frontmatter.js
119-
git add . && git commit -m "Run script/i18n/homogenize-frontmatter.js" || echo "Nothing to commit"
106+
git add translations/${{ matrix.language }} && git commit -m "Run script/i18n/homogenize-frontmatter.js" || echo "Nothing to commit"
120107
121108
# step 7 in docs-engineering/crowdin.md
122109
- name: Fix translation errors
123110
run: |
124111
node script/i18n/fix-translation-errors.js
125-
git add . && git commit -m "Run script/i18n/fix-translation-errors.js" || echo "Nothing to commit"
112+
git add translations/${{ matrix.language }} && git commit -m "Run script/i18n/fix-translation-errors.js" || echo "Nothing to commit"
126113
127114
# step 8a in docs-engineering/crowdin.md
128115
- name: Check parsing
129116
run: |
130-
node script/i18n/lint-translation-files.js --check parsing
131-
git add . && git commit -m "Run script/i18n/lint-translation-files.js --check parsing" || echo "Nothing to commit"
117+
node script/i18n/lint-translation-files.js --check parsing | tee -a /tmp/batch.log | cat
118+
git add translations/${{ matrix.language }} && git commit -m "Run script/i18n/lint-translation-files.js --check parsing" || echo "Nothing to commit"
132119
133120
# step 8b in docs-engineering/crowdin.md
134121
- name: Check rendering
135122
run: |
136-
node script/i18n/lint-translation-files.js --check rendering
137-
git add . && git commit -m "Run script/i18n/lint-translation-files.js --check rendering" || echo "Nothing to commit"
123+
node script/i18n/lint-translation-files.js --check rendering | tee -a /tmp/batch.log | cat
124+
git add translations/${{ matrix.language }} && git commit -m "Run script/i18n/lint-translation-files.js --check rendering" || echo "Nothing to commit"
125+
126+
- name: Reset files with broken liquid tags
127+
run: |
128+
node script/i18n/reset-files-with-broken-liquid-tags.js --language=${{ matrix.language_code }} | tee -a /tmp/batch.log | cat
129+
git add translations/${{ matrix.language }} && git commit -m "run script/i18n/reset-files-with-broken-liquid-tags.js --language=${{ matrix.language_code }}" || echo "Nothing to commit"
130+
131+
# step 5 in docs-engineering/crowdin.md using script from docs-internal#22709
132+
- name: Reset known broken files
133+
run: |
134+
node script/i18n/reset-known-broken-translation-files.js | tee -a /tmp/batch.log | cat
135+
git add translations/${{ matrix.language }} && git commit -m "run script/i18n/reset-known-broken-translation-files.js" || echo "Nothing to commit"
136+
env:
137+
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}
138+
139+
- name: Check in CSV report
140+
run: |
141+
mkdir -p log
142+
csvFile=log/${{ matrix.language_code }}-resets.csv
143+
script/i18n/report-reset-files.js --report-type=csv --language=${{ matrix.language_code }} --log-file=/tmp/batch.log > $csvFile
144+
git add -f $csvFile && git commit -m "Check in ${{ matrix.language }} CSV report" || echo "Nothing to commit"
138145
139146
- name: Create Pull Request
140147
env:
141148
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}
142149
# We'll try to create the pull request based on the changes we pushed up in the branch.
143150
# If there are actually no differences between the branch and `main`, we'll delete it.
144151
run: |
152+
script/i18n/report-reset-files.js --report-type=pull-request-body --language=${{ matrix.language_code }} --log-file=/tmp/batch.log > /tmp/pr-body.txt
145153
git push origin ${{ steps.set-branch.outputs.BRANCH_NAME }}
146-
gh pr create -t "New translation batch for ${{ matrix.language }}" \
154+
gh pr create --title "New translation batch for ${{ matrix.language }}" \
147155
--base=main \
148156
--head=${{ steps.set-branch.outputs.BRANCH_NAME }} \
149-
-b "New batch for ${{ matrix.language }} created by [this workflow]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)" || git push origin :${{ steps.set-branch.outputs.BRANCH_NAME }}
157+
--body-file /tmp/pr-body.txt || git push origin :${{ steps.set-branch.outputs.BRANCH_NAME }}
150158
151159
# When the maximum execution time is reached for this job, Actions cancels the workflow run.
152160
# This emits a notification for the first responder to triage.

.github/workflows/prod-build-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ concurrency:
2121
jobs:
2222
build-and-deploy:
2323
if: ${{ github.repository == 'github/docs-internal'}}
24-
runs-on: ubuntu-latest
24+
runs-on: ${{ fromJSON('["ubuntu-latest", "self-hosted"]')[github.repository == 'github/docs-internal'] }}
2525
timeout-minutes: 15
2626
steps:
2727
- name: Check out repo

.github/workflows/staging-deploy-pr.yml

Lines changed: 6 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ jobs:
6767
BUILD_ACTIONS_RUN_ID: ${{ env.BUILD_ACTIONS_RUN_ID }}
6868
with:
6969
script: |
70+
71+
// Curious about what version of node you get
72+
console.log('Node version:', process.version)
73+
7074
// In order to find out the PR info for a forked repo, we must query
7175
// the API for more info based on the originating workflow run
7276
const { BUILD_ACTIONS_RUN_ID } = process.env
@@ -482,12 +486,8 @@ jobs:
482486
- name: Install dependencies
483487
run: npm ci
484488

485-
- name: Install one-off development-only dependencies
486-
run: npm install --no-save --include=optional esm
487-
488489
- name: Deploy
489490
id: deploy
490-
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
491491
env:
492492
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
493493
HEROKU_API_TOKEN: ${{ secrets.HEROKU_API_TOKEN }}
@@ -499,69 +499,8 @@ jobs:
499499
ACTIONS_RUN_LOG: ${{ env.ACTIONS_RUN_LOG }}
500500
HEAD_SHA: ${{ needs.pr-metadata.outputs.head_sha }}
501501
ALLOWED_POLLING_FAILURES_PER_PHASE: '15'
502-
with:
503-
script: |
504-
const { GITHUB_TOKEN, HEROKU_API_TOKEN } = process.env
505-
506-
// Exit if GitHub Actions PAT is not found
507-
if (!GITHUB_TOKEN) {
508-
throw new Error('You must supply a GITHUB_TOKEN environment variable!')
509-
}
510-
511-
// Exit if Heroku API token is not found
512-
if (!HEROKU_API_TOKEN) {
513-
throw new Error('You must supply a HEROKU_API_TOKEN environment variable!')
514-
}
515-
516-
// Workaround to allow us to load ESM files with `require(...)`
517-
const esm = require('esm')
518-
require = esm({})
519-
520-
const { default: parsePrUrl } = require('./script/deployment/parse-pr-url')
521-
const { default: getOctokit } = require('./script/helpers/github')
522-
const { default: deployToStaging } = require('./script/deployment/deploy-to-staging')
523-
524-
// This helper uses the `GITHUB_TOKEN` implicitly!
525-
// We're using our usual version of Octokit vs. the provided `github`
526-
// instance to avoid versioning discrepancies.
527-
const octokit = getOctokit()
528-
529-
try {
530-
const { PR_URL, SOURCE_BLOB_URL, CONTEXT_NAME, ACTIONS_RUN_LOG, HEAD_SHA } = process.env
531-
const { owner, repo, pullNumber } = parsePrUrl(PR_URL)
532-
if (!owner || !repo || !pullNumber) {
533-
throw new Error(`'pullRequestUrl' input must match URL format 'https://github.com/github/(docs|docs-internal)/pull/123' but was '${PR_URL}'`)
534-
}
535-
536-
const { data: pullRequest } = await octokit.pulls.get({
537-
owner,
538-
repo,
539-
pull_number: pullNumber
540-
})
541-
542-
await deployToStaging({
543-
octokit,
544-
pullRequest,
545-
forceRebuild: false,
546-
// These parameters will ONLY be set by Actions
547-
sourceBlobUrl: SOURCE_BLOB_URL,
548-
runId: context.runId
549-
})
550-
551-
await github.repos.createCommitStatus({
552-
owner,
553-
repo,
554-
sha: HEAD_SHA,
555-
context: CONTEXT_NAME,
556-
state: 'success',
557-
description: 'Successfully deployed! See logs.',
558-
target_url: ACTIONS_RUN_LOG
559-
})
560-
} catch (error) {
561-
console.error(`Failed to deploy to staging: ${error.message}`)
562-
console.error(error)
563-
throw error
564-
}
502+
RUN_ID: ${{ github.run_id }}
503+
run: .github/actions-scripts/staging-deploy.js
565504

566505
- name: Mark the deployment as inactive if timed out
567506
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d

.github/workflows/staging-undeploy-pr.yml

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -69,51 +69,13 @@ jobs:
6969
- name: Install dependencies
7070
run: npm ci
7171

72-
- name: Install one-off development-only dependencies
73-
run: npm install --no-save --include=optional esm
74-
7572
- name: Undeploy
76-
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
7773
env:
7874
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7975
HEROKU_API_TOKEN: ${{ secrets.HEROKU_API_TOKEN }}
80-
with:
81-
script: |
82-
const { GITHUB_TOKEN, HEROKU_API_TOKEN } = process.env
83-
84-
// Exit if GitHub Actions PAT is not found
85-
if (!GITHUB_TOKEN) {
86-
throw new Error('You must supply a GITHUB_TOKEN environment variable!')
87-
}
88-
89-
// Exit if Heroku API token is not found
90-
if (!HEROKU_API_TOKEN) {
91-
throw new Error('You must supply a HEROKU_API_TOKEN environment variable!')
92-
}
93-
94-
// Workaround to allow us to load ESM files with `require(...)`
95-
const esm = require('esm')
96-
require = esm({})
97-
98-
const { default: getOctokit } = require('./script/helpers/github')
99-
const { default: undeployFromStaging } = require('./script/deployment/undeploy-from-staging')
100-
101-
// This helper uses the `GITHUB_TOKEN` implicitly!
102-
// We're using our usual version of Octokit vs. the provided `github`
103-
// instance to avoid versioning discrepancies.
104-
const octokit = getOctokit()
105-
106-
try {
107-
await undeployFromStaging({
108-
octokit,
109-
pullRequest: context.payload.pull_request,
110-
runId: context.runId
111-
})
112-
} catch (error) {
113-
console.error(`Failed to undeploy from staging: ${error.message}`)
114-
console.error(error)
115-
throw error
116-
}
76+
RUN_ID: ${{ github.run_id }}
77+
PR_URL: ${{ github.event.pull_request.html_url }}
78+
run: .github/actions-scripts/staging-undeploy.js
11779

11880
- if: ${{ always() }}
11981
name: Remove the label from the PR to unblock deployment

0 commit comments

Comments
 (0)