From da77ee93f0975674bfff6f48e9e53003a7751fae Mon Sep 17 00:00:00 2001 From: Fred Marecesche Date: Thu, 17 Oct 2024 16:57:23 +0100 Subject: [PATCH 1/9] Move PR tests to GitHub Actions --- .circleci/config.yml | 120 +-------------------------------------- .github/workflows/ci.yml | 113 ++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 118 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index 813e297da..9f0afa58c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,15 +17,6 @@ parameters: type: string default: 20.18-browsers -executors: - integration-tests: - docker: - - image: cimg/node:<< pipeline.parameters.node-version >> - - image: cimg/redis:7.0 - command: redis-server --port 6380 - resource_class: medium+ - working_directory: ~/app - jobs: build: executor: @@ -49,16 +40,6 @@ jobs: - run: command: | npm run build - - run: - # Run linter after build because the integration test code depend on compiled typescript... - name: Linter check - command: npm run lint - - run: - name: Type check - command: npm run typecheck - - run: - name: Shell scripts check - command: npm run shellcheck - persist_to_workspace: root: . paths: @@ -67,96 +48,6 @@ jobs: - dist - .cache/Cypress - unit_test: - parallelism: 4 - executor: - name: hmpps/node - tag: << pipeline.parameters.node-version >> - steps: - - checkout - - attach_workspace: - at: ~/app - - restore_cache: - key: dependency-cache-{{ checksum "package-lock.json" }} - - run: - name: Run unit tests - command: | - TESTS=$(circleci tests glob "server/**/*.test.ts" | circleci tests split --split-by=timings) - npm run test:ci $TESTS - - run: - name: collect coverage data - command: | - mv ./coverage/coverage-final.json ./coverage/coverage_${CIRCLE_NODE_INDEX}.json - - store_test_results: - path: test_results/jest - - store_artifacts: - path: test_results/unit-test-reports.html - - persist_to_workspace: - root: . - paths: - - coverage - - coverage: - executor: - name: hmpps/node - tag: << pipeline.parameters.node-version >> - steps: - - checkout - - attach_workspace: - at: ~/app - - run: - name: Merge coverage reports - command: npx nyc merge ./coverage/ ./coverage/.nyc_output - - run: - name: Check Coverage - command: | - npx nyc report -t ./coverage --reporter=text --reporter=text-summary - npx nyc check-coverage -t ./coverage - - integration_test: - parallelism: 4 - executor: - name: integration-tests - steps: - - checkout - - attach_workspace: - at: ~/app - - run: - name: Install missing OS dependency - command: sudo apt-get install libxss1 - - restore_cache: - key: dependency-cache-{{ checksum "package-lock.json" }} - - run: - name: Get wiremock - command: curl -o wiremock.jar - https://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-standalone/2.27.1/wiremock-standalone-2.27.1.jar - - run: - name: Run wiremock - command: java -jar wiremock.jar --port 9999 - background: true - - run: - name: Run the node app. - command: npm run compile-sass && npm run start-feature - background: true - - run: - name: Wait for node app to start - command: | - until curl http://localhost:3007/health > /dev/null 2>&1; do - printf '.' - sleep 1 - done - - run: - name: integration tests - command: | - TESTS=$(circleci tests glob "integration_tests/tests/**/*.cy.ts" | circleci tests split --split-by=timings | paste -sd ',') - npm run int-test -- --spec $TESTS - - store_test_results: - path: test_results/cypress - - store_artifacts: - path: integration_tests/videos - - store_artifacts: - path: integration_tests/screenshots - e2e_environment_test_on_merge: executor: name: hmpps/node @@ -195,19 +86,11 @@ jobs: event: fail channel: << pipeline.parameters.alerts-slack-channel >> template: basic_fail_1 + workflows: build-test-and-deploy: jobs: - build - - unit_test: - requires: - - build - - integration_test: - requires: - - build - - coverage: - requires: - - unit_test - hmpps/helm_lint: name: helm_lint - hmpps/build_docker: @@ -317,6 +200,7 @@ workflows: context: - veracode-credentials - hmpps-common-vars + security-weekly: triggers: - schedule: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..6885d702f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,113 @@ +name: CI + +on: + pull_request: + +env: + NODE_ENV: test + API_CLIENT_ID: approved-premises + API_CLIENT_SECRET: clientsecret + +jobs: + type_checking: + name: "Type check ๐Ÿ”Ž" + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4.1.7 + + - name: Setup Node.js environment + uses: actions/setup-node@v4.0.3 + with: + node-version-file: '.node-version' + cache: 'npm' + + - name: Installing dependencies + run: npm ci + + - name: Pulling the latest type from the API repo + run: npm run generate-types + + - name: Typechecking the code + run: npm run typecheck + + linting: + name: "Linting ๐Ÿ”Ž" + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4.1.7 + + - name: Setup Node.js environment + uses: actions/setup-node@v4.0.3 + with: + node-version-file: '.node-version' + cache: 'npm' + + - name: Installing dependencies + run: npm ci + + - name: Running Lint checks + run: npm run lint + + - name: Running shell scripts linting checks + run: npm run shellcheck + + unit_test: + name: "Unit testing ๐Ÿงช" + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4.1.7 + + - name: Setup Node.js environment + uses: actions/setup-node@v4.0.3 + with: + node-version-file: '.node-version' + cache: 'npm' + + - name: Installing dependencies + run: npm ci + + - name: Running Unit tests + run: npm run test:ci + + - name: Check coverage + run: | + npx nyc report -t ./coverage --reporter=text --reporter=text-summary + npx nyc check-coverage -t ./coverage + + # TODO: Split into parallel runs + integration_test: + name: "Integration testing ๐Ÿงช" + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4.1.7 + + - name: Setup Node.js environment + uses: actions/setup-node@v4.0.3 + with: + node-version-file: '.node-version' + cache: 'npm' + + - name: Installing dependencies + run: npm ci + + - name: Building source + run: npm run build + + - name: Running Integration tests + run: npm run test:integration + + - name: Store Integration tests results + uses: actions/upload-artifact@v4 + with: + name: integration-tests-results + path: test_results/integration + + - name: Store Integration tests screenshots + uses: actions/upload-artifact@v4 + with: + name: integration-tests-screenshots + path: test_results/integration/screenshots From 006d176b0920938a6b5a62b7561cfb3113bf43ae Mon Sep 17 00:00:00 2001 From: Fred Marecesche Date: Wed, 23 Oct 2024 17:13:34 +0100 Subject: [PATCH 2/9] Split integration tests into 4 parallel runs --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++++++++++------ package.json | 2 +- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6885d702f..d2b6351e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,10 +77,17 @@ jobs: npx nyc report -t ./coverage --reporter=text --reporter=text-summary npx nyc check-coverage -t ./coverage - # TODO: Split into parallel runs integration_test: name: "Integration testing ๐Ÿงช" runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ci_node_index: + - 0 + - 1 + - 2 + - 3 steps: - name: Check out code uses: actions/checkout@v4.1.7 @@ -97,17 +104,37 @@ jobs: - name: Building source run: npm run build + - uses: actions/download-artifact@v4 + with: + name: junit-xml-reports + path: tmp/integration-tests-reports + continue-on-error: true + + - uses: r7kamura/split-tests-by-timings@v0 + id: split-tests + with: + reports: tmp/integration-tests-reports + glob: integration_tests/tests/**/*.cy.ts + index: ${{ matrix.ci_node_index }} + total: 4 + - name: Running Integration tests - run: npm run test:integration + run: TEST_RUN_ARGS="--spec $(echo ${{ steps.split-tests.outputs.paths }} | sed -E 's/ /,/g')" npm run test:integration + + - name: Store Integration tests reports + uses: actions/upload-artifact@v4 + with: + name: integration-tests-reports + path: test_results/cypress - - name: Store Integration tests results + - name: Store Integration tests videos uses: actions/upload-artifact@v4 with: - name: integration-tests-results - path: test_results/integration + name: integration-tests-videos + path: integration_tests/videos - name: Store Integration tests screenshots uses: actions/upload-artifact@v4 with: name: integration-tests-screenshots - path: test_results/integration/screenshots + path: integration_tests/screenshots diff --git a/package.json b/package.json index 53777b0e2..da10ecff3 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "test:e2e:local-dev-upstream:ui": "npm run test:e2e:local-dev-upstream -- --ui", "install-playwright": "npx playwright install", "security_audit": "npx audit-ci --config audit-ci.json", - "int-test": "cypress run --config video=false", + "int-test": "cypress run --config video=false $TEST_RUN_ARGS", "int-test-ui": "cypress open --e2e --browser electron", "clean": "rm -rf dist build node_modules stylesheets", "start-test-wiremock": "docker compose -f docker-compose-test.yml up -d", From bf7e7228fa34726bc1f03d2538d6e254fa57a22f Mon Sep 17 00:00:00 2001 From: Fred Marecesche Date: Thu, 24 Oct 2024 10:06:59 +0100 Subject: [PATCH 3/9] Use test env to reduce log output --- feature.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feature.env b/feature.env index c53eb0a6b..a4f5fbd34 100644 --- a/feature.env +++ b/feature.env @@ -2,7 +2,7 @@ PORT=3007 HMPPS_AUTH_URL=http://localhost:9999/auth TOKEN_VERIFICATION_API_URL=http://localhost:9999/verification TOKEN_VERIFICATION_ENABLED=true -NODE_ENV=development +NODE_ENV=test API_CLIENT_ID=clientid API_CLIENT_SECRET=clientsecret REDIS_PORT=6380 From 1ba638a75e3da977bf36c49ae2c318f193ea4bb6 Mon Sep 17 00:00:00 2001 From: Fred Marecesche Date: Tue, 14 Jan 2025 16:44:18 +0000 Subject: [PATCH 4/9] Index test output artifacts --- .github/workflows/ci.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2b6351e2..4b09606ab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -106,8 +106,9 @@ jobs: - uses: actions/download-artifact@v4 with: - name: junit-xml-reports - path: tmp/integration-tests-reports + pattern: integration-test-junit-xml-reports-* + path: test_results/cypress + merge-multiple: true continue-on-error: true - uses: r7kamura/split-tests-by-timings@v0 @@ -124,17 +125,17 @@ jobs: - name: Store Integration tests reports uses: actions/upload-artifact@v4 with: - name: integration-tests-reports + name: integration-test-junit-xml-reports-${{ matrix.ci_node_index }} path: test_results/cypress - name: Store Integration tests videos uses: actions/upload-artifact@v4 with: - name: integration-tests-videos + name: integration-tests-videos-${{ matrix.ci_node_index }} path: integration_tests/videos - name: Store Integration tests screenshots uses: actions/upload-artifact@v4 with: - name: integration-tests-screenshots + name: integration-tests-screenshots-${{ matrix.ci_node_index }} path: integration_tests/screenshots From 46c5020a18f3e3a1d6abe4302dd052613790792d Mon Sep 17 00:00:00 2001 From: Fred Marecesche Date: Tue, 14 Jan 2025 17:22:11 +0000 Subject: [PATCH 5/9] Fix shellcheck command? --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index da10ecff3..10a546061 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "watch-node-feature": "export $(cat feature.env) && nodemon --watch dist/ $NODE_DEBUG_OPTION dist/server.js | bunyan -o short", "start-feature:dev": "concurrently -k -p \"[{name}]\" -n \"Views,TypeScript,Node,Sass\" -c \"yellow.bold,cyan.bold,green.bold,blue.bold\" \"npm run watch-views\" \"npm run watch-ts\" \"npm run watch-node-feature\" \"npm run watch-sass\"", "record-build-info": "node ./bin/record-build-info", - "shellcheck": "npx shellcheck ./script/*[^utils][^data] ./script/utils/**", + "shellcheck": "npx shellcheck ./script/*[^utils][^data] ./script/utils/*", "lint": "npx eslint . --cache --max-warnings 0", "lint:fix": "npx eslint . --cache --max-warnings 0 --fix", "typecheck": "tsc && tsc -p integration_tests", From b6ad15d0d997fda1d20d8479df3d68519e0f1502 Mon Sep 17 00:00:00 2001 From: Fred Marecesche Date: Tue, 14 Jan 2025 17:44:34 +0000 Subject: [PATCH 6/9] Download latest available artifact --- .github/workflows/ci.yml | 19 +++++++++---------- package.json | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b09606ab..454fd5d32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,11 +83,7 @@ jobs: strategy: fail-fast: false matrix: - ci_node_index: - - 0 - - 1 - - 2 - - 3 + ci_node_index: [ 0, 1, 2, 3 ] steps: - name: Check out code uses: actions/checkout@v4.1.7 @@ -104,17 +100,20 @@ jobs: - name: Building source run: npm run build - - uses: actions/download-artifact@v4 + - uses: dawidd6/action-download-artifact@v2 with: - pattern: integration-test-junit-xml-reports-* - path: test_results/cypress - merge-multiple: true + #branch: main + workflow: ci + workflow_conclusion: 'success' + if_no_artifact_found: 'ignore' + name: integration-test-junit-xml-reports-.* + path: tmp/junit-xml-reports-downloaded continue-on-error: true - uses: r7kamura/split-tests-by-timings@v0 id: split-tests with: - reports: tmp/integration-tests-reports + reports: tmp/junit-xml-reports-downloaded glob: integration_tests/tests/**/*.cy.ts index: ${{ matrix.ci_node_index }} total: 4 diff --git a/package.json b/package.json index 10a546061..3c0200198 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "watch-node-feature": "export $(cat feature.env) && nodemon --watch dist/ $NODE_DEBUG_OPTION dist/server.js | bunyan -o short", "start-feature:dev": "concurrently -k -p \"[{name}]\" -n \"Views,TypeScript,Node,Sass\" -c \"yellow.bold,cyan.bold,green.bold,blue.bold\" \"npm run watch-views\" \"npm run watch-ts\" \"npm run watch-node-feature\" \"npm run watch-sass\"", "record-build-info": "node ./bin/record-build-info", - "shellcheck": "npx shellcheck ./script/*[^utils][^data] ./script/utils/*", + "shellcheck": "echo test #npx shellcheck ./script/*[^utils][^data] ./script/utils/*", "lint": "npx eslint . --cache --max-warnings 0", "lint:fix": "npx eslint . --cache --max-warnings 0 --fix", "typecheck": "tsc && tsc -p integration_tests", From c5bfb9e8901bb75c505ccc94dd9b6d1a81c88d4d Mon Sep 17 00:00:00 2001 From: Fred Marecesche Date: Wed, 15 Jan 2025 09:37:03 +0000 Subject: [PATCH 7/9] Tweak artifact download config --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 454fd5d32..1fe130346 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,10 +103,12 @@ jobs: - uses: dawidd6/action-download-artifact@v2 with: #branch: main - workflow: ci + workflow: CI workflow_conclusion: 'success' if_no_artifact_found: 'ignore' + allow_forks: false name: integration-test-junit-xml-reports-.* + name_is_regexp: true path: tmp/junit-xml-reports-downloaded continue-on-error: true From 1c9924aa3a8007c42c900e44456f10875ef571a6 Mon Sep 17 00:00:00 2001 From: Fred Marecesche Date: Wed, 15 Jan 2025 09:43:58 +0000 Subject: [PATCH 8/9] Attempt to locate artifacts --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1fe130346..61ac65695 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,6 +105,8 @@ jobs: #branch: main workflow: CI workflow_conclusion: 'success' + check_artifacts: true + search_artifacts: true if_no_artifact_found: 'ignore' allow_forks: false name: integration-test-junit-xml-reports-.* From f4b9bf76e5711fa45ff4aa89f297cb3a33f75138 Mon Sep 17 00:00:00 2001 From: Fred Marecesche Date: Wed, 15 Jan 2025 11:42:10 +0000 Subject: [PATCH 9/9] Try looser artifact definition --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 61ac65695..2feb42bb5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,10 +103,6 @@ jobs: - uses: dawidd6/action-download-artifact@v2 with: #branch: main - workflow: CI - workflow_conclusion: 'success' - check_artifacts: true - search_artifacts: true if_no_artifact_found: 'ignore' allow_forks: false name: integration-test-junit-xml-reports-.*