1 Commits
Author SHA1 Message Date
Djeex ceb94a6a2d Add pytest suite and Gitea Actions CI/CD pipeline
CI / build-and-scan (pull_request) Successful in 1m1s
83 tests (94% coverage of src/py) covering the builder pipeline
(gallery sync, HTML/CSS generation, image processing, full site
build) and the Flask webui (routes, uploads, theme/font management).

Dockerfile gains a `test` stage (pytest) between the wheel builder
and the prod image, and pins the alpine base to a full patch tag so
Renovate can classify updates. CI workflow builds, smoke-tests, runs
the suite, scans with Trivy, and publishes/releases on merge to main,
following the same pipeline already running on adguard-cidre.
2026-08-23 10:03:40 +02:00
4 changed files with 83 additions and 131 deletions
+79 -127
View File
@@ -5,8 +5,6 @@ on:
branches: [main] branches: [main]
pull_request: pull_request:
branches: [main] branches: [main]
schedule:
- cron: "0 6 * * 1"
jobs: jobs:
build-and-scan: build-and-scan:
@@ -18,172 +16,126 @@ jobs:
fetch-depth: 0 fetch-depth: 0
persist-credentials: false persist-credentials: false
- name: Build Docker image - name: Build prod image
run: | run: docker build -t lumeex:ci .
docker build -t lumeex: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) - name: Smoke test
run: | run: |
docker run --rm --entrypoint python lumeex:ci -c " docker run --rm --entrypoint python lumeex:ci -c "
import ast import ast
ok = True ast.parse(open('build.py').read())
for f in ('build.py', 'gallery.py'): ast.parse(open('gallery.py').read())
with open(f) as fh: print('syntax ok')
source = fh.read()
try:
ast.parse(source)
except SyntaxError as e:
print(f'::error::Syntax error in {f}: {e}')
ok = False
if not ok:
exit(1)
print('OK: syntax is valid')
" "
- name: Run unit tests - name: Build test image
run: | run: docker build --target test -t lumeex:test .
docker build --target test -t lumeex:test .
docker run --rm lumeex:test pytest -v - name: Unit tests
run: docker run --rm lumeex:test pytest -v
- name: Check deprecation warnings - name: Check deprecation warnings
run: | run: docker run --rm --entrypoint python lumeex:ci -W error::DeprecationWarning -c "import src.py.webui.webui"
docker run --rm --entrypoint python lumeex:ci -W error::DeprecationWarning -c "import src.py.webui.webui" 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) - name: Trivy critical (blocking)
run: | run: |
docker run --rm \ docker run --rm \
-e DOCKER_HOST=tcp://dockerhost:2375 \ -e DOCKER_HOST=tcp://dockerhost:2375 --add-host=dockerhost:host-gateway \
--add-host=dockerhost:host-gateway \ -v /var/run/docker.sock:/var/run/docker.sock \
aquasec/trivy:0.74.0 image --exit-code 1 --severity CRITICAL lumeex:ci aquasec/trivy image --exit-code 1 --severity CRITICAL lumeex:ci
- name: Scan with Trivy (high - informative) - name: Trivy high (informative)
run: | run: |
docker run --rm \ docker run --rm \
-e DOCKER_HOST=tcp://dockerhost:2375 \ -e DOCKER_HOST=tcp://dockerhost:2375 --add-host=dockerhost:host-gateway \
--add-host=dockerhost:host-gateway \ -v /var/run/docker.sock:/var/run/docker.sock \
aquasec/trivy:0.74.0 image --exit-code 0 --severity HIGH lumeex:ci aquasec/trivy image --exit-code 0 --severity HIGH lumeex:ci
- name: Publish tagged image - name: Publish tagged image
if: github.event_name == 'push' && github.ref == 'refs/heads/main' if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
CI_PUSH_TOKEN: ${{ secrets.CI_PUSH_TOKEN }}
GITEA_URL: https://git.djeex.fr
IMAGE: git.djeex.fr/djeex/lumeex
run: | run: |
BEFORE="${{ github.event.before }}" set -e
if [ -n "$BEFORE" ] && [ "$BEFORE" != "0000000000000000000000000000000000000000" ] && git cat-file -e "$BEFORE" 2>/dev/null; then
BASE_REF="$BEFORE"
else
BASE_REF="HEAD~1"
fi
CHANGED=$(git diff --name-only "$BASE_REF" "${{ github.sha }}")
echo "Changed files:"
echo "$CHANGED"
if ! echo "$CHANGED" | grep -qE '^(Dockerfile|requirements\.txt|VERSION|build\.py|gallery\.py)$|^(src|config)/|^docker/\.sh/entrypoint\.sh$'; then # Only republish when a container-relevant file actually changed
echo "No container-relevant file changed, skipping publish." BEFORE="${{ github.event.before }}"
if [ -z "$BEFORE" ] || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
BEFORE="HEAD~1"
fi
CHANGED=$(git diff --name-only "$BEFORE" "${{ github.sha }}" -- \
Dockerfile requirements.txt VERSION build.py gallery.py \
src/ config/ docker/.sh/entrypoint.sh || true)
if [ -z "$CHANGED" ]; then
echo "No container-relevant changes, skipping publish."
exit 0 exit 0
fi fi
if echo "$CHANGED" | grep -qE '^VERSION$'; then VERSION_BUMPED=false
echo "VERSION was manually edited in this push, using it as-is." if ! echo "$CHANGED" | grep -qx "VERSION"; then
else CURRENT_VERSION=$(cat VERSION)
echo "VERSION untouched but container files changed, auto-bumping the build number (Z)." MAJOR=$(echo "$CURRENT_VERSION" | cut -d. -f1)
OLD_VERSION=$(tr -d '[:space:]' < VERSION) MINOR=$(echo "$CURRENT_VERSION" | cut -d. -f2)
IFS='.' read -r MAJOR MINOR PATCH <<< "$OLD_VERSION" PATCH=$(echo "$CURRENT_VERSION" | cut -d. -f3)
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
echo "$NEW_VERSION" > VERSION echo "$NEW_VERSION" > VERSION
git config user.name "lumeex-ci" git config user.name "gitea-ci"
git config user.email "[email protected]" git config user.email "[email protected]"
git remote set-url origin "https://gitea-ci:${CI_PUSH_TOKEN}@git.djeex.fr/Djeex/lumeex.git"
git add VERSION git add VERSION
git commit -m "Bump build version to $NEW_VERSION [skip ci]" git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
git push origin HEAD:main
# Belt and suspenders: actions/checkout can leave its own ephemeral git config --unset-all "http.https://git.djeex.fr/Djeex/lumeex.git/.extraheader" || true
# credential injected as an extraheader, which would silently override VERSION_BUMPED=true
# the URL-embedded token below. persist-credentials:false on checkout
# should already prevent this, but strip it here too just in case.
git config --unset-all http.https://git.djeex.fr/.extraheader || true
git push "https://Djeex:${{ secrets.CI_PUSH_TOKEN }}@git.djeex.fr/Djeex/lumeex.git" HEAD:main
fi fi
VERSION=$(tr -d '[:space:]' < VERSION) FULL_VERSION=$(cat VERSION)
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" MAJOR_MINOR=$(echo "$FULL_VERSION" | cut -d. -f1,2)
MINOR_TAG="${MAJOR}.${MINOR}"
IMAGE=git.djeex.fr/djeex/lumeex echo "$REGISTRY_TOKEN" | docker login git.djeex.fr -u Djeex --password-stdin
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 lumeex:ci "$IMAGE:latest" docker tag lumeex:ci "$IMAGE:latest"
docker tag lumeex:ci "$IMAGE:$MINOR_TAG" docker tag lumeex:ci "$IMAGE:$MAJOR_MINOR"
docker tag lumeex:ci "$IMAGE:$VERSION" docker tag lumeex:ci "$IMAGE:$FULL_VERSION"
docker push "$IMAGE:latest" docker push "$IMAGE:latest"
docker push "$IMAGE:$MINOR_TAG" docker push "$IMAGE:$MAJOR_MINOR"
docker push "$IMAGE:$VERSION" docker push "$IMAGE:$FULL_VERSION"
TRIGGER_MSG=$(git log -1 --format=%s "${{ github.sha }}")
PR_NUM=$(echo "$TRIGGER_MSG" | grep -oE '#[0-9]+' | head -1 | tr -d '#' || true)
# Categorize the changelog from the merged PR's labels, if any
PR_NUMBER=$(git log -1 --format=%B "${{ github.sha }}" | grep -oE '#[0-9]+' | head -1 | tr -d '#' || true)
CATEGORY="🔧 Maintenance" CATEGORY="🔧 Maintenance"
CHANGE_TITLE="$TRIGGER_MSG" PR_LINK=""
if [ -n "$PR_NUMBER" ]; then
if [ -n "$PR_NUM" ]; then PR_LINK="https://git.djeex.fr/Djeex/lumeex/pulls/$PR_NUMBER"
PR_JSON=$(curl -s -H "Authorization: token ${{ secrets.CI_PUSH_TOKEN }}" \ LABELS=$(curl -s -H "Authorization: token $CI_PUSH_TOKEN" \
"https://git.djeex.fr/api/v1/repos/Djeex/lumeex/pulls/$PR_NUM") "$GITEA_URL/api/v1/repos/Djeex/lumeex/issues/$PR_NUMBER/labels" | jq -r '.[].name' || true)
PR_TITLE=$(echo "$PR_JSON" | jq -r '.title // empty' 2>/dev/null || true) if echo "$LABELS" | grep -qx "bug"; then
LABELS=$(echo "$PR_JSON" | jq -r '.labels[]?.name' 2>/dev/null || true)
if [ -n "$PR_TITLE" ]; then
CHANGE_TITLE="$PR_TITLE"
fi
if echo "$LABELS" | grep -qx 'bug'; then
CATEGORY="⚠️ Hotfix" CATEGORY="⚠️ Hotfix"
elif echo "$LABELS" | grep -qx 'major'; then elif echo "$LABELS" | grep -qx "major"; then
CATEGORY="💥 Breaking change" CATEGORY="💥 Breaking change"
elif echo "$LABELS" | grep -qx 'minor'; then elif echo "$LABELS" | grep -qx "minor"; then
CATEGORY="✨ Update" CATEGORY="✨ Update"
fi fi
fi fi
REPO_URL="https://git.djeex.fr/Djeex/lumeex" COMMIT_LINK="https://git.djeex.fr/Djeex/lumeex/commit/${{ github.sha }}"
COMMIT_LIST=$(git log --no-merges --format="- [%h](${REPO_URL}/commit/%H) %s" "$BASE_REF".."${{ github.sha }}") BODY="**$CATEGORY**\n\nCommit: $COMMIT_LINK"
if [ -n "$PR_LINK" ]; then
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) BODY="$BODY\nPR: $PR_LINK"
SOURCE_LINE="[${SHORT_SHA}](${REPO_URL}/commit/${{ github.sha }})"
if [ -n "$PR_NUM" ]; then
SOURCE_LINE="[#${PR_NUM}](${REPO_URL}/pulls/${PR_NUM}) · ${SOURCE_LINE}"
fi fi
BODY=$(cat <<EOF jq -n \
## Changelog --arg tag "$FULL_VERSION" \
--- --arg name "$FULL_VERSION" \
### ${CATEGORY}
---
${CHANGE_TITLE}
**Source:** ${SOURCE_LINE}
**Image:** \`${IMAGE}:${VERSION}\`
**Commits:**
${COMMIT_LIST}
EOF
)
JSON_PAYLOAD=$(jq -n \
--arg tag "$VERSION" \
--arg name "$VERSION" \
--arg body "$BODY" \ --arg body "$BODY" \
'{tag_name: $tag, name: $name, target_commitish: "main", body: $body}') '{tag_name: $tag, name: $name, body: $body}' | \
curl -s -X POST \
curl -s -o /dev/null -w "Release API response: %{http_code}\n" -X POST \ -H "Authorization: token $CI_PUSH_TOKEN" \
-H "Authorization: token ${{ secrets.CI_PUSH_TOKEN }}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$JSON_PAYLOAD" \ -d @- \
"https://git.djeex.fr/api/v1/repos/Djeex/lumeex/releases" "$GITEA_URL/api/v1/repos/Djeex/lumeex/releases"
+2 -2
View File
@@ -1,4 +1,4 @@
FROM python:3.14.7-alpine AS builder FROM python:3.13.15-alpine AS builder
WORKDIR /app WORKDIR /app
@@ -7,7 +7,7 @@ RUN apk add --no-cache gcc musl-dev jpeg-dev zlib-dev
COPY requirements.txt . COPY requirements.txt .
RUN pip wheel --no-cache-dir --wheel-dir=/wheels -r requirements.txt RUN pip wheel --no-cache-dir --wheel-dir=/wheels -r requirements.txt
FROM python:3.14.7-alpine AS base FROM python:3.13.15-alpine AS base
WORKDIR /app WORKDIR /app
+1 -1
View File
@@ -1 +1 @@
2.1.4 2.1.2
+1 -1
View File
@@ -1,3 +1,3 @@
-r requirements.txt -r requirements.txt
pytest==8.4.2 pytest==8.4.2
pytest-cov==7.1.0 pytest-cov==7.0.0