Skip to content

Commit 090d210

Browse files
authored
Merge branch 'main' into open-command-palette
2 parents d8979e5 + 4c16bf7 commit 090d210

File tree

3,880 files changed

+98027
-95997
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,880 files changed

+98027
-95997
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package-lock.json @github/docs-engineering
1717
package.json @github/docs-engineering
1818

1919
# Localization
20+
/.github/actions-scripts/create-translation-batch-pr.js @github/docs-localization
2021
/.github/workflows/create-translation-batch-pr.yml @github/docs-localization
2122
/.github/workflows/crowdin.yml @github/docs-localization
2223
/crowdin*.yml @github/docs-engineering @github/docs-localization
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/usr/bin/env node
2+
3+
import fs from 'fs'
4+
import github from '@actions/github'
5+
6+
const OPTIONS = Object.fromEntries(
7+
['BASE', 'BODY_FILE', 'GITHUB_TOKEN', 'HEAD', 'LANGUAGE', 'TITLE', 'GITHUB_REPOSITORY'].map(
8+
(envVarName) => {
9+
const envVarValue = process.env[envVarName]
10+
if (!envVarValue) {
11+
throw new Error(`You must supply a ${envVarName} environment variable`)
12+
}
13+
return [envVarName, envVarValue]
14+
}
15+
)
16+
)
17+
18+
if (!process.env.GITHUB_REPOSITORY) {
19+
throw new Error('GITHUB_REPOSITORY environment variable not set')
20+
}
21+
22+
const RETRY_STATUSES = [
23+
422, // Retry the operation if the PR already exists
24+
502, // Retry the operation if the API responds with a `502 Bad Gateway` error.
25+
]
26+
const RETRY_ATTEMPTS = 3
27+
const {
28+
// One of the default environment variables provided by Actions.
29+
GITHUB_REPOSITORY,
30+
31+
// These are passed in from the step in the workflow file.
32+
TITLE,
33+
BASE,
34+
HEAD,
35+
LANGUAGE,
36+
BODY_FILE,
37+
GITHUB_TOKEN,
38+
} = OPTIONS
39+
const [OWNER, REPO] = GITHUB_REPOSITORY.split('/')
40+
41+
const octokit = github.getOctokit(GITHUB_TOKEN)
42+
43+
/**
44+
* @param {object} config Configuration options for finding the PR.
45+
* @returns {Promise<number | undefined>} The PR number.
46+
*/
47+
async function findPullRequestNumber(config) {
48+
// Get a list of PRs and see if one already exists.
49+
const { data: listOfPullRequests } = await octokit.rest.pulls.list({
50+
owner: config.owner,
51+
repo: config.repo,
52+
head: `${config.owner}:${config.head}`,
53+
})
54+
55+
return listOfPullRequests[0]?.number
56+
}
57+
58+
/**
59+
* When this file was first created, we only introduced support for creating a pull request for some translation batch.
60+
* However, some of our first workflow runs failed during the pull request creation due to a timeout error.
61+
* There have been cases where, despite the timeout error, the pull request gets created _anyway_.
62+
* To accommodate this reality, we created this function to look for an existing pull request before a new one is created.
63+
* Although the "find" check is redundant in the first "cycle", it's designed this way to recursively call the function again via its retry mechanism should that be necessary.
64+
*
65+
* @param {object} config Configuration options for creating the pull request.
66+
* @returns {Promise<number>} The PR number.
67+
*/
68+
async function findOrCreatePullRequest(config) {
69+
const found = await findPullRequestNumber(config)
70+
71+
if (found) {
72+
return found
73+
}
74+
75+
try {
76+
const { data: pullRequest } = await octokit.rest.pulls.create({
77+
owner: config.owner,
78+
repo: config.repo,
79+
base: config.base,
80+
head: config.head,
81+
title: config.title,
82+
body: config.body,
83+
draft: false,
84+
})
85+
86+
return pullRequest.number
87+
} catch (error) {
88+
if (!error.response || !config.retryCount) {
89+
throw error
90+
}
91+
92+
if (!config.retryStatuses.includes(error.response.status)) {
93+
throw error
94+
}
95+
96+
console.error(`Error creating pull request: ${error.message}`)
97+
console.warn(`Retrying in 5 seconds...`)
98+
await new Promise((resolve) => setTimeout(resolve, 5000))
99+
100+
config.retryCount -= 1
101+
102+
return findOrCreatePullRequest(config)
103+
}
104+
}
105+
106+
/**
107+
* @param {object} config Configuration options for labeling the PR
108+
* @returns {Promise<undefined>}
109+
*/
110+
async function labelPullRequest(config) {
111+
await octokit.rest.issues.update({
112+
owner: config.owner,
113+
repo: config.repo,
114+
issue_number: config.issue_number,
115+
labels: config.labels,
116+
})
117+
}
118+
119+
async function main() {
120+
const options = {
121+
title: TITLE,
122+
base: BASE,
123+
head: HEAD,
124+
body: fs.readFileSync(BODY_FILE, 'utf8'),
125+
labels: ['translation-batch', `translation-batch-${LANGUAGE}`],
126+
owner: OWNER,
127+
repo: REPO,
128+
retryStatuses: RETRY_STATUSES,
129+
retryCount: RETRY_ATTEMPTS,
130+
}
131+
132+
options.issue_number = await findOrCreatePullRequest(options)
133+
const pr = `${GITHUB_REPOSITORY}#${options.issue_number}`
134+
console.log(`Created PR ${pr}`)
135+
136+
// metadata parameters aren't currently available in `github.rest.pulls.create`,
137+
// but they are in `github.rest.issues.update`.
138+
await labelPullRequest(options)
139+
console.log(`Updated ${pr} with these labels: ${options.labels.join(', ')}`)
140+
}
141+
142+
main()

.github/workflows/autoupdate-branch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
4444

4545
- name: Setup Node
46-
uses: actions/setup-node@04c56d2f954f1e4c69436aa54cfef261a018f458
46+
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561
4747
with:
4848
node-version: 16.13.x
4949
cache: npm

.github/workflows/browser-test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
run: git lfs checkout
4141

4242
- name: Setup Node
43-
uses: actions/setup-node@04c56d2f954f1e4c69436aa54cfef261a018f458
43+
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561
4444
with:
4545
node-version: 16.13.x
4646
cache: npm
@@ -54,13 +54,13 @@ jobs:
5454
run: npm ci --include=optional
5555

5656
- name: Cache nextjs build
57-
uses: actions/cache@c64c572235d810460d0d6876e9c705ad5002b353
57+
uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
5858
with:
5959
path: .next/cache
6060
key: ${{ runner.os }}-nextjs-${{ hashFiles('package*.json') }}
6161

6262
- name: Cache lib/redirects/.redirects-cache_en_ja.json
63-
uses: actions/cache@c64c572235d810460d0d6876e9c705ad5002b353
63+
uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
6464
with:
6565
path: lib/redirects/.redirects-cache_en_ja.json
6666
key: ${{ runner.os }}-redirects-cache-${{ hashFiles('.github/workflows/browser-test.yml') }}

.github/workflows/check-all-english-links.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ jobs:
2828
- name: Check out repo's default branch
2929
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
3030
- name: Setup Node
31-
uses: actions/setup-node@04c56d2f954f1e4c69436aa54cfef261a018f458
31+
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561
3232
with:
3333
node-version: 16.13.x
3434
cache: npm
3535
- name: npm ci
3636
run: npm ci
3737
- name: Cache nextjs build
38-
uses: actions/cache@c64c572235d810460d0d6876e9c705ad5002b353
38+
uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
3939
with:
4040
path: .next/cache
4141
key: ${{ runner.os }}-nextjs-${{ hashFiles('package*.json') }}

.github/workflows/check-broken-links-github-github.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
4343

4444
- name: Setup Node
45-
uses: actions/setup-node@04c56d2f954f1e4c69436aa54cfef261a018f458
45+
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561
4646
with:
4747
node-version: 16.13.x
4848
cache: npm

.github/workflows/code-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
3838

3939
- name: Setup node
40-
uses: actions/setup-node@04c56d2f954f1e4c69436aa54cfef261a018f458
40+
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561
4141
with:
4242
node-version: 16.13.x
4343
cache: npm
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Prebuild Codespaces
2+
3+
# **What it does**: Prebuild the Codespaces image using powerful machines.
4+
# See https://github.com/github/codespaces-precache#readme for more details.
5+
# IMPORTANT: Requires we set a `EXPERIMENTAL_CODESPACE_CACHE_TOKEN` Codespaces
6+
# Secret (NOT an Actions Secret) in the repository.
7+
# **Why we have it**: Reduces startup time when booting Codespaces.
8+
# **Who does it impact**: Any Docs contributors who want to use Codespaces.
9+
10+
on:
11+
push:
12+
branches:
13+
- main
14+
workflow_dispatch:
15+
16+
# Currently requires write, but in the future will only require read
17+
permissions:
18+
contents: write
19+
20+
jobs:
21+
createPrebuild:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
25+
- uses: github/codespaces-precache@2ad40630d7e3e45e8725d6a74656cb6dd17363dc
26+
with:
27+
regions: WestUs2 EastUs WestEurope SouthEastAsia
28+
sku_name: basicLinux32gb
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
5151

5252
- name: Setup Node
53-
uses: actions/setup-node@04c56d2f954f1e4c69436aa54cfef261a018f458
53+
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561
5454
with:
5555
node-version: 16.13.x
5656
cache: npm

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ jobs:
116116
git commit -m "Add crowdin translations" || echo "Nothing to commit"
117117
118118
- name: 'Setup node'
119-
uses: actions/setup-node@04c56d2f954f1e4c69436aa54cfef261a018f458
119+
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561
120120
with:
121121
node-version: '16'
122122

@@ -166,26 +166,27 @@ jobs:
166166
script/i18n/report-reset-files.js --report-type=csv --language=${{ matrix.language }} --log-file=/tmp/batch.log > $csvFile
167167
git add -f $csvFile && git commit -m "Check in ${{ matrix.language }} CSV report" || echo "Nothing to commit"
168168
169+
- name: Write the reported files that were reset to /tmp/pr-body.txt
170+
run: script/i18n/report-reset-files.js --report-type=pull-request-body --language=${{ matrix.language }} --log-file=/tmp/batch.log > /tmp/pr-body.txt
171+
172+
- name: Push filtered translations
173+
run: git push origin ${{ steps.set-branch.outputs.BRANCH_NAME }}
174+
169175
- name: Close existing stale batches
170176
uses: lee-dohm/close-matching-issues@e9e43aad2fa6f06a058cedfd8fb975fd93b56d8f
171177
with:
172178
token: ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
173179
query: 'type:pr label:translation-batch-${{ matrix.language }}'
174180

175-
- name: Create Pull Request
181+
- name: Create translation batch pull request
176182
env:
177183
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}
178-
# We'll try to create the pull request based on the changes we pushed up in the branch.
179-
# If there are actually no differences between the branch and `main`, we'll delete it.
180-
run: |
181-
script/i18n/report-reset-files.js --report-type=pull-request-body --language=${{ matrix.language }} --log-file=/tmp/batch.log > /tmp/pr-body.txt
182-
git push origin ${{ steps.set-branch.outputs.BRANCH_NAME }}
183-
gh pr create --title "New translation batch for ${{ matrix.language }}" \
184-
--base=main \
185-
--head=${{ steps.set-branch.outputs.BRANCH_NAME }} \
186-
--label "translation-batch-${{ matrix.language }}" \
187-
--label "translation-batch" \
188-
--body-file /tmp/pr-body.txt || git push origin :${{ steps.set-branch.outputs.BRANCH_NAME }}
184+
TITLE: 'New translation batch for ${{ matrix.language }}'
185+
BASE: 'main'
186+
HEAD: ${{ steps.set-branch.outputs.BRANCH_NAME }}
187+
LANGUAGE: ${{ matrix.language }}
188+
BODY_FILE: '/tmp/pr-body.txt'
189+
run: .github/actions-scripts/create-translation-batch-pr.js
189190

190191
- name: Approve PR
191192
if: github.ref_name == 'main'

.github/workflows/crowdin-cleanup.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
3030

3131
- name: Setup Node
32-
uses: actions/setup-node@04c56d2f954f1e4c69436aa54cfef261a018f458
32+
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561
3333
with:
3434
node-version: 16.13.x
3535
cache: npm
@@ -41,7 +41,7 @@ jobs:
4141
run: script/i18n/homogenize-frontmatter.js
4242

4343
- name: Check in homogenized files
44-
uses: EndBug/add-and-commit@2bdc0a61a03738a1d1bda24d566ad0dbe3083d87
44+
uses: EndBug/add-and-commit@8c12ff729a98cfbcd3fe38b49f55eceb98a5ec02
4545
with:
4646
# The arguments for the `git add` command
4747
add: 'translations'

.github/workflows/docs-review-collect.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
2424

2525
- name: Setup Node
26-
uses: actions/setup-node@04c56d2f954f1e4c69436aa54cfef261a018f458
26+
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561
2727
with:
2828
node-version: 16.13.x
2929
cache: npm

.github/workflows/enterprise-dates.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
4040

4141
- name: Setup Node
42-
uses: actions/setup-node@04c56d2f954f1e4c69436aa54cfef261a018f458
42+
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561
4343
with:
4444
node-version: 16.13.x
4545
cache: npm
@@ -55,7 +55,7 @@ jobs:
5555

5656
- name: Create pull request
5757
id: create-pull-request
58-
uses: peter-evans/create-pull-request@7380612b49221684fefa025244f2ef4008ae50ad
58+
uses: peter-evans/create-pull-request@dcd5fd746d53dd8de555c0f10bca6c35628be47a
5959
env:
6060
# Disable pre-commit hooks; they don't play nicely here
6161
HUSKY: '0'

.github/workflows/enterprise-release-sync-search-index.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
token: ${{ secrets.DOCUBOT_REPO_PAT }}
5151

5252
- name: Setup Node
53-
uses: actions/setup-node@04c56d2f954f1e4c69436aa54cfef261a018f458
53+
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561
5454
with:
5555
node-version: 16.13.x
5656
cache: npm
@@ -63,7 +63,7 @@ jobs:
6363
run: $GITHUB_WORKSPACE/.github/actions-scripts/enterprise-search-label.js
6464

6565
- name: Cache nextjs build
66-
uses: actions/cache@c64c572235d810460d0d6876e9c705ad5002b353
66+
uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
6767
with:
6868
path: .next/cache
6969
key: ${{ runner.os }}-nextjs-${{ hashFiles('package*.json') }}

0 commit comments

Comments
 (0)