name: CI on: push: branches: [main] pull_request: branches: [main] schedule: - cron: "0 6 * * 1" jobs: build-and-scan: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - name: Build Docker image run: | docker build -t adguard-cidre:ci . 2>&1 | tee build.log if grep -q "Building wheel for" build.log; then echo "::warning::A dependency was built from source — check Python/Alpine compatibility" fi - name: Smoke test (syntax check) run: | docker run --rm --entrypoint python adguard-cidre:ci -c " import ast with open('blocklist_scheduler.py') as f: source = f.read() try: ast.parse(source) print('OK: syntax is valid') except SyntaxError as e: print(f'::error::Syntax error: {e}') exit(1) " - name: Run unit tests run: | docker build --target test -t adguard-cidre:test . docker run --rm adguard-cidre:test pytest -v - name: Check deprecation warnings run: | docker run --rm --entrypoint python adguard-cidre:ci -W error::DeprecationWarning -c "import blocklist_scheduler" 2>&1 | tee deprecation.log || true if grep -qi "deprecat" deprecation.log; then echo "::warning::Deprecation warning detected, check logs" fi - name: Scan with Trivy (critical - blocking) run: | docker run --rm \ -e DOCKER_HOST=tcp://dockerhost:2375 \ --add-host=dockerhost:host-gateway \ aquasec/trivy:0.74.0 image --exit-code 1 --severity CRITICAL adguard-cidre:ci - name: Scan with Trivy (high - informative) run: | docker run --rm \ -e DOCKER_HOST=tcp://dockerhost:2375 \ --add-host=dockerhost:host-gateway \ aquasec/trivy:0.74.0 image --exit-code 0 --severity HIGH adguard-cidre:ci - name: Publish tagged image if: github.event_name == 'push' && github.ref == 'refs/heads/main' run: | BEFORE="${{ github.event.before }}" if [ -n "$BEFORE" ] && [ "$BEFORE" != "0000000000000000000000000000000000000000" ] && git cat-file -e "$BEFORE" 2>/dev/null; then CHANGED=$(git diff --name-only "$BEFORE" "${{ github.sha }}") else CHANGED=$(git diff --name-only HEAD~1 HEAD) fi echo "Changed files:" echo "$CHANGED" if ! echo "$CHANGED" | grep -qE '^(Dockerfile|blocklist_scheduler\.py|VERSION)$'; then echo "No container-relevant file changed, skipping publish." exit 0 fi IMAGE=git.djeex.fr/djeex/adguard-cidre echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.djeex.fr -u Djeex --password-stdin # Retag the already-built, already-scanned image — never rebuild for publish, # so what ships is byte-for-byte what Trivy just scanned. docker tag adguard-cidre:ci "$IMAGE:latest" docker push "$IMAGE:latest" if echo "$CHANGED" | grep -qE '^VERSION$'; then VERSION=$(tr -d '[:space:]' < VERSION) docker tag adguard-cidre:ci "$IMAGE:$VERSION" docker push "$IMAGE:$VERSION" else echo "VERSION unchanged, skipping versioned tag to avoid overwriting an existing release." fi