-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: experiment with optional CI jobs (#626)
- Loading branch information
1 parent
700927f
commit 5495e7b
Showing
5 changed files
with
157 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
const {request} = require('gaxios'); | ||
const args = process.argv.slice(2); | ||
const requiredJobs = JSON.parse(args[0]); | ||
const runId = process.env.GITHUB_RUN_ID; | ||
const repo = process.env.GITHUB_REPOSITORY; | ||
const githubToken = args[1]; | ||
|
||
async function main() { | ||
// Do not wait longer than 20 minutes for all jobs to finish. | ||
// This loop goes 5 seconds at a time. | ||
// 20 minutes * 60 seconds/min / 5 seconds per loop. | ||
const iterations = 20 * 60 / 5 | ||
for (let i=0; i<iterations; i++) { | ||
const url = `https://api.github.com/repos/${repo}/actions/runs/${runId}/jobs`; | ||
const res = await request({ | ||
url, | ||
headers: { | ||
authentication: `token ${githubToken}`, | ||
} | ||
}); | ||
for (const job of res.data.jobs) { | ||
if (job.status === 'completed' && job.conclusion !== 'success') { | ||
throw new Error(`Job ${job.name} failed.`); | ||
} | ||
} | ||
const totalCount = res.data.total_count; | ||
console.log(`total count: ${totalCount}`); | ||
console.log(`required jobs: ${requiredJobs.length}`); | ||
for (const job of requiredJobs) { | ||
console.log(`- ${job}`); | ||
} | ||
if (totalCount >= requiredJobs.length) { | ||
const successfulJobs = res.data.jobs.filter(job => { | ||
return job.status === 'completed' && job.conclusion === 'success'; | ||
}).map(job => job.name); | ||
let completedCount = 0; | ||
for (const job of requiredJobs) { | ||
if (successfulJobs.includes(job)) { | ||
completedCount++; | ||
} | ||
} | ||
console.log(`${completedCount} of ${requiredJobs.length} required jobs complete.`); | ||
if (completedCount === requiredJobs.length) { | ||
return; | ||
} | ||
} | ||
await new Promise(r => setTimeout(r, 5000)); | ||
} | ||
} | ||
main().catch(err => { | ||
console.log(`::error ${err.message}`); | ||
console.error(err); | ||
process.exitCode = -1; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
const {execSync} = require('child_process'); | ||
execSync('git fetch origin master'); | ||
const baseRef = process.env.GITHUB_BASE_REF; | ||
console.log(`base ref: ${baseRef}`); | ||
const status = execSync(`git diff --name-only origin/${baseRef}`, { encoding: 'utf-8'}); | ||
console.log(status); | ||
const changes = status.split('\n'); | ||
let nodePaths = new Set(); | ||
let goPaths = new Set(); | ||
let bashPaths = new Set(); | ||
for (const change of changes) { | ||
if (change.startsWith('packages/')) { | ||
nodePaths.add(change.split('/')[1]); | ||
}; | ||
if (change.startsWith('packages/buildcop/')) { | ||
goPaths.add('packages/buildcop') | ||
} | ||
if (change.startsWith('serverless-scheduler-proxy/')) { | ||
goPaths.add('serverless-scheduler-proxy'); | ||
} | ||
if (change.startsWith('scripts/')) { | ||
bashPaths.add('scripts'); | ||
} | ||
} | ||
nodePaths = Array.from(nodePaths); | ||
goPaths = Array.from(goPaths); | ||
bashPaths = Array.from(bashPaths); | ||
const requiredJobs = [ | ||
'changeFinder', | ||
...nodePaths.map(p => `test (${p})`), | ||
...goPaths.map(p => `go-test (${p})`), | ||
...bashPaths.map(p => `bash-test (${p})`), | ||
]; | ||
console.log(nodePaths, '\n', goPaths, '\n', bashPaths, '\n', requiredJobs); | ||
console.log(`::set-output name=nodePaths::${JSON.stringify(nodePaths)}`); | ||
console.log(`::set-output name=goPaths::${JSON.stringify(goPaths)}`); | ||
console.log(`::set-output name=bashPaths::${JSON.stringify(bashPaths)}`); | ||
console.log(`::set-output name=requiredJobs::${JSON.stringify(requiredJobs)}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters