Skip to content
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

ci(idp-sql): run idp-sql tests in testing isolation #3985

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
3 changes: 1 addition & 2 deletions .github/config/nodejs-prod.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
".kokoro/",
".prettierignore",
".prettierrc.js",
"cloud-samples-tools", // checked out by GH action in ci-*.yml
"cloud-samples-tools", // checked out by GH action in ci-*.yml
"CODEOWNERS",
"CODE_OF_CONDUCT.md",
"CONTRIBUTING.md",
Expand Down Expand Up @@ -94,7 +94,6 @@
"healthcare/fhir", // Error: Cannot find module 'whatwg-url'
"iam/deny", // PERMISSION_DENIED: Permission iam.googleapis.com/denypolicies.create denied on resource cloudresourcemanager.googleapis.com/projects/long-door-651
"recaptcha_enterprise/snippets", // Cannot use import statement outside a module
"run/idp-sql", // Error: Invalid contents in the credentials file
"run/markdown-preview/editor", // Error: could not create an identity token: Cannot fetch ID token in this environment, use GCE or set the GOOGLE_APPLICATION_CREDENTIALS environment variable to a service account credentials JSON file
"run/system-package", // Error: ENOENT: no such file or directory, access '/usr/bin/dot'
"scheduler", // SyntaxError: Cannot use import statement outside a module
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ci-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
path: ${{ fromJson(github.event_name == 'pull_request' && needs.affected.outputs.nodejs-paths || '[]') }}
env:
GOOGLE_SAMPLES_PROJECT: long-door-651
GOOGLE_SERVICE_ACCOUNT: [email protected]
CI_SETUP: ${{ toJson(fromJson(needs.affected.outputs.nodejs-setups)[matrix.path])}}
steps:
- name: CI Setup
Expand All @@ -99,7 +100,7 @@ jobs:
with:
project_id: ${{ env.GOOGLE_SAMPLES_PROJECT }}
workload_identity_provider: projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider
service_account: [email protected]
service_account: ${{ env.GOOGLE_SERVICE_ACCOUNT }}
access_token_lifetime: 600s # 10 minutes
- name: Export environment variables
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
Expand Down
2 changes: 1 addition & 1 deletion run/idp-sql/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const {authenticateJWT, requestLogger} = require('./middleware');
const app = express();
app.use(express.static(__dirname + '/static'));

// Automatically parse request body as form data.
// Automatically parse request body as form data
app.use(express.urlencoded({extended: false}));
app.use(express.json());

Expand Down
12 changes: 12 additions & 0 deletions run/idp-sql/ci-setup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"env": {
"SERVICE_NAME": "idp-sql-${RUN_ID}",
"CLOUD_SQL_CONNECTION_NAME": "nodejs-docs-samples-tests:us-central1:postgres-ci",
"DB_NAME": "kokoro_ci",
"DB_USER": "kokoro_ci"
},
"secrets": {
"IDP_KEY": "nodejs-docs-samples-tests/nodejs-docs-samples-idp-key",
"DB_PASSWORD": "nodejs-docs-samples-tests/nodejs-docs-samples-sql-password"
}
}
8 changes: 5 additions & 3 deletions run/idp-sql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
},
"scripts": {
"start": "node index.js",
"test": "c8 mocha -p -j 2 test/app.test.js --timeout=120000 --exit",
"system-test": "c8 mocha -p -j 2 test/system.test.js --timeout=1800000 --exit"
"unit-test": "c8 mocha -p -j 2 test/app.test.js --timeout=120000 --exit",
"system-test": "c8 mocha -p -j 2 test/system.test.js --timeout=1800000 --exit",
"all-test": "npm run unit-test && npm run system-test",
"test": "npm -- run all-test"
},
"dependencies": {
"express": "^4.16.2",
"firebase-admin": "^12.0.0",
"firebase-admin": "^13.0.0",
"gcp-metadata": "^6.0.0",
"google-auth-library": "^9.0.0",
"handlebars": "^4.7.6",
Expand Down
6 changes: 6 additions & 0 deletions run/idp-sql/test/e2e_test_cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ substitutions:
_VERSION: manual
_REGION: us-central1
_PLATFORM: managed
_SERVICE_ACCOUNT: ${PROJECT_NUMBER}@cloudbuild.gserviceaccount.com

serviceAccount: 'projects/${PROJECT_ID}/serviceAccounts/${_SERVICE_ACCOUNT}'
options:
logging: CLOUD_LOGGING_ONLY
dynamicSubstitutions: true
6 changes: 6 additions & 0 deletions run/idp-sql/test/e2e_test_setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ substitutions:
_DB_NAME: postgres
_DB_USER: postgres
_DB_PASSWORD: password1234
_SERVICE_ACCOUNT: ${PROJECT_NUMBER}@cloudbuild.gserviceaccount.com

serviceAccount: 'projects/${PROJECT_ID}/serviceAccounts/${_SERVICE_ACCOUNT}'
options:
logging: CLOUD_LOGGING_ONLY
dynamicSubstitutions: true
2 changes: 1 addition & 1 deletion run/idp-sql/test/retry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ do
if ((attempt_num==max_attempts))
then
echo "Attempt $attempt_num / $max_attempts failed! No more retries left!"
exit
exit 1
else
echo "Attempt $attempt_num / $max_attempts failed!"
sleep $((attempt_num++))
Expand Down
3 changes: 3 additions & 0 deletions run/idp-sql/test/system.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
console.log('"SERVICE_NAME" env var not found. Defaulting to "idp-sql"');
SERVICE_NAME = 'idp-sql';
}

const {GOOGLE_SERVICE_ACCOUNT} = process.env;
const {SAMPLE_VERSION} = process.env;
const PLATFORM = 'managed';
const REGION = 'us-central1';
Expand Down Expand Up @@ -60,6 +62,7 @@
'--config ./test/e2e_test_setup.yaml ' +
`--substitutions _SERVICE=${SERVICE_NAME},_PLATFORM=${PLATFORM},_REGION=${REGION}` +
`,_DB_PASSWORD=${DB_PASSWORD},_CLOUD_SQL_CONNECTION_NAME=${CLOUD_SQL_CONNECTION_NAME}`;
if (GOOGLE_SERVICE_ACCOUNT) buildCmd += `,_SERVICE_ACCOUNT=${GOOGLE_SERVICE_ACCOUNT}`;

Check failure on line 65 in run/idp-sql/test/system.test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎·····`
if (SAMPLE_VERSION) buildCmd += `,_VERSION=${SAMPLE_VERSION}`;

console.log('Starting Cloud Build...');
Expand Down
Loading