Skip to content

Commit 4f53381

Browse files
JustinBeckwithnoerog
authored andcommitted
test(tasks): migrate cloud tasks to GitHub Actions (#2458)
1 parent 064d7e8 commit 4f53381

10 files changed

Lines changed: 283 additions & 170 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: cloud-tasks-app
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- 'cloud-tasks/app/**'
8+
pull_request:
9+
paths:
10+
- 'cloud-tasks/app/**'
11+
pull_request_target:
12+
types: [labeled]
13+
schedule:
14+
- cron: '0 2 * * *'
15+
jobs:
16+
test:
17+
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: 'write'
21+
pull-requests: 'write'
22+
id-token: 'write'
23+
steps:
24+
- uses: 'google-github-actions/auth@v0.3.1'
25+
with:
26+
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
27+
service_account: 'kokoro-system-test@long-door-651.iam.gserviceaccount.com'
28+
create_credentials_file: 'true'
29+
access_token_lifetime: 600s
30+
- uses: actions/checkout@v2
31+
with:
32+
ref: ${{github.event.pull_request.head.ref}}
33+
repository: ${{github.event.pull_request.head.repo.full_name}}
34+
- uses: actions/setup-node@v2
35+
with:
36+
node-version: 14
37+
- run: npm install
38+
working-directory: cloud-tasks/app
39+
- run: npm test
40+
working-directory: cloud-tasks/app
41+
env:
42+
MOCHA_REPORTER_SUITENAME: cloud_tasks_app
43+
MOCHA_REPORTER_OUTPUT: cloud_tasks_app_sponge_log.xml
44+
MOCHA_REPORTER: xunit
45+
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
46+
uses: actions/github-script@v5
47+
with:
48+
github-token: ${{ secrets.GITHUB_TOKEN }}
49+
script: |
50+
try {
51+
await github.rest.issues.removeLabel({
52+
name: 'actions:force-run',
53+
owner: 'GoogleCloudPlatform',
54+
repo: 'nodejs-docs-samples',
55+
issue_number: context.payload.pull_request.number
56+
});
57+
} catch (e) {
58+
if (!e.message.includes('Label does not exist')) {
59+
throw e;
60+
}
61+
}
62+
- if: ${{ github.event_name == 'schedule'}}
63+
run: |
64+
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
65+
chmod +x ./flakybot
66+
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: cloud-tasks-function
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- 'cloud-tasks/function/**'
8+
pull_request:
9+
paths:
10+
- 'cloud-tasks/function/**'
11+
pull_request_target:
12+
types: [labeled]
13+
schedule:
14+
- cron: '0 2 * * *'
15+
jobs:
16+
test:
17+
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: 'write'
21+
pull-requests: 'write'
22+
id-token: 'write'
23+
steps:
24+
- uses: 'google-github-actions/auth@v0.3.1'
25+
with:
26+
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
27+
service_account: 'kokoro-system-test@long-door-651.iam.gserviceaccount.com'
28+
create_credentials_file: 'true'
29+
access_token_lifetime: 600s
30+
- uses: actions/checkout@v2
31+
with:
32+
ref: ${{github.event.pull_request.head.ref}}
33+
repository: ${{github.event.pull_request.head.repo.full_name}}
34+
- uses: actions/setup-node@v2
35+
with:
36+
node-version: 14
37+
- run: npm install
38+
working-directory: cloud-tasks/function
39+
- run: npm test
40+
working-directory: cloud-tasks/function
41+
env:
42+
MOCHA_REPORTER_SUITENAME: cloud_tasks_function
43+
MOCHA_REPORTER_OUTPUT: cloud_tasks_function_sponge_log.xml
44+
MOCHA_REPORTER: xunit
45+
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
46+
uses: actions/github-script@v5
47+
with:
48+
github-token: ${{ secrets.GITHUB_TOKEN }}
49+
script: |
50+
try {
51+
await github.rest.issues.removeLabel({
52+
name: 'actions:force-run',
53+
owner: 'GoogleCloudPlatform',
54+
repo: 'nodejs-docs-samples',
55+
issue_number: context.payload.pull_request.number
56+
});
57+
} catch (e) {
58+
if (!e.message.includes('Label does not exist')) {
59+
throw e;
60+
}
61+
}
62+
- if: ${{ github.event_name == 'schedule'}}
63+
run: |
64+
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
65+
chmod +x ./flakybot
66+
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}

.github/workflows/workflows.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[
2+
"cloud-tasks/app",
3+
"cloud-tasks/function",
24
"composer",
35
"composer/functions/composer-storage-trigger",
46
"healthcare/datasets",

.kokoro/cloud-tasks/cloud-tasks-app.cfg

Lines changed: 0 additions & 7 deletions
This file was deleted.

.kokoro/cloud-tasks/cloud-tasks-func.cfg

Lines changed: 0 additions & 7 deletions
This file was deleted.

.kokoro/cloud-tasks/common.cfg

Lines changed: 0 additions & 29 deletions
This file was deleted.

cloud-tasks/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"scripts": {
1010
"start": "node index.js",
11-
"test": "mocha"
11+
"test": "mocha --timeout 10000"
1212
},
1313
"dependencies": {
1414
"@google-cloud/tasks": "^2.0.0",

cloud-tasks/app/test/create_task.test.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,24 @@
1616

1717
const createHttpTaskWithToken = require('../createTask');
1818
const {assert} = require('chai');
19+
const {CloudTasksClient} = require('@google-cloud/tasks');
1920

20-
const PROJECT_ID = process.env.GOOGLE_CLOUD_PROJECT;
2121
const QUEUE_ID = 'default';
2222
const LOCATION_ID = 'us-central1';
23-
const SERVICE_ACCOUNT =
24-
'test-invoker@nodejs-docs-samples-tests.iam.gserviceaccount.com'; // Service account for test project.
23+
const SERVICE_ACCOUNT = 'test-invoker@long-door-651.iam.gserviceaccount.com'; // Service account for test project.
2524
const URL = 'https://example.com/'; // Fake endpoint that returns status 200.
2625

2726
describe('Cloud Task Sample Tests', () => {
27+
let projectId;
28+
before(async () => {
29+
const client = new CloudTasksClient();
30+
projectId = await client.getProjectId();
31+
});
32+
2833
it('should create a task', async () => {
2934
const date = new Date();
3035
const response = await createHttpTaskWithToken(
31-
PROJECT_ID,
36+
projectId,
3237
QUEUE_ID,
3338
LOCATION_ID,
3439
URL,
@@ -37,7 +42,7 @@ describe('Cloud Task Sample Tests', () => {
3742
);
3843

3944
const regex_output = new RegExp(
40-
`projects/${PROJECT_ID}/locations/${LOCATION_ID}/queues/${QUEUE_ID}/tasks/`
45+
`projects/${projectId}/locations/${LOCATION_ID}/queues/${QUEUE_ID}/tasks/`
4146
);
4247
assert.match(response, regex_output);
4348
});

cloud-tasks/function/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"test": "mocha test/*.test.js --timeout=60000"
1111
},
1212
"dependencies": {
13+
"@google-cloud/secret-manager": "^3.10.1",
1314
"@sendgrid/mail": "^7.0.0"
1415
},
1516
"devDependencies": {

0 commit comments

Comments
 (0)