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@v7 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 if echo "$CHANGED" | grep -qE '^VERSION$'; then echo "VERSION was manually edited in this push, using it as-is." else echo "VERSION untouched but container files changed, auto-bumping the build number (Z)." OLD_VERSION=$(tr -d '[:space:]' < VERSION) IFS='.' read -r MAJOR MINOR PATCH <<< "$OLD_VERSION" NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" echo "$NEW_VERSION" > VERSION git config user.name "adguard-cidre-ci" git config user.email "ci@git.djeex.fr" git add VERSION git commit -m "Bump build version to $NEW_VERSION [skip ci]" git push "https://Djeex:${{ secrets.CI_PUSH_TOKEN }}@git.djeex.fr/Djeex/adguard-cidre.git" HEAD:main fi VERSION=$(tr -d '[:space:]' < VERSION) IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" MINOR_TAG="${MAJOR}.${MINOR}" 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 tag adguard-cidre:ci "$IMAGE:$MINOR_TAG" docker tag adguard-cidre:ci "$IMAGE:$VERSION" docker push "$IMAGE:latest" docker push "$IMAGE:$MINOR_TAG" docker push "$IMAGE:$VERSION"