Skip to content

Commit

Permalink
build: experiment with optional CI jobs (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Nov 17, 2020
1 parent 700927f commit 5495e7b
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 56 deletions.
22 changes: 2 additions & 20 deletions .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,8 @@ branchProtectionRules:
- pattern: master
isAdminEnforced: true
requiredStatusCheckContexts:
- 'test (12, auto-label)'
- 'test (12, blunderbuss)'
- 'test (12, buildcop)'
- 'test (12, conventional-commit-lint)'
- 'test (12, failurechecker)'
- 'test (12, gcf-utils)'
- 'test (12, generate-bot)'
- 'test (12, header-checker-lint)'
- 'test (12, label-sync)'
- 'test (12, merge-on-green)'
- 'test (12, monitoring-system/data-processor)'
- 'test (12, release-please)'
- 'test (12, slo-stat-bot)'
- 'test (12, snippet-bot)'
- 'test (12, sync-repo-settings)'
- 'test (12, trusted-contribution)'
- 'test (10, publish)'
- 'Go tests (packages/buildcop)'
- 'Go tests (serverless-scheduler-proxy)'
- 'Bash tests (scripts)'
- 'changeFinder'
- 'finale'
- 'cla/google'
requiredApprovingReviewCount: 1
requiresCodeOwnerReviews: true
Expand Down
62 changes: 32 additions & 30 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,29 @@ on:
pull_request:
name: ci
jobs:
changeFinder:
runs-on: ubuntu-latest
outputs:
nodePaths: ${{ steps.interrogate.outputs.nodePaths }}
goPaths: ${{ steps.interrogate.outputs.goPaths }}
bashPaths: ${{ steps.interrogate.outputs.bashPaths }}
requiredJobs: ${{ steps.interrogate.outputs.requiredJobs }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
- id: interrogate
run: node ./.github/workflows/interrogate.js
env:
GITHUB_BASE_REF: ${{github.base_ref}}
test:
runs-on: ubuntu-latest
needs: changeFinder
strategy:
fail-fast: false
matrix:
node: [12]
package: [
'auto-label',
'blunderbuss',
'buildcop',
'conventional-commit-lint',
'failurechecker',
'gcf-utils',
'generate-bot',
'generated-files-bot',
'header-checker-lint',
'label-sync',
'merge-on-green',
'monitoring-system/data-processor',
'release-please',
'slo-stat-bot',
'snippet-bot',
'sync-repo-settings',
'trusted-contribution'
]
include:
- node: 10
package: 'publish'
package: ${{fromJson(needs.changeFinder.outputs.nodePaths)}}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand All @@ -48,15 +43,12 @@ jobs:
- run: npm run lint
working-directory: ./packages/${{ matrix.package }}
go-test:
name: Go tests
runs-on: ubuntu-latest
needs: changeFinder
strategy:
fail-fast: false
matrix:
module: [
'packages/buildcop',
'serverless-scheduler-proxy'
]
module: ${{fromJson(needs.changeFinder.outputs.goPaths)}}
steps:
- name: Install Go
uses: actions/setup-go@v2
Expand All @@ -76,16 +68,26 @@ jobs:
- run: go test ./...
working-directory: ./${{ matrix.module }}
bash-test:
name: Bash tests
runs-on: ubuntu-latest
needs: changeFinder
strategy:
fail-fast: false
matrix:
module: ["scripts"]
module: ${{fromJson(needs.changeFinder.outputs.bashPaths)}}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: bashtest
run: |
./test.sh
working-directory: ./${{ matrix.module }}
finale:
runs-on: ubuntu-latest
needs: changeFinder
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npm install
- run: node ./.github/workflows/finale.js '${{needs.changeFinder.outputs.requiredJobs}}' ${{secrets.GITHUB_TOKEN}}
68 changes: 68 additions & 0 deletions .github/workflows/finale.js
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;
});
52 changes: 52 additions & 0 deletions .github/workflows/interrogate.js
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)}`);
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
"fix": "npm run run -- npm run fix",
"test": "c8 npm run run -- npm test",
"proxy": "smee",
"generate-bot": "node ./packages/generate-bot/run.js",
"api-extractor": "api-extractor run --local",
"api-documenter": "api-documenter yaml --input-folder=temp"
"generate-bot": "node ./packages/generate-bot/run.js"
},
"devDependencies": {
"c8": "^7.1.0",
"smee-client": "^1.1.0",
"@microsoft/api-documenter": "^7.8.10",
"@microsoft/api-extractor": "^7.8.10"
"gaxios": "^3.0.3",
"smee-client": "^1.1.0"
}
}

0 comments on commit 5495e7b

Please sign in to comment.