diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09f1d59..c6de37e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,105 +1,105 @@ -name: CI - -on: - push: - branches: [main, develop] - pull_request: - workflow_dispatch: - -permissions: - contents: read - -concurrency: - group: ci-${{ github.ref }} - cancel-in-progress: true - -env: - DOTNET_NOLOGO: true - DOTNET_CLI_TELEMETRY_OPTOUT: true - -jobs: - build: - name: Build and test - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 10.0.x - - - name: Restore - run: dotnet restore src/Taskist.sln - - - name: Build - run: dotnet build src/Taskist.sln --configuration Release --no-restore - - - name: Test - run: dotnet test src/Taskist.sln --configuration Release --no-build --logger "trx;LogFileName=results.trx" - - - name: Check the generated dark theme is up to date - run: | - python3 tools/theme/generate-dark-css.py - git diff --exit-code -- src/Presentation/Taskist.Web/wwwroot/css/theme-dark.generated.css || { echo "::error::theme-dark.generated.css is stale. Run 'python tools/theme/generate-dark-css.py' and commit the result."; exit 1; } - - - name: Check for missing migrations - run: | - dotnet tool install --global dotnet-ef --version 10.* - dotnet ef migrations has-pending-model-changes \ - --project src/Libraries/Taskist.Data \ - --startup-project src/Libraries/Taskist.Data \ - --configuration Release \ - --no-build - - - name: Upload test results - if: always() - uses: actions/upload-artifact@v4 - with: - name: test-results - path: "**/TestResults/*.trx" - if-no-files-found: ignore - - docker: - name: Docker stack smoke test - runs-on: ubuntu-latest - needs: build - steps: - - uses: actions/checkout@v4 - - - name: Create .env - run: | - cp .env.example .env - sed -i "s/^MSSQL_SA_PASSWORD=.*/MSSQL_SA_PASSWORD=Ci_$(openssl rand -hex 12)Aa1!/" .env - - - name: Build and start - run: docker compose up -d --build - - - name: Wait for the web container to become healthy - run: | - for attempt in $(seq 1 120); do - migrate="$(docker compose ps -a --format '{{.State}} {{.ExitCode}}' migrate)" - case "$migrate" in - exited\ 0|"") ;; - exited*) echo "migrate failed: $migrate"; exit 1 ;; - esac - web="$(docker compose ps -q web)" - if [ -n "$web" ] && [ "$(docker inspect -f '{{.State.Health.Status}}' "$web")" = "healthy" ]; then - echo "web is healthy"; exit 0 - fi - sleep 5 - done - echo "timed out waiting for web"; exit 1 - - - name: Sign-in page responds - run: curl -fsS http://localhost:8080/login -o /dev/null - - - name: Seeding is repeatable - run: docker compose run --rm migrate - - - name: Logs - if: failure() - run: docker compose logs - - - name: Tear down - if: always() - run: docker compose down -v +name: CI + +on: + push: + branches: [main, develop] + pull_request: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +env: + DOTNET_NOLOGO: true + DOTNET_CLI_TELEMETRY_OPTOUT: true + +jobs: + build: + name: Build and test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: 10.0.x + + - name: Restore + run: dotnet restore src/Taskist.sln + + - name: Build + run: dotnet build src/Taskist.sln --configuration Release --no-restore + + - name: Test + run: dotnet test src/Taskist.sln --configuration Release --no-build --logger "trx;LogFileName=results.trx" + + - name: Check the generated dark theme is up to date + run: | + python3 tools/theme/generate-dark-css.py + git diff --exit-code -- src/Presentation/Taskist.Web/wwwroot/css/theme-dark.generated.css || { echo "::error::theme-dark.generated.css is stale. Run 'python tools/theme/generate-dark-css.py' and commit the result."; exit 1; } + + - name: Check for missing migrations + run: | + dotnet tool install --global dotnet-ef --version 10.* + dotnet ef migrations has-pending-model-changes \ + --project src/Libraries/Taskist.Data \ + --startup-project src/Libraries/Taskist.Data \ + --configuration Release \ + --no-build + + - name: Upload test results + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-results + path: "**/TestResults/*.trx" + if-no-files-found: ignore + + docker: + name: Docker stack smoke test + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v7 + + - name: Create .env + run: | + cp .env.example .env + sed -i "s/^MSSQL_SA_PASSWORD=.*/MSSQL_SA_PASSWORD=Ci_$(openssl rand -hex 12)Aa1!/" .env + + - name: Build and start + run: docker compose up -d --build + + - name: Wait for the web container to become healthy + run: | + for attempt in $(seq 1 120); do + migrate="$(docker compose ps -a --format '{{.State}} {{.ExitCode}}' migrate)" + case "$migrate" in + exited\ 0|"") ;; + exited*) echo "migrate failed: $migrate"; exit 1 ;; + esac + web="$(docker compose ps -q web)" + if [ -n "$web" ] && [ "$(docker inspect -f '{{.State.Health.Status}}' "$web")" = "healthy" ]; then + echo "web is healthy"; exit 0 + fi + sleep 5 + done + echo "timed out waiting for web"; exit 1 + + - name: Sign-in page responds + run: curl -fsS http://localhost:8080/login -o /dev/null + + - name: Seeding is repeatable + run: docker compose run --rm migrate + + - name: Logs + if: failure() + run: docker compose logs + + - name: Tear down + if: always() + run: docker compose down -v