Skip to content

Commit 2925239

Browse files
authored
build: migrate auth to GH Actions (GoogleCloudPlatform#2543)
* build: migrate auth to GH Actions
1 parent 6642fcc commit 2925239

5 files changed

Lines changed: 78 additions & 36 deletions

File tree

.github/workflows/auth.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: auth
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- 'auth/**'
8+
pull_request:
9+
paths:
10+
- 'auth/**'
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+
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
30+
access_token_lifetime: 600s
31+
- uses: actions/checkout@v2
32+
with:
33+
ref: ${{github.event.pull_request.head.ref}}
34+
repository: ${{github.event.pull_request.head.repo.full_name}}
35+
- uses: actions/setup-node@v2
36+
with:
37+
node-version: 14
38+
- run: npm install
39+
working-directory: auth
40+
- run: npm test
41+
working-directory: auth
42+
env:
43+
MOCHA_REPORTER_SUITENAME: auth
44+
MOCHA_REPORTER_OUTPUT: auth_sponge_log.xml
45+
MOCHA_REPORTER: xunit
46+
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
47+
uses: actions/github-script@v5
48+
with:
49+
github-token: ${{ secrets.GITHUB_TOKEN }}
50+
script: |
51+
try {
52+
await github.rest.issues.removeLabel({
53+
name: 'actions:force-run',
54+
owner: 'GoogleCloudPlatform',
55+
repo: 'nodejs-docs-samples',
56+
issue_number: context.payload.pull_request.number
57+
});
58+
} catch (e) {
59+
if (!e.message.includes('Label does not exist')) {
60+
throw e;
61+
}
62+
}
63+
- if: ${{ github.event_name == 'schedule'}}
64+
run: |
65+
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
66+
chmod +x ./flakybot
67+
./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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"appengine/static-files",
1414
"appengine/storage/flexible",
1515
"appengine/storage/standard",
16+
"auth",
1617
"appengine/typescript",
1718
"appengine/websockets",
1819
"appengine/twilio",
@@ -40,6 +41,5 @@
4041
"monitoring/prometheus",
4142
"datacatalog/cloud-client",
4243
"datacatalog/quickstart",
43-
"datastore/functions",
44-
"run/jobs"
44+
"datastore/functions"
4545
]

.kokoro/auth.cfg

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

auth/system-test/auth.test.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,24 @@
1414

1515
'use strict';
1616

17-
const path = require('path');
1817
const assert = require('assert');
18+
const path = require('path');
1919
const {execSync} = require('child_process');
2020

2121
const cwd = path.join(__dirname, '..');
2222
const cmd = 'node auth.js';
2323

24-
const {BUCKET_NAME} = process.env;
25-
26-
before(() => {
27-
assert(
28-
process.env.GOOGLE_CLOUD_PROJECT,
29-
'Must set GOOGLE_CLOUD_PROJECT environment variable!'
30-
);
31-
assert(
32-
process.env.GOOGLE_APPLICATION_CREDENTIALS,
33-
'Must set GOOGLE_APPLICATION_CREDENTIALS environment variable!'
34-
);
35-
assert(process.env.BUCKET_NAME, 'Must set BUCKET_NAME environment variable!');
36-
});
24+
const BUCKET_NAME = 'long-door-651';
25+
const GOOGLE_CLOUD_PROJECT = 'long-door-651';
26+
process.env.GOOGLE_CLOUD_PROJECT = 'long-door-651';
3727

3828
it('should load credentials implicitly', () => {
3929
const output = execSync(`${cmd} auth-cloud-implicit`, {cwd, shell: true});
4030
assert.strictEqual(output.includes(BUCKET_NAME), true);
4131
});
4232

4333
it('should load credentials explicitly', () => {
44-
const project = process.env.GOOGLE_CLOUD_PROJECT;
34+
const project = GOOGLE_CLOUD_PROJECT;
4535
const keyfile = process.env.GOOGLE_APPLICATION_CREDENTIALS;
4636
console.log(`${cmd} auth-cloud-explicit -p ${project} -k ${keyfile}`);
4737
const output = execSync(

auth/system-test/downscoping.test.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@ const {Storage} = require('@google-cloud/storage');
2222

2323
const cwd = path.join(__dirname, '..');
2424
const cmd = 'node downscoping.js';
25+
process.env.GOOGLE_CLOUD_PROJECT = 'long-door-651';
2526

2627
const CONTENTS = 'helloworld';
2728
let bucket;
2829
let file;
2930
let bucketName;
3031
let objectName;
3132

32-
before(async () => {
33-
assert(
34-
process.env.GOOGLE_CLOUD_PROJECT,
35-
'Must set GOOGLE_CLOUD_PROJECT environment variable!'
36-
);
33+
const GOOGLE_CLOUD_PROJECT = 'long-door-651';
3734

38-
const storage = new Storage({projectId: process.env.GOOGLE_CLOUD_PROJECT});
35+
before(async () => {
36+
const storage = new Storage({projectId: GOOGLE_CLOUD_PROJECT});
3937
bucketName = 'bucket-downscoping-test-' + uuidv4();
4038
objectName = 'object-downscoping-test-' + uuidv4();
4139

0 commit comments

Comments
 (0)