Skip to content

ci: use flakybot with actions workflows #3079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ff652c2
ci: use flakybot with actions workflows
kweinmeister Mar 11, 2023
2090428
revert to old workflow file
kweinmeister Mar 11, 2023
46e2e86
use 2 workflows
kweinmeister Mar 11, 2023
e46a195
comment out both workflows
kweinmeister Mar 11, 2023
b4f6345
add back flakybot
kweinmeister Mar 11, 2023
320c829
update flakybot path
kweinmeister Mar 11, 2023
abfc09a
refactor directory structure
kweinmeister Mar 11, 2023
6aab921
fix job reference
kweinmeister Mar 11, 2023
2bd765b
more tests
kweinmeister Mar 11, 2023
d5951ee
rename file
kweinmeister Mar 11, 2023
df9d6b4
test
kweinmeister Mar 11, 2023
77c248b
update var names
kweinmeister Mar 11, 2023
f033771
remove if
kweinmeister Mar 11, 2023
a0cadfa
update var names
kweinmeister Mar 11, 2023
dd43240
add env vars to GITHUB_ENV
kweinmeister Mar 11, 2023
71a49d4
fix env vars
kweinmeister Mar 11, 2023
141769f
fix if statement
kweinmeister Mar 11, 2023
918b15f
test flakybot run
kweinmeister Mar 11, 2023
b819ae2
cleanup flakybot script
kweinmeister Mar 11, 2023
7a5f878
use go.mod file
kweinmeister Mar 11, 2023
9b4f956
missing $
kweinmeister Mar 11, 2023
73984ef
missing }
kweinmeister Mar 11, 2023
7c27ae8
update flakybot yaml
kweinmeister Mar 11, 2023
771b794
improve caching
kweinmeister Mar 11, 2023
0479596
test flakybot run
kweinmeister Mar 11, 2023
a60af54
test run
kweinmeister Mar 11, 2023
9cbe3ad
Update workflow conditions
kweinmeister Mar 11, 2023
80915fd
revert test case to pass
kweinmeister Mar 11, 2023
790ff93
remove label fix
kweinmeister Mar 11, 2023
dc947af
test pr number logic
kweinmeister Mar 11, 2023
48e4089
revert change to root package.json
kweinmeister Mar 15, 2023
0f8e6d1
test simplifying remove_label
kweinmeister Mar 16, 2023
d83abb5
remove comment
kweinmeister Mar 17, 2023
51188d4
Merge branch 'main' into flakybot-actions
kweinmeister Mar 21, 2023
acf819a
Merge branch 'main' into flakybot-actions
pattishin Apr 6, 2023
3390b7e
address feedback and update template
kweinmeister Apr 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/flakybot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 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.

issuePriority: p2
62 changes: 12 additions & 50 deletions .github/workflows/ci.yaml.njk
Original file line number Diff line number Diff line change
Expand Up @@ -33,53 +33,15 @@ on:
- cron: '0 0 * * 0'
jobs:
test:
if: {% raw %}${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}{% endraw %}
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: 'write'
pull-requests: 'write'
id-token: 'write'
steps:
- uses: actions/[email protected]
with:
ref: {% raw %}${{github.event.pull_request.head.sha}}{% endraw %}
- uses: 'google-github-actions/[email protected]'
with:
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
service_account: '[email protected]'
create_credentials_file: 'true'
access_token_lifetime: 600s
- uses: actions/[email protected]
with:
node-version: 16
- run: npm install
working-directory: {{path}}
- run: npm test
working-directory: {{path}}
env:
MOCHA_REPORTER_SUITENAME: {{suite}}
MOCHA_REPORTER_OUTPUT: {{suite}}_sponge_log.xml
MOCHA_REPORTER: xunit
- if: {% raw %}${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}{% endraw %}
uses: actions/github-script@v6
with:
github-token: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %}
script: |
try {
await github.rest.issues.removeLabel({
name: 'actions:force-run',
owner: 'GoogleCloudPlatform',
repo: 'nodejs-docs-samples',
issue_number: context.payload.pull_request.number
});
} catch (e) {
if (!e.message.includes('Label does not exist')) {
throw e;
}
}
- if: {% raw %}${{ github.event_name == 'schedule' && always() }}{% endraw %}
run: |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
chmod +x ./flakybot
{% raw %}./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}{% endraw %}
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run'
uses: ./.github/workflows/test.yaml
with:
name: '{{name}}'
path: '{{path}}'
remove_label:
if: github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' && always()
uses: ./.github/workflows/remove-label.yaml
flakybot:
if: github.event_name == 'schedule' && always()
uses: ./.github/workflows/flakybot.yaml
needs: [test]
53 changes: 53 additions & 0 deletions .github/workflows/flakybot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2023 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.

name: FlakyBot

on:
workflow_call:

env:
FLAKYBOT_VERSION: '1.2.0'

jobs:
flakybot:
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: authenticate
uses: 'google-github-actions/auth@v1'
with:
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
service_account: '[email protected]'
create_credentials_file: 'true'
access_token_lifetime: 600s
- name: download test results
uses: actions/download-artifact@v3
with:
name: test-results
- name: download FlakyBot
run: |
curl -s -L https://github.com/googleapis/repo-automation-bots/archive/refs/tags/flakybot-v${{ env.FLAKYBOT_VERSION }}.tar.gz -o flakybot.tar.gz
tar xzf flakybot.tar.gz
cp -rT repo-automation-bots-flakybot-v${{ env.FLAKYBOT_VERSION}}/packages/flakybot/ .
- uses: actions/setup-go@v3
with:
cache: true
cache-dependency-path: '${{ github.workspace }}/go.sum'
go-version-file: '${{ github.workspace }}/go.mod'
- name: run FlakyBot
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}}
43 changes: 43 additions & 0 deletions .github/workflows/remove-label.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2023 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.

name: Remove Label

on:
workflow_call:

jobs:
remove_label:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
const event = JSON.parse(
require("fs").readFileSync(process.env.GITHUB_EVENT_PATH, "utf8")
);
await github.rest.issues.removeLabel({
name: "actions:force-run",
owner: "GoogleCloudPlatform",
repo: "nodejs-docs-samples",
issue_number: event.pull_request.number,
});
} catch (e) {
if (!e.message.includes("Label does not exist")) {
throw e;
}
}
66 changes: 12 additions & 54 deletions .github/workflows/scheduler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,57 +33,15 @@ on:
- cron: '0 0 * * 0'
jobs:
test:
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: 'write'
pull-requests: 'write'
id-token: 'write'
defaults:
run:
working-directory: scheduler
steps:
- uses: actions/[email protected]
with:
ref: ${{github.event.pull_request.head.sha}}
- uses: 'google-github-actions/[email protected]'
with:
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
service_account: '[email protected]'
create_credentials_file: 'true'
access_token_lifetime: 600s
- uses: actions/[email protected]
with:
node-version: 16
- run: npm install
working-directory: .
- run: npm install
- run: npm run build
- run: npm test
env:
MOCHA_REPORTER_SUITENAME: scheduler
MOCHA_REPORTER_OUTPUT: scheduler_sponge_log.xml
MOCHA_REPORTER: xunit
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
await github.rest.issues.removeLabel({
name: 'actions:force-run',
owner: 'GoogleCloudPlatform',
repo: 'nodejs-docs-samples',
issue_number: context.payload.pull_request.number
});
} catch (e) {
if (!e.message.includes('Label does not exist')) {
throw e;
}
}
- if: ${{ github.event_name == 'schedule' && always() }}
run: |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
chmod +x ./flakybot
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run'
uses: ./.github/workflows/test.yaml
with:
name: 'scheduler'
path: 'scheduler'
remove_label:
if: github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' && always()
uses: ./.github/workflows/remove-label.yaml
flakybot:
if: github.event_name == 'schedule' && always()
uses: ./.github/workflows/flakybot.yaml
needs: [test]
80 changes: 80 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright 2023 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.

name: Test Sample

on:
workflow_call:
inputs:
name:
required: true
type: string
path:
required: true
type: string
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: 'write'
pull-requests: 'write'
id-token: 'write'
defaults:
run:
working-directory: ${{ inputs.path }}
steps:
- uses: actions/[email protected]
with:
ref: ${{github.event.pull_request.head.sha}}
- uses: 'google-github-actions/[email protected]'
with:
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
service_account: '[email protected]'
create_credentials_file: 'true'
access_token_lifetime: 600s
- uses: actions/[email protected]
with:
node-version: 16
- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- uses: actions/cache@v3
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: install repo dependencies
run: npm install
working-directory: .
- name: install directory dependencies
run: npm install
- run: npm run build
- name: set env vars for scheduled run
if: github.event.action == 'schedule'
run: |
echo "MOCHA_REPORTER_SUITENAME=${{ inputs.name }}" >> $GITHUB_ENV
echo "MOCHA_REPORTER_OUTPUT=${{github.run_id}}_sponge_log.xml" >> $GITHUB_ENV
echo "MOCHA_REPORTER=xunit" >> $GITHUB_ENV
- run: npm test
- name: upload test results for FlakyBot workflow
if: github.event.action == 'schedule' && always()
uses: actions/upload-artifact@v3
with:
name: test-results
path: ${{ inputs.path }}/${{ env.MOCHA_REPORTER_OUTPUT }}
retention-days: 1
32 changes: 32 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 config = {};

if (process.env.MOCHA_THROW_DEPRECATION === 'false') {
delete config['throw-deprecation'];
}
if (process.env.MOCHA_REPORTER) {
config.reporter = process.env.MOCHA_REPORTER;
}

const reporterOptions = [];
if (process.env.MOCHA_REPORTER_OUTPUT) {
reporterOptions.push(`output=${process.env.MOCHA_REPORTER_OUTPUT}`);
}
if (process.env.MOCHA_REPORTER_SUITENAME) {
reporterOptions.push(`suiteName=${process.env.MOCHA_REPORTER_SUITENAME}`);
}
config['reporter-option'] = reporterOptions;

module.exports = config;