From b3efa2b7585a4ea9133fa4d73a4458f10675c215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20H=C3=A4kkinen?= Date: Fri, 28 Jul 2023 16:05:46 +0300 Subject: [PATCH] Run tests for Nest.js project in CI --- .github/workflows/build_image.yaml | 22 ++++++++- .github/workflows/run_tests.yaml | 75 ++++++++++++++++++++---------- compose-ci.yaml | 5 +- 3 files changed, 75 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build_image.yaml b/.github/workflows/build_image.yaml index 3324cf0..8dc4aa3 100644 --- a/.github/workflows/build_image.yaml +++ b/.github/workflows/build_image.yaml @@ -1,6 +1,6 @@ name: Build and upload image -on: +on: workflow_call: jobs: @@ -23,3 +23,23 @@ jobs: with: name: hybridilusmu path: /tmp/hybridilusmu.tar + + build-nest: + name: Build and upload image (Nest.js) + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Build and export + uses: docker/build-push-action@v4 + with: + context: app-nest + tags: hybridilusmu-nest + outputs: type=docker,dest=/tmp/hybridilusmu-nest.tar + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: hybridilusmu-nest + path: /tmp/hybridilusmu-nest.tar diff --git a/.github/workflows/run_tests.yaml b/.github/workflows/run_tests.yaml index 0ad3497..678a7cc 100644 --- a/.github/workflows/run_tests.yaml +++ b/.github/workflows/run_tests.yaml @@ -40,28 +40,53 @@ jobs: - name: Stop containers if: always() run: npm stop -# FIXME: Enable these once integration tests exit cleanly. -# integration-tests: -# name: Integration tests -# runs-on: ubuntu-latest -# needs: build -# steps: -# - name: Checkout -# uses: actions/checkout@v3 -# - name: Set up Docker Buildx -# uses: docker/setup-buildx-action@v2 -# - name: Download artifact -# uses: actions/download-artifact@v3 -# with: -# name: hybridilusmu -# path: /tmp -# - name: Load image -# run: | -# docker load --input /tmp/hybridilusmu.tar -# docker image ls -a -# - name: Start containers -# run: docker compose -f compose.yaml -f compose-ci.yaml up -d lusmu -# - name: Run integration tests -# run: npm run test:integration -# - name: Stop containers -# run: npm stop + + unit-tests-nest: + name: Unit tests (Nest.js) + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Download artifact + uses: actions/download-artifact@v3 + with: + name: hybridilusmu-nest + path: /tmp + - name: Load image + run: | + docker load --input /tmp/hybridilusmu-nest.tar + docker image ls -a + - name: Start containers + run: docker compose -f compose.yaml -f compose-ci.yaml up -d lusmu-nest + - name: Run unit tests + run: docker exec -t lusmu-nest npm test + - name: Stop containers + if: always() + run: npm stop + + integration-tests-nest: + name: Integration tests (Nest.js) + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Download artifact + uses: actions/download-artifact@v3 + with: + name: hybridilusmu-nest + path: /tmp + - name: Load image + run: | + docker load --input /tmp/hybridilusmu-nest.tar + docker image ls -a + - name: Start containers + run: docker compose -f compose.yaml -f compose-ci.yaml up -d lusmu-nest + - name: Run integration tests + run: npm run test:integration + - name: Stop containers + if: always() + run: npm stop diff --git a/compose-ci.yaml b/compose-ci.yaml index 26101e9..6dabfb2 100644 --- a/compose-ci.yaml +++ b/compose-ci.yaml @@ -1,3 +1,6 @@ services: lusmu: - image: hybridilusmu-ci + image: hybridilusmu + + lusmu-nest: + image: hybridilusmu-nest