generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2171 from ministryofjustice/CHORE/github-actions-…
…pipeline Move PR tests to GitHub Actions
- Loading branch information
Showing
5 changed files
with
173 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
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/[email protected] | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/[email protected] | ||
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/[email protected] | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/[email protected] | ||
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/[email protected] | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/[email protected] | ||
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 | ||
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/[email protected] | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/[email protected] | ||
with: | ||
node-version-file: '.node-version' | ||
cache: 'npm' | ||
|
||
- name: Installing dependencies | ||
run: npm ci | ||
|
||
- name: Building source | ||
run: npm run build | ||
|
||
- name: Downloading test reports from previous runs | ||
uses: dawidd6/action-download-artifact@v2 | ||
with: | ||
branch: main | ||
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 | ||
|
||
- name: Determining tests splitting by timing | ||
uses: r7kamura/split-tests-by-timings@v0 | ||
id: split-tests | ||
with: | ||
reports: tmp/junit-xml-reports-downloaded | ||
glob: integration_tests/tests/**/*.cy.ts | ||
index: ${{ matrix.ci_node_index }} | ||
total: 4 | ||
|
||
- name: Running Integration tests | ||
run: TEST_RUN_ARGS="--spec $(echo ${{ steps.split-tests.outputs.paths }} | sed -E 's/ /,/g')" npm run test:integration | ||
|
||
- name: Fix Cypress JUnit XML reports | ||
run: script/fix-cypress-junit-xml | ||
|
||
- name: Store Integration tests reports | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
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-${{ matrix.ci_node_index }} | ||
path: integration_tests/videos | ||
|
||
- name: Store Integration tests screenshots | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: integration-tests-screenshots-${{ matrix.ci_node_index }} | ||
path: integration_tests/screenshots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/sh | ||
|
||
# script/fix-cypress-junit-xml: adds the `file` attribute found in the 'Root Suite' testsuite node to all other | ||
# testuite nodes, so the split-test utility can correctly identify test run times. | ||
|
||
# Directory containing Junit XML files | ||
directory="./test_results/cypress" | ||
|
||
cd "$(dirname "$0")/.." || exit | ||
|
||
# Iterate over all XML files in the directory | ||
find "$directory" -name "*.xml" | while read -r xml_file; do | ||
# Extract the 'file' attribute (from the "Root Suite" testsuite) | ||
file=$(grep -o 'file="[^"]*"' "$xml_file") | ||
|
||
# If the 'file' attribute was found, apply it to all other testsuite nodes | ||
if [ -n "$file" ]; then | ||
# Use sed to add the 'file' attribute to all testsuite nodes except 'Root Suite' | ||
sed -i'' -e "/<testsuite [^>]*name=\"Root Suite\"[^>]*>/!s|<testsuite |<testsuite $file |" "$xml_file" | ||
else | ||
echo "No 'file' attribute found in $xml_file, skipping..." | ||
fi | ||
done |