Skip to content

Commit 0cf8d3f

Browse files
authored
ci: add coverage to ci test command (#1453)
* ci: add coverage to ci test command * feat(ci): load env with github action, run test:ci script * fix: add ci as valid dd_env in convict used in ci * feat: use dotenv cli instead of sourcing .env.test
1 parent 8509ddd commit 0cf8d3f

File tree

5 files changed

+91
-59
lines changed

5 files changed

+91
-59
lines changed

.env.test

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
1-
export CLIENT_ID="i am a client"
2-
export CLIENT_SECRET="i am a secret"
3-
export REDIRECT_URI="http://localhost:8081/v1/auth"
4-
export NODE_ENV="test"
5-
export COOKIE_DOMAIN="localhost"
6-
export AUTH_TOKEN_EXPIRY_DURATION_IN_MILLISECONDS=800000000
7-
export JWT_SECRET="blah"
8-
export ENCRYPTION_SECRET="blah"
9-
export FRONTEND_URL="http://localhost:3000"
10-
export GITHUB_ORG_NAME="isomerpages"
11-
export GITHUB_BUILD_ORG_NAME="opengovsg"
12-
export GITHUB_BUILD_REPO_NAME="isomer-build"
13-
export MUTEX_TABLE_NAME="mutex-table"
14-
export MAX_NUM_OTP_ATTEMPTS=5
15-
export OTP_EXPIRY=900000
16-
export SESSION_SECRET=blahblah
1+
CLIENT_ID="i am a client"
2+
CLIENT_SECRET="i am a secret"
3+
REDIRECT_URI="http://localhost:8081/v1/auth"
4+
NODE_ENV="test"
5+
COOKIE_DOMAIN="localhost"
6+
AUTH_TOKEN_EXPIRY_DURATION_IN_MILLISECONDS=800000000
7+
JWT_SECRET="blah"
8+
ENCRYPTION_SECRET="blah"
9+
FRONTEND_URL="http://localhost:3000"
10+
GITHUB_ORG_NAME="isomerpages"
11+
GITHUB_BUILD_ORG_NAME="opengovsg"
12+
GITHUB_BUILD_REPO_NAME="isomer-build"
13+
MUTEX_TABLE_NAME="mutex-table"
14+
MAX_NUM_OTP_ATTEMPTS=5
15+
OTP_EXPIRY=900000
16+
SESSION_SECRET=blahblah
1717

1818
# GitHub access token to create repo
19-
export SYSTEM_GITHUB_TOKEN="github_token"
19+
SYSTEM_GITHUB_TOKEN="github_token"
2020

2121
# FormSG keys
22-
export SITE_CREATE_FORM_KEY="site_form_key"
23-
export SITE_LAUNCH_FORM_KEY="site_launch_form_key"
24-
export GGS_REPAIR_FORM_KEY="ggs_repair_form_key"
25-
export SITE_CHECKER_FORM_KEY="site_checker_form_key"
26-
export SITE_AUDIT_LOGS_FORM_KEY="site_audit_logs_form_key"
27-
export NOTIFY_SITE_COLLABORATORS_FORM_KEY="notify_site_collaborators_form_key"
22+
SITE_CREATE_FORM_KEY="site_form_key"
23+
SITE_LAUNCH_FORM_KEY="site_launch_form_key"
24+
GGS_REPAIR_FORM_KEY="ggs_repair_form_key"
25+
SITE_CHECKER_FORM_KEY="site_checker_form_key"
26+
SITE_AUDIT_LOGS_FORM_KEY="site_audit_logs_form_key"
27+
NOTIFY_SITE_COLLABORATORS_FORM_KEY="notify_site_collaborators_form_key"
2828

2929
# Required to connect to DynamoDB
30-
export AWS_ACCESS_KEY_ID="abc123"
31-
export AWS_SECRET_ACCESS_KEY="xyz123"
30+
AWS_ACCESS_KEY_ID="abc123"
31+
AWS_SECRET_ACCESS_KEY="xyz123"
3232

3333
# Required to run end-to-end tests
34-
export E2E_TEST_REPO="e2e-test-repo"
35-
export E2E_TEST_SECRET="test"
36-
export E2E_TEST_GH_TOKEN="test"
34+
E2E_TEST_REPO="e2e-test-repo"
35+
E2E_TEST_SECRET="test"
36+
E2E_TEST_GH_TOKEN="test"
3737

3838
# Database
39-
export DB_URI="postgres://isomer:[email protected]:54321/isomercms_test"
40-
export DB_MIN_POOL="1"
41-
export DB_MAX_POOL="10"
42-
export DB_ENABLE_LOGGING="true"
39+
DB_URI="postgres://isomer:[email protected]:54321/isomercms_test"
40+
DB_MIN_POOL="1"
41+
DB_MAX_POOL="10"
42+
DB_ENABLE_LOGGING="true"
4343

44-
export LOCAL_SITE_ACCESS_TOKEN="dummy"
45-
export OTP_SECRET="dummysecret"
44+
LOCAL_SITE_ACCESS_TOKEN="dummy"
45+
OTP_SECRET="dummysecret"
4646

4747
# Email
48-
export POSTMAN_API_KEY="some api key"
48+
POSTMAN_API_KEY="some api key"
4949

5050
# SMS
51-
export POSTMAN_SMS_CRED_NAME="isomer"
51+
POSTMAN_SMS_CRED_NAME="isomer"
5252

5353
# Amplify
54-
export AWS_REGION="ap-southeast-1"
55-
export AWS_ACCOUNT_NUMBER="random"
54+
AWS_REGION="ap-southeast-1"
55+
AWS_ACCOUNT_NUMBER="random"
5656

5757
# DataDog
58-
export DD_ENV="local"
59-
export DD_SERVICE="isomer"
60-
export DD_TAGS="service:isomer"
58+
DD_ENV="ci"
59+
DD_SERVICE="isomer"
60+
DD_TAGS="service:isomer"
6161

6262
# Cloudmersive
63-
export CLOUDMERSIVE_API_KEY="cloudmersive"
63+
CLOUDMERSIVE_API_KEY="cloudmersive"
6464

6565
# GitGuardian
66-
export GITGUARDIAN_API_KEY="gitguardian"
66+
GITGUARDIAN_API_KEY="gitguardian"
6767

6868
# SQS Queue
69-
export INCOMING_QUEUE_URL="incoming"
70-
export OUTGOING_QUEUE_URL="outgoing"
71-
export SITE_LAUNCH_QUEUE_URL="site_launch"
69+
INCOMING_QUEUE_URL="incoming"
70+
OUTGOING_QUEUE_URL="outgoing"
71+
SITE_LAUNCH_QUEUE_URL="site_launch"
7272

7373
# DynamoDB
74-
export SITE_LAUNCH_DYNAMO_DB_TABLE_NAME="ddb-name"
75-
export STEP_FUNCTIONS_ARN="arn:aws:some-arn"
76-
export SITE_PASSWORD_SECRET_KEY="1234567812345678123456781234567812345678123456781234567812345678"
74+
SITE_LAUNCH_DYNAMO_DB_TABLE_NAME="ddb-name"
75+
STEP_FUNCTIONS_ARN="arn:aws:some-arn"
76+
SITE_PASSWORD_SECRET_KEY="1234567812345678123456781234567812345678123456781234567812345678"
7777

78-
export NETLIFY_ACCESS_TOKEN="blahblah"
78+
NETLIFY_ACCESS_TOKEN="blahblah"
7979

8080
# sgID
81-
export SGID_CLIENT_ID="client"
82-
export SGID_CLIENT_SECRET="secret"
83-
export SGID_PRIVATE_KEY="private"
84-
export SGID_REDIRECT_URI="http://localhost:8081/v2/auth/sgid/auth-redirect"
81+
SGID_CLIENT_ID="client"
82+
SGID_CLIENT_SECRET="secret"
83+
SGID_PRIVATE_KEY="private"
84+
SGID_REDIRECT_URI="http://localhost:8081/v2/auth/sgid/auth-redirect"
8585

8686
# GrowthBook
87-
export GROWTHBOOK_CLIENT_KEY="some random key"
87+
GROWTHBOOK_CLIENT_KEY="some random key"
8888

89-
export KEYCDN_API_KEY="secret"
89+
KEYCDN_API_KEY="secret"
9090

91-
export REDIS_HOST="redis"
91+
REDIS_HOST="redis"

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ jobs:
8787
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
8888
- run: npm ci
8989
- run: npm run test:docker
90+
- name: Load .env file
91+
uses: xom9ikk/dotenv@v2
92+
with:
93+
mode: test
9094
# Not using Datadog Test Visibility action since we need to use the local
9195
# (patched) package for it to work with neverthrow
9296
- name: run tests
@@ -99,7 +103,7 @@ jobs:
99103
DD_SERVICE: isomer
100104
DD_API_KEY: ${{ secrets.DD_API_KEY }}
101105
DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER: github
102-
run: . .env.test && npx jest --runInBand
106+
run: npm run test:ci
103107

104108
gatekeep:
105109
name: Determine if Build & Deploy is needed

package-lock.json

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"start:support:prod": "node --unhandled-rejections=warn -r ts-node/register/transpile-only -r tsconfig-paths/register support/index.ts",
1414
"dev": "source .env && docker compose -f docker-compose.dev.yml up",
1515
"test:docker": "docker run -d -p 54321:5432 --name postgres -e POSTGRES_USER=isomer -e POSTGRES_PASSWORD=password -e POSTGRES_DB=isomercms_test postgres:latest",
16-
"test": "source .env.test && jest --runInBand",
16+
"test": "dotenv -e .env.test jest --runInBand",
17+
"test:ci": "jest --runInBand --coverage",
1718
"release": "bash scripts/release_prep.sh",
1819
"lint": "npx eslint .",
1920
"lint-fix": "eslint --ignore-path .gitignore . --fix",
@@ -62,6 +63,7 @@
6263
"debug": "~2.6.9",
6364
"dompurify": "^3.1.3",
6465
"dotenv": "^16.4.5",
66+
"dotenv-cli": "^7.4.2",
6567
"eventsource": "^2.0.2",
6668
"exponential-backoff": "^3.1.0",
6769
"express": "~4.19.2",

src/config/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ const config = convict({
275275
"prod",
276276
"stg",
277277
"dev",
278+
"ci",
278279
],
279280
env: "DD_ENV",
280281
default: "local",

0 commit comments

Comments
 (0)