From 1b29ea88b0a47ff2c5586b6164bc25e0d608bad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mence=20Lesn=C3=A9?= Date: Thu, 5 Dec 2024 16:06:29 +0100 Subject: [PATCH] dev: Add CI test step --- .github/workflows/pipeline.yaml | 64 +++++++++++++++++++++++++++++++-- Makefile | 5 +++ 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index b6f804ba..0768d791 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -1,4 +1,4 @@ -name: pipeline +name: Pipeline on: push: @@ -86,6 +86,65 @@ jobs: with: sarif_file: semgrep.sarif + test: + name: Test + permissions: + id-token: write + runs-on: ubuntu-24.04 + needs: + - init + strategy: + fail-fast: false + matrix: + # Run all test suites + step: + - static + # TODO: Enable unit tests (Azure login and config file required) + # - unit + steps: + - name: Checkout + uses: actions/checkout@v4.1.7 + + - name: Set up uv + uses: astral-sh/setup-uv@v4.2.0 + with: + enable-cache: true + python-version: "3.12" + version: "0.5.x" + + # - name: Login to Azure + # uses: Azure/login@v2.2.0 + # with: + # client-id: ${{ secrets.AZURE_CLIENT_ID }} + # subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + # tenant-id: ${{ secrets.AZURE_TENANT_ID }} + + - name: Cache pytest + uses: actions/cache@v4.0.2 + with: + key: pytest-${{ github.head_ref || github.ref_name }}-${{ hashFiles('requirements-dev.txt') }} + path: .pytest_cache + + - name: Cache Ruff + uses: actions/cache@v4.0.2 + with: + key: ruff-${{ github.head_ref || github.ref_name }}-${{ hashFiles('requirements-dev.txt') }} + path: .ruff_cache + + # - name: Configure environment variables + # run: echo "${{ secrets.DOTENV_UNIT_TESTS }}" > .env + + - name: Run tests + run: make test-${{ matrix.step }} version_full=${{ needs.init.outputs.VERSION_FULL }} + + - name: Upload artifacts + uses: actions/upload-artifact@v4.3.6 + if: always() + with: + compression-level: 9 + name: test-${{ matrix.step }} + path: test-reports/* + build-image: name: Build & publish image needs: @@ -168,8 +227,9 @@ jobs: create-release: name: Create release needs: - - init - build-image + - init + - test permissions: # Allow to create releases contents: write diff --git a/Makefile b/Makefile index c76d5f63..3f38986f 100644 --- a/Makefile +++ b/Makefile @@ -70,12 +70,17 @@ upgrade: az bicep upgrade test: + $(MAKE) test-static + $(MAKE) test-unit + +test-static: @echo "➡️ Test code smells (Ruff)..." uv run ruff check --select I,PL,RUF,UP,ASYNC,A,DTZ,T20,ARG,PERF --ignore RUF012 @echo "➡️ Test types (Pyright)..." uv run pyright . +test-unit: @echo "➡️ Unit tests (Pytest)..." PUBLIC_DOMAIN=dummy uv run pytest \ --junit-xml=test-reports/$(version_full).xml \