Skip to content

Commit 63cc746

Browse files
authored
Auto label PRs that change docs, then auto assign tech writers (#5059)
* save * detect doc changes * create workflow to add label to PRs that change docs * assign techwriters to labeled PRs * update workflow name * update command * trigger workflow for testing * fix bug * update node version * add missing import * test * revert change for testing * update action version * update version * pass github token * uppercase * secrets * fix workflow * fix syntax * use a different GHA * downgrade * format * rename file
1 parent 4a194b7 commit 63cc746

File tree

5 files changed

+169
-1
lines changed

5 files changed

+169
-1
lines changed

.github/auto_assign.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Set to true to add reviewers to pull requests
2+
addReviewers: false
3+
4+
# Set to true to add assignees to pull requests
5+
addAssignees: true
6+
7+
# A list of reviewers to be added to pull requests (GitHub user name)
8+
# reviewers:
9+
# - egilmorez
10+
11+
# A number of reviewers added to the pull request
12+
# Set 0 to add all the reviewers (default: 0)
13+
# numberOfReviewers: 0
14+
15+
# A list of assignees, overrides reviewers if set
16+
assignees:
17+
- egilmorez
18+
19+
# A number of assignees to add to the pull request
20+
# Set to 0 to add all of the assignees.
21+
# Uses numberOfReviewers if unset.
22+
numberOfAssignees: 0
23+
24+
# A list of keywords to be skipped the process that add reviewers if pull requests include it
25+
# skipKeywords:
26+
# - wip
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Assign tech writers
2+
3+
on:
4+
pull_request:
5+
types: [labeled]
6+
jobs:
7+
assign_tech_writers:
8+
if: ${{github.event.label.name == 'doc-changes'}}
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: assign techwriters to PR
13+
uses: kentaro-m/[email protected]
14+
with:
15+
configuration-path: ".github/auto_assign.yml"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Label doc changes
2+
3+
on: pull_request
4+
5+
env:
6+
GITHUB_PULL_REQUEST_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
7+
GITHUB_PULL_REQUEST_BASE_SHA: ${{ github.event.pull_request.base.sha }}
8+
9+
jobs:
10+
check_doc_changes:
11+
name: Check if docs are being changed
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout Repo
16+
uses: actions/checkout@master
17+
with:
18+
# This makes Actions fetch all Git history so check_changeset script can diff properly.
19+
fetch-depth: 0
20+
- name: Set up Node (14)
21+
uses: actions/setup-node@v2
22+
with:
23+
node-version: 14.x
24+
- name: Yarn install
25+
run: yarn
26+
- name: Run detect doc changes script
27+
run: yarn ts-node-script scripts/exp/detect-doc-changes.ts
28+
id: check-doc-changes
29+
- name: Print if doc changed output
30+
run: echo "${{steps.check-doc-changes.outputs.DOC_CHANGED}}"
31+
- name: Add label if there are doc changes
32+
uses: actions-ecosystem/[email protected]
33+
if: ${{steps.check-doc-changes.outputs.DOC_CHANGED == 'true'}}
34+
with:
35+
labels: doc-changes
36+
github_token: ${{ secrets.GITHUB_TOKEN }}

scripts/exp/detect-doc-changes.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import simpleGit from 'simple-git/promise';
19+
import { spawn } from 'child-process-promise';
20+
import * as tmp from 'tmp';
21+
22+
/**
23+
* check if there is any doc changes from baseSha to headSha
24+
*/
25+
async function docChanged(baseSha: string, headSha: string): Promise<boolean> {
26+
const tmpDir = tmp.dirSync().name;
27+
console.log('tmpDir is', tmpDir);
28+
// clone repo to the tmpDir
29+
await spawn(
30+
'git',
31+
['clone', 'https://github.com/firebase/firebase-js-sdk.git', tmpDir],
32+
{ stdio: 'inherit' }
33+
);
34+
35+
const git = simpleGit(tmpDir);
36+
37+
// generate reference docs using the baseSha
38+
await git.checkout(baseSha);
39+
await spawn('yarn', [], { cwd: tmpDir, stdio: 'inherit' });
40+
await spawn('yarn', ['docgen:exp', 'devsite'], {
41+
cwd: tmpDir,
42+
stdio: 'inherit'
43+
});
44+
45+
// revert yarn.lock, so we can checkout the headSha without conflict.
46+
await git.checkout('yarn.lock');
47+
// stash changes, so we can checkout the headSha without conflict.
48+
await git.stash();
49+
50+
// generate reference docs using the headSha
51+
await git.checkout(headSha);
52+
await spawn('yarn', [], { cwd: tmpDir, stdio: 'inherit' });
53+
54+
// stage the docs generated by baseSha, so we can use git diff to tell if any docs are different in the headSha
55+
await git.stash(['pop']);
56+
await git.add('*');
57+
await spawn('yarn', ['docgen:exp', 'devsite'], {
58+
cwd: tmpDir,
59+
stdio: 'inherit'
60+
});
61+
62+
// check if any file is changed.
63+
const diff = await git.diff();
64+
// check if new files are created.
65+
const untracked = await git.raw([
66+
'ls-files',
67+
'-o',
68+
'--directory',
69+
'--exclude-standard'
70+
]);
71+
72+
return !!diff || !!untracked;
73+
}
74+
75+
// this function is supposed to run in the Github action.
76+
async function runInCI() {
77+
const headSha = process.env.GITHUB_PULL_REQUEST_HEAD_SHA;
78+
const mergeBaseSha = process.env.GITHUB_PULL_REQUEST_BASE_SHA;
79+
80+
if (!headSha || !mergeBaseSha) {
81+
console.log('No merge base or head found. Is it not a PR?');
82+
process.exit(1);
83+
}
84+
85+
if (await docChanged(mergeBaseSha, headSha)) {
86+
console.log(`::set-output name=DOC_CHANGED::true`);
87+
} else {
88+
console.log(`::set-output name=DOC_CHANGED::false`);
89+
}
90+
}
91+
92+
runInCI();

scripts/exp/remove-exp.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const {
3232
// can be used in command line
3333
if (argv._[0]) {
3434
const dirOrFile = path.resolve(argv._[0]);
35-
3635
try {
3736
accessSync(dirOrFile);
3837
if (statSync(dirOrFile).isFile()) {

0 commit comments

Comments
 (0)