Compare commits
4
Commits
v1.3.1
..
d051d9deb7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d051d9deb7 | ||
|
|
267d9e52e0 | ||
|
|
4753d80891 | ||
|
|
36611ef30b |
@@ -0,0 +1,63 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
- 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 adguard-cidre:ci python -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
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
/adguard/*.log
|
/adguard/*.log
|
||||||
/tmp/
|
/tmp/
|
||||||
|
__pycache__/
|
||||||
|
.pytest_cache/
|
||||||
|
|||||||
+8
-1
@@ -1,4 +1,4 @@
|
|||||||
FROM python:3.13-alpine
|
FROM python:3.13-alpine AS base
|
||||||
|
|
||||||
ENV TZ=Europe/Paris
|
ENV TZ=Europe/Paris
|
||||||
|
|
||||||
@@ -11,4 +11,11 @@ WORKDIR /app
|
|||||||
|
|
||||||
COPY blocklist_scheduler.py .
|
COPY blocklist_scheduler.py .
|
||||||
|
|
||||||
|
FROM base AS test
|
||||||
|
COPY requirements-dev.txt .
|
||||||
|
RUN pip install --no-cache-dir -r requirements-dev.txt
|
||||||
|
COPY tests/ tests/
|
||||||
|
COPY pytest.ini .
|
||||||
|
|
||||||
|
FROM base
|
||||||
ENTRYPOINT ["python3", "blocklist_scheduler.py"]
|
ENTRYPOINT ["python3", "blocklist_scheduler.py"]
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
[pytest]
|
||||||
|
pythonpath = .
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
requests
|
||||||
|
pyyaml
|
||||||
|
schedule
|
||||||
|
pytest
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
import blocklist_scheduler as bs
|
||||||
|
|
||||||
|
|
||||||
|
def test_backup_first_start_creates_backup_when_missing(tmp_path, monkeypatch):
|
||||||
|
adguard_yaml = tmp_path / "AdGuardHome.yaml"
|
||||||
|
adguard_yaml.write_text("original: config\n")
|
||||||
|
first_backup = tmp_path / "AdGuardHome.yaml.first-start.bak"
|
||||||
|
|
||||||
|
monkeypatch.setattr(bs, "ADGUARD_YAML", adguard_yaml)
|
||||||
|
monkeypatch.setattr(bs, "FIRST_BACKUP", first_backup)
|
||||||
|
|
||||||
|
bs.backup_first_start()
|
||||||
|
|
||||||
|
assert first_backup.read_text() == "original: config\n"
|
||||||
|
|
||||||
|
|
||||||
|
def test_backup_first_start_does_not_overwrite_existing_backup(tmp_path, monkeypatch):
|
||||||
|
adguard_yaml = tmp_path / "AdGuardHome.yaml"
|
||||||
|
adguard_yaml.write_text("new: config\n")
|
||||||
|
first_backup = tmp_path / "AdGuardHome.yaml.first-start.bak"
|
||||||
|
first_backup.write_text("pristine: original\n")
|
||||||
|
|
||||||
|
monkeypatch.setattr(bs, "ADGUARD_YAML", adguard_yaml)
|
||||||
|
monkeypatch.setattr(bs, "FIRST_BACKUP", first_backup)
|
||||||
|
|
||||||
|
bs.backup_first_start()
|
||||||
|
|
||||||
|
assert first_backup.read_text() == "pristine: original\n"
|
||||||
|
|
||||||
|
|
||||||
|
def test_backup_first_start_raises_if_adguard_yaml_missing(tmp_path, monkeypatch):
|
||||||
|
adguard_yaml = tmp_path / "AdGuardHome.yaml"
|
||||||
|
first_backup = tmp_path / "AdGuardHome.yaml.first-start.bak"
|
||||||
|
|
||||||
|
monkeypatch.setattr(bs, "ADGUARD_YAML", adguard_yaml)
|
||||||
|
monkeypatch.setattr(bs, "FIRST_BACKUP", first_backup)
|
||||||
|
|
||||||
|
with pytest.raises(FileNotFoundError):
|
||||||
|
bs.backup_first_start()
|
||||||
Reference in New Issue
Block a user