diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 50d7818..dbb3422 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -4,6 +4,10 @@ on: push: branches: [main] tags: ['v*'] + paths: + - package.json + - Dockerfile + - 'src/**' workflow_dispatch: inputs: tag: diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml index 4ee9bbe..e8deb1b 100644 --- a/.github/workflows/mirror.yml +++ b/.github/workflows/mirror.yml @@ -1,18 +1,43 @@ -# Pushes the contents of the repo to the Codeberg mirror +# Mirrors the repository to an alternate (non-Microsoft!) Git hosting service + +# The following options can be specified as env vars/secrets: +# - MIRROR_SSH: (REQUIRED) SSH private key with write access to target repo +# - MIRROR_HOST: (optional) Hostname of target Git server, defaults to Codeberg +# - MIRROR_USER: (optional) User or org name of target repo, defaults to alicia +# - MIRROR_REPO: (optional) Name of target repo, defaults to same as source repo + name: 🪞 Mirror to Codeberg + on: workflow_dispatch: schedule: - cron: '30 01 * * 0' push: tags: [ 'v*' ] + jobs: codeberg: runs-on: ubuntu-latest + env: # Get values for target repo from env vars or fallback to defaults + MIRROR_HOST: ${{ vars.MIRROR_HOST || 'git@codeberg.org' }} + MIRROR_USER: ${{ vars.MIRROR_USER || 'alicia' }} + MIRROR_REPO: ${{ vars.MIRROR_REPO || github.event.repository.name }} + HAS_SSH: ${{ secrets.MIRROR_SSH != '' }} steps: - - uses: actions/checkout@v4 + - name: Cancel if SSH key not set + if: env.HAS_SSH != 'true' + run: echo "::warning::MIRROR_SSH secret not set" && exit 1 + + - name: Checkout source repository + uses: actions/checkout@v4 with: { fetch-depth: 0 } - - uses: pixta-dev/repository-mirroring-action@v1 - with: - target_repo_url: git@codeberg.org:alicia/networking-toolbox.git - ssh_private_key: ${{ secrets.CODEBERG_SSH }} + + - name: Mirror repository to target + run: | + set -e + mkdir -p ~/.ssh + echo "${{ secrets.MIRROR_SSH }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan codeberg.org >> ~/.ssh/known_hosts + git remote add mirror ${{ env.MIRROR_HOST }}:${{ env.MIRROR_USER }}/${{ env.MIRROR_REPO }}.git || true + git push mirror --mirror diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ad2d731..9ea7c48 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -57,7 +57,7 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage/lcov.info flags: unittests - name: ip-calc + name: networking-toolbox fail_ci_if_error: false continue-on-error: true @@ -97,6 +97,80 @@ jobs: if: steps.test.outcome == 'failure' run: exit 1 + api-tests: + name: API Contract Tests + runs-on: ubuntu-latest + env: + NODE_OPTIONS: "--max_old_space_size=8192" + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - run: npm ci + + - name: Build application + run: npm run build + + - name: Start preview server + run: npm run preview -- --port 4175 & + + - name: Wait for server + run: | + timeout 30 bash -c 'until curl -f http://localhost:4175/api >/dev/null 2>&1; do sleep 1; done' + + - name: Run API contract tests + id: test + run: | + npm run test:api -- \ + --reporter=github-actions \ + --reporter=verbose \ + --reporter=junit \ + --outputFile=api-test-results.xml + continue-on-error: true + + - name: Save test result + if: always() + run: echo "${{ steps.test.outcome }}" > test-result-api.txt + + - name: Upload test result + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-result-api + path: test-result-api.txt + + - name: API Test Report + id: api-test-report + uses: dorny/test-reporter@v1 + if: always() + with: + name: API Contract Tests + path: api-test-results.xml + reporter: java-junit + fail-on-error: false + + - name: Save API test report data + if: always() + run: | + echo "passed=${{ steps.api-test-report.outputs.passed }}" > api-report-data.txt + echo "failed=${{ steps.api-test-report.outputs.failed }}" >> api-report-data.txt + echo "skipped=${{ steps.api-test-report.outputs.skipped }}" >> api-report-data.txt + echo "time=${{ steps.api-test-report.outputs.time }}" >> api-report-data.txt + + - name: Upload API test report data + if: always() + uses: actions/upload-artifact@v4 + with: + name: api-report-data + path: api-report-data.txt + + - name: Fail if tests failed + if: steps.test.outcome == 'failure' + run: exit 1 + e2e-tests: name: E2E Tests runs-on: ubuntu-latest @@ -187,7 +261,7 @@ jobs: name: Summary runs-on: ubuntu-latest if: always() - needs: [unit-tests, e2e-tests] + needs: [unit-tests, api-tests, e2e-tests] steps: - name: Download test results uses: actions/download-artifact@v4 @@ -204,10 +278,12 @@ jobs: - name: Write summary env: UNIT_JOB: ${{ needs.unit-tests.result }} + API_JOB: ${{ needs.api-tests.result }} E2E_JOB: ${{ needs.e2e-tests.result }} run: | # Read actual test results from artifacts (or use job result as fallback) UNIT=$(cat test-result-unit.txt 2>/dev/null || echo "$UNIT_JOB") + API=$(cat test-result-api.txt 2>/dev/null || echo "$API_JOB") E2E=$(cat test-result-e2e.txt 2>/dev/null || echo "$E2E_JOB") # Helper functions @@ -228,16 +304,22 @@ jobs: # Count failures failures=0 [ "$UNIT" = "failure" ] && failures=$((failures + 1)) + [ "$API" = "failure" ] && failures=$((failures + 1)) [ "$E2E" = "failure" ] && failures=$((failures + 1)) # Get detailed test data UNIT_DATA=$(parse_report "unit-report-data.txt") + API_DATA=$(parse_report "api-report-data.txt") E2E_DATA=$(parse_report "e2e-report-data.txt") # Parse unit test data eval "$UNIT_DATA" UNIT_PASSED=$passed; UNIT_FAILED=$failed; UNIT_SKIPPED=$skipped; UNIT_TIME=$time + # Parse API test data + eval "$API_DATA" + API_PASSED=$passed; API_FAILED=$failed; API_SKIPPED=$skipped; API_TIME=$time + # Parse e2e test data eval "$E2E_DATA" E2E_PASSED=$passed; E2E_FAILED=$failed; E2E_SKIPPED=$skipped; E2E_TIME=$time @@ -258,6 +340,7 @@ jobs: echo "## 🧪 Test Results" echo "" line "$UNIT" "Unit Tests" "npm run test:coverage" + line "$API" "API Contract Tests" "npm run test:api" line "$E2E" "E2E Tests" "npm run test:e2e" if [ "$failures" -eq 0 ]; then @@ -278,6 +361,17 @@ jobs: [ "$UNIT_TIME" != "0" ] && echo "| ⏱️ Duration | $(format_time $UNIT_TIME) |" fi + # Detailed API Test Report + if [ "$API_PASSED" != "0" ] || [ "$API_FAILED" != "0" ] || [ "$API_SKIPPED" != "0" ]; then + echo -e "\n### 🔗 API Contract Test Details" + echo "| Metric | Count |" + echo "|--------|-------|" + [ "$API_PASSED" != "0" ] && echo "| ✅ Passed | $API_PASSED |" + [ "$API_FAILED" != "0" ] && echo "| ❌ Failed | $API_FAILED |" + [ "$API_SKIPPED" != "0" ] && echo "| ⏭️ Skipped | $API_SKIPPED |" + [ "$API_TIME" != "0" ] && echo "| ⏱️ Duration | $(format_time $API_TIME) |" + fi + # Detailed E2E Test Report if [ "$E2E_PASSED" != "0" ] || [ "$E2E_FAILED" != "0" ] || [ "$E2E_SKIPPED" != "0" ]; then echo -e "\n### 🎭 E2E Test Details"