Skip to content

Commit

Permalink
Split unit and integration tests into separate ci jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
JonJagger committed Mar 3, 2024
1 parent 4e8f787 commit 50cef04
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 24 deletions.
49 changes: 38 additions & 11 deletions .github/workflows/main.yml
Expand Up @@ -147,7 +147,7 @@ jobs:
echo "kosli_fingerprint=${FINGERPRINT}" >> ${GITHUB_OUTPUT}
tests:
unit-tests:
needs: [build-image, kosli-trail]
runs-on: ubuntu-latest
env:
Expand All @@ -156,32 +156,59 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Run unit tests with branch-coverage
run:
make unit_test

- name: Setup Kosli CLI
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}

- name: Run tests with branch-coverage
run: |
make test
- name: Attest results to Kosli
run: |
export REPORTS_DIR=./test/server/reports
kosli attest junit "${IMAGE_NAME}" \
--name=runner.unit-test \
--results-dir=./test/server/reports/junit
--results-dir="${REPORTS_DIR}/junit"
kosli attest generic "${IMAGE_NAME}" \
--attachments=./test/server/reports/coverage \
--attachments="${REPORTS_DIR}/coverage" \
--name=runner.unit-test-branch-coverage \
--user-data=./test/server/reports/coverage/summary.json
--user-data="${REPORTS_DIR}/coverage/summary.json"
integration-tests:
needs: [build-image, kosli-trail]
runs-on: ubuntu-latest
env:
IMAGE_NAME: ${{ needs.kosli-trail.outputs.image_name }}
KOSLI_FINGERPRINT: ${{ needs.build-image.outputs.kosli_fingerprint }}
steps:
- uses: actions/checkout@v4

- name: Run integration tests with branch-coverage
run:
make integration_test

- name: Setup Kosli CLI
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}

- name: Attest results to Kosli
run: |
export REPORTS_DIR=./test/client/reports
kosli attest junit "${IMAGE_NAME}" \
--name=runner.integration-test \
--results-dir=./test/client/reports/junit
--results-dir="${REPORTS_DIR}/junit"
kosli attest generic "${IMAGE_NAME}" \
--attachments=./test/client/reports/coverage \
--attachments="${REPORTS_DIR}/coverage" \
--name=runner.integration-test-branch-coverage \
--user-data=./test/client/reports/coverage/summary.json
--user-data="${REPORTS_DIR}/coverage/summary.json"
snyk-container-scan:
Expand Down Expand Up @@ -261,7 +288,7 @@ jobs:
sdlc-control-gate:
needs: [tests, snyk-container-scan, snyk-code-scan, kosli-trail, build-image]
needs: [unit-tests, integration-tests, snyk-container-scan, snyk-code-scan, kosli-trail, build-image]
runs-on: ubuntu-latest
steps:
- name: Setup Kosli CLI
Expand Down
47 changes: 37 additions & 10 deletions .github/workflows/main_staging.yml
Expand Up @@ -135,7 +135,7 @@ jobs:
echo "kosli_fingerprint=${FINGERPRINT}" >> ${GITHUB_OUTPUT}
tests:
unit-tests:
needs: [wait-for-image, kosli-trail]
runs-on: ubuntu-latest
env:
Expand All @@ -144,32 +144,59 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Run unit tests with branch-coverage
run:
make unit_test

- name: Setup Kosli CLI
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}

- name: Run tests with branch-coverage
- name: Attest results to Kosli
run: |
make test
export REPORTS_DIR=./test/server/reports
kosli attest junit "${IMAGE_NAME}" \
--name=runner.unit-test \
--results-dir=./test/server/reports/junit
--results-dir="${REPORTS_DIR}/junit"
kosli attest generic "${IMAGE_NAME}" \
--attachments=./test/server/reports/coverage \
--attachments="${REPORTS_DIR}/coverage" \
--name=runner.unit-test-branch-coverage \
--user-data=./test/server/reports/coverage/summary.json
--user-data="${REPORTS_DIR}/coverage/summary.json"
integration-tests:
needs: [wait-for-image, kosli-trail]
runs-on: ubuntu-latest
env:
IMAGE_NAME: ${{ needs.kosli-trail.outputs.image_name }}
KOSLI_FINGERPRINT: ${{ needs.wait-for-image.outputs.kosli_fingerprint }}
steps:
- uses: actions/checkout@v4

- name: Run integration tests with branch-coverage
run:
make integration_test

- name: Setup Kosli CLI
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}

- name: Attest results to Kosli
run: |
export REPORTS_DIR=./test/client/reports
kosli attest junit "${IMAGE_NAME}" \
--name=runner.integration-test \
--results-dir=./test/client/reports/junit
--results-dir="${REPORTS_DIR}/junit"
kosli attest generic "${IMAGE_NAME}" \
--attachments=./test/client/reports/coverage \
--attachments="${REPORTS_DIR}/coverage" \
--name=runner.integration-test-branch-coverage \
--user-data=./test/client/reports/coverage/summary.json
--user-data="${REPORTS_DIR}/coverage/summary.json"
snyk-container-scan:
Expand Down Expand Up @@ -249,7 +276,7 @@ jobs:
sdlc-control-gate:
needs: [tests, snyk-container-scan, snyk-code-scan, kosli-trail, wait-for-image]
needs: [unit-tests, integration-tests, snyk-container-scan, snyk-code-scan, kosli-trail, wait-for-image]
runs-on: ubuntu-latest
steps:
- name: Setup Kosli CLI
Expand Down
11 changes: 8 additions & 3 deletions Makefile
Expand Up @@ -2,16 +2,21 @@
SHORT_SHA := $(shell git rev-parse HEAD | head -c7)
IMAGE_NAME := cyberdojo/runner:${SHORT_SHA}

.PHONY: image lint test demo snyk-container snyk-code
.PHONY: image lint unit_test integration_test test demo snyk-container snyk-code

image:
${PWD}/sh/build_tag.sh

lint:
docker run --rm --volume "${PWD}:/app" cyberdojo/rubocop --raise-cop-error

test:
${PWD}/sh/test.sh
unit_test:
${PWD}/sh/test.sh server

integration_test:
${PWD}/sh/test.sh client

test: unit_test integration_test

demo:
${PWD}/sh/demo.sh
Expand Down

0 comments on commit 50cef04

Please sign in to comment.