Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit c4dccdc

Browse files
jelbournmmalerba
authored andcommitted
chore: add script to generate a script to schedule presubmit runs (#10994)
1 parent 1956d22 commit c4dccdc

File tree

3 files changed

+193
-0
lines changed

3 files changed

+193
-0
lines changed

package-lock.json

Lines changed: 109 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"conventional-changelog": "^1.1.0",
3737
"dgeni": "^0.4.1",
3838
"dgeni-packages": "^0.13.0",
39+
"github": "^12.0.5",
3940
"github-contributors-list": "^1.2.1",
4041
"glob": "~7.0.5",
4142
"gulp": "^3.9.1",

scripts/write-presubmit-scheduler.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env node
2+
3+
const path = require('path');
4+
const fs = require('fs');
5+
const GitHubApi = require('github');
6+
const github = new GitHubApi();
7+
8+
9+
/** CONFIGURATION: change these things if you want to tweak how the runs are made. */
10+
11+
/** Path to the local ng-material. By default based on the location of this script. */
12+
const localRepo = path.resolve(__dirname, '..');
13+
14+
/** Where to write the output from the presubmit script. */
15+
const logDir = '/tmp/v1-pr-presubmit-logs';
16+
17+
/**
18+
* The presubmit script to use (can change this if you want to use a locally modified script).
19+
* The default path is stored in an environment variable because it references an internal-Google
20+
* location.
21+
*/
22+
const presubmitScript = path.join(process.env.MAT_PRESUBMIT_DIR, 'sync-material.sh');
23+
24+
/** Time to start presubmits. */
25+
const startTime = '9:30 pm';
26+
27+
/** Number of minutes between presubmit runs. */
28+
const intervalMinutes = 20;
29+
30+
/** Instead of querying github for PR numbers, manually provide the PR numbers to be presubmit */
31+
const explicitPullRequests = [];
32+
33+
/** END OF CONFIGURATION. */
34+
35+
36+
37+
/** Number of intervals that have scheduled tasks already. */
38+
let presubmitCount = 0;
39+
40+
if (explicitPullRequests.length) {
41+
writeScheduleScript(explicitPullRequests.map(n => ({number: n})));
42+
} else {
43+
// Fetch PRs that are merge-ready but not merge-safe
44+
github.search.issues({
45+
per_page: 100,
46+
q: 'repo:angular/material is:open type:pr label:"pr: merge ready" -label:"pr: merge safe"',
47+
}, (error, response) => {
48+
if (response) {
49+
writeScheduleScript(response.data.items);
50+
} else {
51+
console.error('Fetching merge-ready PRs failed.');
52+
console.error(error);
53+
}
54+
});
55+
}
56+
57+
58+
function writeScheduleScript(prs) {
59+
let script =
60+
`#!/bin/bash \n\n` +
61+
`mkdir -p ${logDir} \n\n` +
62+
`# Be sure you have no locally modified files in your git client before running this. \n\n`;
63+
64+
// Generate a command for each file to be piped into the `at` command, scheduling it to run at
65+
// a later time.
66+
for (const pr of prs) {
67+
script +=
68+
`echo '(` +
69+
`cd ${localRepo} ; ` +
70+
`${presubmitScript} presubmit ${pr.number} --global 2>&1 > ${logDir}/pr-${pr.number}.txt ` +
71+
`)' | ` +
72+
`at ${startTime} today + ${intervalMinutes * presubmitCount} min ` +
73+
`\n`;
74+
75+
presubmitCount++;
76+
}
77+
78+
fs.writeFileSync(path.join(localRepo, 'dist', 'schedule-presubmit.sh'), script, 'utf-8');
79+
80+
console.log('schedule-presubmit.sh written to dist');
81+
console.log('Be sure to prodaccess overnight, that you have no locally modified files, ' +
82+
'and push_tag has been run');
83+
}

0 commit comments

Comments
 (0)