Skip to content

Commit a2edfd1

Browse files
build: experiment with GitHub Actions for healthcare/datasets (#2365)
1 parent c2059b7 commit a2edfd1

File tree

4 files changed

+93
-21
lines changed

4 files changed

+93
-21
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: healthcare-datasets
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- 'healthcare/datasets/**'
8+
pull_request:
9+
schedule:
10+
- cron: '0 2 * * *'
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: 'read'
16+
id-token: 'write'
17+
steps:
18+
- uses: 'google-github-actions/[email protected]'
19+
with:
20+
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
21+
service_account: '[email protected]'
22+
create_credentials_file: 'true'
23+
access_token_lifetime: 600s
24+
- uses: actions/checkout@v2
25+
- uses: actions/setup-node@v2
26+
with:
27+
node-version: 14
28+
- run: npm install
29+
working-directory: healthcare/datasets
30+
- run: npm test
31+
working-directory: healthcare/datasets

buildsetup.sh

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#! /bin/bash
2+
3+
# This script will configure a given GCP project to use
4+
# Workload Identity Federation. To learn more, see:
5+
# https://github.com/google-github-actions/auth
6+
7+
export PROJECT_ID="long-door-651"
8+
export POOL_NAME="github-actions-pool"
9+
export PROVIDER_NAME="github-actions-provider"
10+
export SERVICE_ACCOUNT="[email protected]"
11+
export GITHUB_REPO="GoogleCloudPlatform/nodejs-docs-samples"
12+
13+
# Enable the IAM Credentials API
14+
gcloud services enable iamcredentials.googleapis.com --project "${PROJECT_ID}"
15+
16+
# Create a workload identity pool
17+
gcloud iam workload-identity-pools create "${POOL_NAME}" \
18+
--project="${PROJECT_ID}" \
19+
--location="global" \
20+
--display-name="GitHub Actions Pool"
21+
22+
# Get the full ID of the Workload Identity Pool
23+
gcloud iam workload-identity-pools describe "${POOL_NAME}" \
24+
--project="${PROJECT_ID}" \
25+
--location="global" \
26+
--format="value(name)"
27+
28+
export WORKLOAD_IDENTITY_POOL_ID="$(!!)"
29+
30+
# Create a Workload Identity Provider in that pool
31+
gcloud iam workload-identity-pools providers create-oidc "${PROVIDER_NAME}" \
32+
--project="${PROJECT_ID}" \
33+
--location="global" \
34+
--workload-identity-pool="${POOL_NAME}" \
35+
--display-name="GitHub Actions Provider" \
36+
--attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.aud=assertion.aud" \
37+
--issuer-uri="https://token.actions.githubusercontent.com"
38+
39+
# Allow authentications from the Workload Identity Provider to impersonate the Service Account.
40+
# Note executions are limited to requests from this specific repository.
41+
gcloud iam service-accounts add-iam-policy-binding "${SERVICE_ACCOUNT}" \
42+
--role="roles/iam.workloadIdentityUser" \
43+
--member="principalSet://iam.googleapis.com/${WORKLOAD_IDENTITY_POOL_ID}/attribute.repository/${GITHUB_REPO}"

healthcare/datasets/createDataset.js

+5
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@ const main = (
4444
// [END healthcare_create_dataset]
4545
};
4646

47+
process.on('unhandledRejection', err => {
48+
console.error(err.message);
49+
process.exitCode = 1;
50+
});
51+
4752
// node createDataset.js <projectId> <cloudRegion> <datasetId>
4853
main(...process.argv.slice(2));

healthcare/datasets/system-test/datasets.test.js

+14-21
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,27 @@
1717
const assert = require('assert');
1818
const uuid = require('uuid');
1919
const {execSync} = require('child_process');
20+
const healthcare = require('@googleapis/healthcare');
2021

21-
const projectId = process.env.GOOGLE_CLOUD_PROJECT;
2222
const datasetId = `dataset-${uuid.v4()}`.replace(/-/gi, '_');
2323
const destinationDatasetId = `destination-${uuid.v4()}`.replace(/-/gi, '_');
2424
const keeplistTags = 'PatientID';
2525
const cloudRegion = 'us-central1';
26-
27-
before(() => {
28-
assert(
29-
process.env.GOOGLE_CLOUD_PROJECT,
30-
'Must set GOOGLE_CLOUD_PROJECT environment variable!'
31-
);
32-
assert(
33-
process.env.GOOGLE_APPLICATION_CREDENTIALS,
34-
'Must set GOOGLE_APPLICATION_CREDENTIALS environment variable!'
35-
);
36-
});
37-
after(() => {
38-
try {
39-
execSync(
40-
`node deleteDataset.js ${projectId} ${cloudRegion} ${destinationDatasetId}`
41-
);
42-
} catch (err) {
43-
// Ignore error
44-
}
45-
});
26+
let projectId;
4627

4728
describe('run datasets tests with 5 retries', function () {
29+
before(async () => {
30+
projectId = await healthcare.auth.getProjectId();
31+
});
32+
after(() => {
33+
try {
34+
execSync(
35+
`node deleteDataset.js ${projectId} ${cloudRegion} ${destinationDatasetId}`
36+
);
37+
} catch (err) {
38+
// Ignore error
39+
}
40+
});
4841
// Retry every test in this suite 5 times.
4942
this.retries(5);
5043
it('should create a dataset', () => {

0 commit comments

Comments
 (0)