Skip to content

Commit 88f8d65

Browse files
authored
Merge pull request #12125 from github/repo-sync
repo sync
2 parents ae17cae + 7079099 commit 88f8d65

112 files changed

Lines changed: 2310 additions & 1898 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.

.github/actions-scripts/enable-automerge.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { getOctokit } from '@actions/github'
22
const token = process.env.GITHUB_TOKEN
33
const prNumber = process.env.AUTOMERGE_PR_NUMBER
4+
const [org, repo] = process.env.GITHUB_REPOSITORY.split('/')
45
const github = getOctokit(token)
56

67
main()
78
async function main() {
8-
const pull = await github.pulls.get({
9-
...context.repo,
9+
const pull = await github.rest.pulls.get({
10+
owner: org,
11+
repo: repo,
1012
pull_number: parseInt(prNumber),
1113
})
1214

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/env node
2+
3+
import { getOctokit } from '@actions/github'
4+
const token = process.env.GITHUB_TOKEN
5+
const github = getOctokit(token)
6+
7+
// Mergeable status documentation here:
8+
// https://docs.github.com/en/graphql/reference/enums#mergestatestatus
9+
// https://docs.github.com/en/graphql/reference/enums#mergeablestate
10+
11+
/*
12+
This script gets a list of automerge-enabled PRs and sorts them
13+
by priority. The PRs with the skip-to-front-of-merge-queue label
14+
are prioritized first. The rest of the PRs are sorted by the date
15+
they were updated. This is basically a FIFO queue, while allowing
16+
writers the ability to skip the line when high-priority ships are
17+
needed but a freeze isn't necessary.
18+
*/
19+
20+
main()
21+
22+
async function main() {
23+
// Get a list of open PRs and order them from oldest to newest
24+
const query = `query ($first: Int, $after: String, $firstLabels: Int) {
25+
organization(login: "github") {
26+
repository(name: "docs-internal") {
27+
pullRequests(first: $first, after: $after, states: OPEN, orderBy: {field: UPDATED_AT, direction: ASC}) {
28+
edges{
29+
node {
30+
number
31+
url
32+
updatedAt
33+
mergeable
34+
mergeStateStatus
35+
autoMergeRequest {
36+
enabledBy {
37+
login
38+
}
39+
enabledAt
40+
}
41+
labels (first:$firstLabels){
42+
nodes {
43+
name
44+
}
45+
}
46+
}
47+
}
48+
pageInfo {
49+
hasNextPage
50+
endCursor
51+
}
52+
}
53+
}
54+
}
55+
}`
56+
57+
const queryVariables = {
58+
first: 100,
59+
after: null, // when pagination in null it will get first page
60+
firstLabels: 100,
61+
headers: {
62+
// required for the mergeStateStatus enum
63+
accept: 'application/vnd.github.merge-info-preview+json',
64+
},
65+
}
66+
let hasNextPage = true
67+
const autoMergeEnabledPRs = []
68+
69+
// we need to get all the paginated results in the case that
70+
// there are more than 100 PRs
71+
while (hasNextPage) {
72+
const graph = await github.graphql(query, queryVariables)
73+
const dataRoot = graph.organization.repository.pullRequests
74+
const pullRequests = dataRoot.edges
75+
// update pagination variables
76+
hasNextPage = dataRoot.pageInfo.hasNextPage
77+
// the endCursor is the start cursor for the next page
78+
queryVariables.after = dataRoot.pageInfo.endCursor
79+
80+
const filteredPrs = pullRequests
81+
// this simplifies the format received from the graphql query to
82+
// remove the unnecessary nested objects
83+
.map((pr) => {
84+
// make the labels object just an array of the label names
85+
const labelArray = pr.node.labels.nodes.map((label) => label.name)
86+
pr.node.labels = labelArray
87+
// return the pr object and ✂️ the node property
88+
return pr.node
89+
})
90+
.filter((pr) => pr.autoMergeRequest !== null)
91+
.filter((pr) => pr.mergeable === 'MERGEABLE')
92+
// filter out prs that don't have a calculated mergeable state yet
93+
.filter((pr) => pr.mergeStateStatus !== 'UNKNOWN')
94+
// filter out prs that still need a review, have merge conflicts,
95+
// or have failing ci tests
96+
.filter((pr) => pr.mergeStateStatus !== 'BLOCKED')
97+
// **NOTE**: In the future we may want to send slack message to initiators
98+
// of PRs with the following merge states because these can happen after
99+
// a PR is green and the automerge is enabled
100+
.filter((pr) => pr.mergeStateStatus !== 'DIRTY')
101+
.filter((pr) => pr.mergeStateStatus !== 'UNSTABLE')
102+
103+
autoMergeEnabledPRs.push(...filteredPrs)
104+
}
105+
106+
// Get the list of prs with the skip label so they can
107+
// be put at the beginning of the list
108+
const prioritizedPrList = autoMergeEnabledPRs
109+
.filter((pr) => pr.labels.includes('skip-to-front-of-merge-queue'))
110+
.concat(autoMergeEnabledPRs.filter((pr) => !pr.labels.includes('skip-to-front-of-merge-queue')))
111+
112+
const nextInQueue = prioritizedPrList.shift()
113+
// Update the branch for the next PR in the merge queue
114+
github.rest.pulls.updateBranch({
115+
owner: 'github',
116+
repo: 'docs-internal',
117+
pull_number: parseInt(nextInQueue.number),
118+
})
119+
120+
console.log(`⏱ Total PRs in the merge queue: ${prioritizedPrList.length + 1}`)
121+
console.log(`🚂 Updated branch for PR #${JSON.stringify(nextInQueue, null, 2)}`)
122+
console.log(`🚏 Next up in the queue: `)
123+
console.log(JSON.stringify(prioritizedPrList, null, 2))
124+
}

.github/allowed-actions.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export default [
1717
'cschleiden/actions-linter@caffd707beda4fc6083926a3dff48444bc7c24aa', // uses github-actions-parser v0.23.0
1818
'dawidd6/action-delete-branch@47743101a121ad657031e6704086271ca81b1911', // v3.0.2
1919
'dawidd6/action-download-artifact@af92a8455a59214b7b932932f2662fdefbd78126', // v2.15.0
20-
'docker://chinthakagodawita/autoupdate-action:v1',
2120
'dorny/paths-filter@eb75a1edc117d3756a18ef89958ee59f9500ba58',
2221
'trilom/file-changes-action@a6ca26c14274c33b15e6499323aac178af06ad4b', // v1.2.4
2322
'github/codeql-action/analyze@v1',
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
name: Autoupdate branch
22

3-
# **What it does**: Any pull requests with "autoupdate" label will get main branch updates.
4-
# **Why we have it**: Our repo-sync automation relies on it.
5-
# **Who does it impact**: Our ability to support the open-source repository.
6-
3+
# **What it does**: The next pull request in the merge queue will get its
4+
# branch updated with main. Only updating one branch ensures that pull requests
5+
# in the queue are merged sequentially.
6+
# **Why we have it**: So we don't have to watch pull requests and click
7+
# update branch 1000x.
8+
# **Who does it impact**: Our health.
79
#
8-
# This workflow checks all open PRs targeting `main` as their base branch and
9-
# will attempt to update them if they have the `autoupdate` label applied.
10-
# It is triggered when a `push` event occurs ON the `main` branch (e.g. a PR
11-
# was merged or a force-push was done).
10+
# The merge queue consists of any pull requests with automerge enabled and
11+
# are mergeable. There is a label that can be used to skip to the front of
12+
# the queue (`skip-to-front-of-merge-queue`).
1213
#
13-
# It should work on all PRs created from source branches within the repo itself
14-
# but is unlikely to work for PRs created from forked repos.
14+
# This workflow is triggered when a `push` event occurs ON the `main` branch
15+
# (e.g. a PR was merged or a force-push was done).
1516
#
16-
# It is still worthwhile to leave it enabled for the `docs` open source repo as
17-
# it should at least be running on `repo-sync` branch PRs.
17+
# This workflow runs on all PRs created from source branches within the
18+
# public and private docs repos but is won't work for PRs created from
19+
# forked repos.
1820
#
1921

2022
on:
@@ -28,9 +30,7 @@ jobs:
2830
name: autoupdate
2931
runs-on: ubuntu-latest
3032
steps:
31-
- uses: docker://chinthakagodawita/autoupdate-action:v1
33+
- name: Update next PR in queue
3234
env:
33-
GITHUB_TOKEN: ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
34-
PR_FILTER: labelled
35-
PR_LABELS: autoupdate
36-
MERGE_MSG: "Branch was updated using the 'autoupdate branch' Actions workflow."
35+
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}
36+
run: node .github/actions-scripts/update-merge-queue-branch.js
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
name: Create translation Batch Pull Request
2+
3+
# **What it does**:
4+
# - Creates one pull request per language after running a series of automated checks,
5+
# removing translations that are broken in any known way
6+
# **Why we have it**:
7+
# - To deploy translations
8+
# **Who does it impact**: It automates what would otherwise be manual work,
9+
# helping docs engineering focus on higher value work
10+
11+
on:
12+
workflow_dispatch:
13+
schedule:
14+
- cron: '33 18 * * *' # every day at 18:33 UTC at least until automerge is working
15+
16+
jobs:
17+
create-translation-batch:
18+
name: Create translation batch
19+
runs-on: ubuntu-latest
20+
# A sync's average run time is ~3.2 hours.
21+
# This sets a maximum execution time of 300 minutes (5 hours) to prevent the workflow from running longer than necessary.
22+
timeout-minutes: 300
23+
strategy:
24+
fail-fast: false
25+
max-parallel: 1
26+
matrix:
27+
include:
28+
- language: pt-BR
29+
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
36+
steps:
37+
- name: Set branch name
38+
id: set-branch
39+
run: |
40+
echo "::set-output name=BRANCH_NAME::translation-batch-${{ matrix.language }}-$(date +%Y-%m-%d__%H-%M)"
41+
42+
- run: git config --global user.name "docubot"
43+
- run: git config --global user.email "67483024+docubot@users.noreply.github.com"
44+
45+
- name: Checkout
46+
uses: actions/checkout@1e204e9a9253d643386038d443f96446fa156a97
47+
with:
48+
fetch-depth: 0
49+
lfs: true
50+
51+
- run: git checkout -b ${{ steps.set-branch.outputs.BRANCH_NAME }}
52+
53+
- name: Remove unwanted git hooks
54+
run: rm .git/hooks/post-checkout
55+
56+
- name: Install Crowdin CLI
57+
run: |
58+
wget https://artifacts.crowdin.com/repo/deb/crowdin3.deb -O /tmp/crowdin.deb
59+
sudo dpkg -i /tmp/crowdin.deb
60+
61+
- name: Upload files to crowdin
62+
run: crowdin upload sources --no-progress --no-colors --verbose --debug '--branch=main' '--config=crowdin.yml'
63+
env:
64+
# This is a numeric id, not to be confused with Crowdin API v1 "project identifier" string
65+
# See "API v2" on https://crowdin.com/project/<your-project>/settings#api
66+
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
67+
68+
# A personal access token, not to be confused with Crowdin API v1 "API key"
69+
# See https://crowdin.com/settings#api-key to generate a token
70+
# This token was created by logging into Crowdin with the octoglot user
71+
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
72+
73+
- name: Remove all language translations
74+
run: |
75+
git rm -rf --quiet translations/${{ matrix.language }}/content
76+
git rm -rf --quiet translations/${{ matrix.language }}/data
77+
78+
- name: Download crowdin translations
79+
run: crowdin download --no-progress --no-colors --verbose --debug '--branch=main' '--config=crowdin.yml' --language=${{ matrix.language }}
80+
env:
81+
# This is a numeric id, not to be confused with Crowdin API v1 "project identifier" string
82+
# See "API v2" on https://crowdin.com/project/<your-project>/settings#api
83+
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
84+
85+
# A personal access token, not to be confused with Crowdin API v1 "API key"
86+
# See https://crowdin.com/settings#api-key to generate a token
87+
# This token was created by logging into Crowdin with the octoglot user
88+
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
89+
90+
- name: Commit crowdin sync
91+
run: |
92+
git add .
93+
git commit -m "Add crowdin translations" || echo "Nothing to commit"
94+
95+
- name: 'Setup node'
96+
uses: actions/setup-node@270253e841af726300e85d718a5f606959b2903c
97+
with:
98+
node-version: '16'
99+
100+
- run: npm ci
101+
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+
115+
# step 6 in docs-engineering/crowdin.md
116+
- name: Homogenize frontmatter
117+
run: |
118+
node script/i18n/homogenize-frontmatter.js
119+
git add . && git commit -m "Run script/i18n/homogenize-frontmatter.js" || echo "Nothing to commit"
120+
121+
# step 7 in docs-engineering/crowdin.md
122+
- name: Fix translation errors
123+
run: |
124+
node script/i18n/fix-translation-errors.js
125+
git add . && git commit -m "Run script/i18n/fix-translation-errors.js" || echo "Nothing to commit"
126+
127+
# step 8a in docs-engineering/crowdin.md
128+
- name: Check parsing
129+
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 parsin" || echo "Nothing to commit"
132+
133+
# step 8b in docs-engineering/crowdin.md
134+
- name: Check rendering
135+
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"
138+
139+
- name: Create Pull Request
140+
env:
141+
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}
142+
# We'll try to create the pull request based on the changes we pushed up in the branch.
143+
# If there are actually no differences between the branch and `main`, we'll delete it.
144+
run: |
145+
git push origin ${{ steps.set-branch.outputs.BRANCH_NAME }}
146+
gh pr create -t "New translation batch for ${{ matrix.language }}" \
147+
--base=main \
148+
--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 }}
150+
151+
# When the maximum execution time is reached for this job, Actions cancels the workflow run.
152+
# This emits a notification for the first responder to triage.
153+
- name: Send Slack notification if workflow is cancelled
154+
uses: someimportantcompany/github-actions-slack-message@f8d28715e7b8a4717047d23f48c39827cacad340
155+
if: cancelled()
156+
with:
157+
channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }}
158+
bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
159+
color: failure
160+
text: 'The new translation batch for ${{ matrix.language }} was cancelled.'
161+
162+
# Emit a notification for the first responder to triage if the workflow failed.
163+
- name: Send Slack notification if workflow failed
164+
uses: someimportantcompany/github-actions-slack-message@f8d28715e7b8a4717047d23f48c39827cacad340
165+
if: failure()
166+
with:
167+
channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }}
168+
bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
169+
color: failure
170+
text: 'The new translation batch for ${{ matrix.language }} failed.'

.github/workflows/enterprise-dates.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ jobs:
6464
"Hello! The GitHub Enterprise Server release dates have changed.\n\n
6565
If CI passes, this PR will be auto-merged. :green_heart:\n\n
6666
If CI does not pass or other problems arise, contact #docs-engineering on slack.\n\nThis PR was 🤖-crafted by `.github/workflows/enterprise-dates.yml`. 🧶"
67-
labels: autoupdate
6867
branch: enterprise-server-dates-update
6968
delete-branch: true
7069

7170
- name: Enable GitHub auto-merge
7271
if: ${{ steps.create-pull-request.outputs.pull-request-number }}
7372
env:
73+
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}
7474
AUTOMERGE_PR_NUMBER: ${{ steps.create-pull-request.outputs.pull-request-number }}
7575
run: node .github/actions-scripts/enable-automerge.js
7676

0 commit comments

Comments
 (0)