Skip to content

Commit bb962b8

Browse files
ci: use flakybot with actions workflows (#3079)
* ci: use flakybot with actions workflows * revert to old workflow file * use 2 workflows * comment out both workflows * add back flakybot * update flakybot path * refactor directory structure * fix job reference * more tests * rename file * test * update var names * remove if * update var names * add env vars to GITHUB_ENV * fix env vars * fix if statement * test flakybot run * cleanup flakybot script * use go.mod file * missing $ * missing } * update flakybot yaml * improve caching * test flakybot run * test run * Update workflow conditions * revert test case to pass * remove label fix * test pr number logic * revert change to root package.json * test simplifying remove_label * remove comment * address feedback and update template --------- Co-authored-by: Patti Shin <[email protected]>
1 parent 11205f4 commit bb962b8

File tree

7 files changed

+247
-104
lines changed

7 files changed

+247
-104
lines changed

.github/flakybot.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
issuePriority: p2

.github/workflows/ci.yaml.njk

+12-50
Original file line numberDiff line numberDiff line change
@@ -33,53 +33,15 @@ on:
3333
- cron: '0 0 * * 0'
3434
jobs:
3535
test:
36-
if: {% raw %}${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}{% endraw %}
37-
runs-on: ubuntu-latest
38-
timeout-minutes: 60
39-
permissions:
40-
contents: 'write'
41-
pull-requests: 'write'
42-
id-token: 'write'
43-
steps:
44-
- uses: actions/[email protected]
45-
with:
46-
ref: {% raw %}${{github.event.pull_request.head.sha}}{% endraw %}
47-
- uses: 'google-github-actions/[email protected]'
48-
with:
49-
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
50-
service_account: '[email protected]'
51-
create_credentials_file: 'true'
52-
access_token_lifetime: 600s
53-
- uses: actions/[email protected]
54-
with:
55-
node-version: 16
56-
- run: npm install
57-
working-directory: {{path}}
58-
- run: npm test
59-
working-directory: {{path}}
60-
env:
61-
MOCHA_REPORTER_SUITENAME: {{suite}}
62-
MOCHA_REPORTER_OUTPUT: {{suite}}_sponge_log.xml
63-
MOCHA_REPORTER: xunit
64-
- if: {% raw %}${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}{% endraw %}
65-
uses: actions/github-script@v6
66-
with:
67-
github-token: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %}
68-
script: |
69-
try {
70-
await github.rest.issues.removeLabel({
71-
name: 'actions:force-run',
72-
owner: 'GoogleCloudPlatform',
73-
repo: 'nodejs-docs-samples',
74-
issue_number: context.payload.pull_request.number
75-
});
76-
} catch (e) {
77-
if (!e.message.includes('Label does not exist')) {
78-
throw e;
79-
}
80-
}
81-
- if: {% raw %}${{ github.event_name == 'schedule' && always() }}{% endraw %}
82-
run: |
83-
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
84-
chmod +x ./flakybot
85-
{% raw %}./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}{% endraw %}
36+
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run'
37+
uses: ./.github/workflows/test.yaml
38+
with:
39+
name: '{{name}}'
40+
path: '{{path}}'
41+
remove_label:
42+
if: github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' && always()
43+
uses: ./.github/workflows/remove-label.yaml
44+
flakybot:
45+
if: github.event_name == 'schedule' && always()
46+
uses: ./.github/workflows/flakybot.yaml
47+
needs: [test]

.github/workflows/flakybot.yaml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: FlakyBot
16+
17+
on:
18+
workflow_call:
19+
20+
env:
21+
FLAKYBOT_VERSION: '1.2.0'
22+
23+
jobs:
24+
flakybot:
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 5
27+
permissions:
28+
contents: 'read'
29+
id-token: 'write'
30+
steps:
31+
- name: authenticate
32+
uses: 'google-github-actions/auth@v1'
33+
with:
34+
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
35+
service_account: '[email protected]'
36+
create_credentials_file: 'true'
37+
access_token_lifetime: 600s
38+
- name: download test results
39+
uses: actions/download-artifact@v3
40+
with:
41+
name: test-results
42+
- name: download FlakyBot
43+
run: |
44+
curl -s -L https://github.com/googleapis/repo-automation-bots/archive/refs/tags/flakybot-v${{ env.FLAKYBOT_VERSION }}.tar.gz -o flakybot.tar.gz
45+
tar xzf flakybot.tar.gz
46+
cp -rT repo-automation-bots-flakybot-v${{ env.FLAKYBOT_VERSION}}/packages/flakybot/ .
47+
- uses: actions/setup-go@v3
48+
with:
49+
cache: true
50+
cache-dependency-path: '${{ github.workspace }}/go.sum'
51+
go-version-file: '${{ github.workspace }}/go.mod'
52+
- name: run FlakyBot
53+
run: go run flakybot.go --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}

.github/workflows/remove-label.yaml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Remove Label
16+
17+
on:
18+
workflow_call:
19+
20+
jobs:
21+
remove_label:
22+
runs-on: ubuntu-latest
23+
timeout-minutes: 5
24+
steps:
25+
- uses: actions/github-script@v6
26+
with:
27+
github-token: ${{ secrets.GITHUB_TOKEN }}
28+
script: |
29+
try {
30+
const event = JSON.parse(
31+
require("fs").readFileSync(process.env.GITHUB_EVENT_PATH, "utf8")
32+
);
33+
await github.rest.issues.removeLabel({
34+
name: "actions:force-run",
35+
owner: "GoogleCloudPlatform",
36+
repo: "nodejs-docs-samples",
37+
issue_number: event.pull_request.number,
38+
});
39+
} catch (e) {
40+
if (!e.message.includes("Label does not exist")) {
41+
throw e;
42+
}
43+
}

.github/workflows/scheduler.yaml

+12-54
Original file line numberDiff line numberDiff line change
@@ -33,57 +33,15 @@ on:
3333
- cron: '0 0 * * 0'
3434
jobs:
3535
test:
36-
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}
37-
runs-on: ubuntu-latest
38-
timeout-minutes: 60
39-
permissions:
40-
contents: 'write'
41-
pull-requests: 'write'
42-
id-token: 'write'
43-
defaults:
44-
run:
45-
working-directory: scheduler
46-
steps:
47-
- uses: actions/[email protected]
48-
with:
49-
ref: ${{github.event.pull_request.head.sha}}
50-
- uses: 'google-github-actions/[email protected]'
51-
with:
52-
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
53-
service_account: '[email protected]'
54-
create_credentials_file: 'true'
55-
access_token_lifetime: 600s
56-
- uses: actions/[email protected]
57-
with:
58-
node-version: 16
59-
- run: npm install
60-
working-directory: .
61-
- run: npm install
62-
- run: npm run build
63-
- run: npm test
64-
env:
65-
MOCHA_REPORTER_SUITENAME: scheduler
66-
MOCHA_REPORTER_OUTPUT: scheduler_sponge_log.xml
67-
MOCHA_REPORTER: xunit
68-
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
69-
uses: actions/github-script@v6
70-
with:
71-
github-token: ${{ secrets.GITHUB_TOKEN }}
72-
script: |
73-
try {
74-
await github.rest.issues.removeLabel({
75-
name: 'actions:force-run',
76-
owner: 'GoogleCloudPlatform',
77-
repo: 'nodejs-docs-samples',
78-
issue_number: context.payload.pull_request.number
79-
});
80-
} catch (e) {
81-
if (!e.message.includes('Label does not exist')) {
82-
throw e;
83-
}
84-
}
85-
- if: ${{ github.event_name == 'schedule' && always() }}
86-
run: |
87-
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
88-
chmod +x ./flakybot
89-
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
36+
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run'
37+
uses: ./.github/workflows/test.yaml
38+
with:
39+
name: 'scheduler'
40+
path: 'scheduler'
41+
remove_label:
42+
if: github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' && always()
43+
uses: ./.github/workflows/remove-label.yaml
44+
flakybot:
45+
if: github.event_name == 'schedule' && always()
46+
uses: ./.github/workflows/flakybot.yaml
47+
needs: [test]

.github/workflows/test.yaml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Test Sample
16+
17+
on:
18+
workflow_call:
19+
inputs:
20+
name:
21+
required: true
22+
type: string
23+
path:
24+
required: true
25+
type: string
26+
jobs:
27+
test:
28+
runs-on: ubuntu-latest
29+
timeout-minutes: 60
30+
permissions:
31+
contents: 'write'
32+
pull-requests: 'write'
33+
id-token: 'write'
34+
defaults:
35+
run:
36+
working-directory: ${{ inputs.path }}
37+
steps:
38+
- uses: actions/[email protected]
39+
with:
40+
ref: ${{github.event.pull_request.head.sha}}
41+
- uses: 'google-github-actions/[email protected]'
42+
with:
43+
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
44+
service_account: '[email protected]'
45+
create_credentials_file: 'true'
46+
access_token_lifetime: 600s
47+
- uses: actions/[email protected]
48+
with:
49+
node-version: 16
50+
- name: Get npm cache directory
51+
id: npm-cache-dir
52+
shell: bash
53+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
54+
- uses: actions/cache@v3
55+
id: npm-cache
56+
with:
57+
path: ${{ steps.npm-cache-dir.outputs.dir }}
58+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
59+
restore-keys: |
60+
${{ runner.os }}-node-
61+
- name: install repo dependencies
62+
run: npm install
63+
working-directory: .
64+
- name: install directory dependencies
65+
run: npm install
66+
- run: npm run build
67+
- name: set env vars for scheduled run
68+
if: github.event.action == 'schedule'
69+
run: |
70+
echo "MOCHA_REPORTER_SUITENAME=${{ inputs.name }}" >> $GITHUB_ENV
71+
echo "MOCHA_REPORTER_OUTPUT=${{github.run_id}}_sponge_log.xml" >> $GITHUB_ENV
72+
echo "MOCHA_REPORTER=xunit" >> $GITHUB_ENV
73+
- run: npm test
74+
- name: upload test results for FlakyBot workflow
75+
if: github.event.action == 'schedule' && always()
76+
uses: actions/upload-artifact@v3
77+
with:
78+
name: test-results
79+
path: ${{ inputs.path }}/${{ env.MOCHA_REPORTER_OUTPUT }}
80+
retention-days: 1

.mocharc.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
const config = {};
15+
16+
if (process.env.MOCHA_THROW_DEPRECATION === 'false') {
17+
delete config['throw-deprecation'];
18+
}
19+
if (process.env.MOCHA_REPORTER) {
20+
config.reporter = process.env.MOCHA_REPORTER;
21+
}
22+
23+
const reporterOptions = [];
24+
if (process.env.MOCHA_REPORTER_OUTPUT) {
25+
reporterOptions.push(`output=${process.env.MOCHA_REPORTER_OUTPUT}`);
26+
}
27+
if (process.env.MOCHA_REPORTER_SUITENAME) {
28+
reporterOptions.push(`suiteName=${process.env.MOCHA_REPORTER_SUITENAME}`);
29+
}
30+
config['reporter-option'] = reporterOptions;
31+
32+
module.exports = config;

0 commit comments

Comments
 (0)