ci: Run the test suite before building release images (v2.7.1)

Add a 'test' stage to the Containerfile (production base image plus pytest)
and build it in the release workflow before the push step, so a failing test
stops the release.

Fix the eight tests that were failing: media validation returns a PIL Image
since v1.5.0, and the migration test needs TESTING to skip production config
checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-03 08:28:08 -07:00
1 parent 43ec7cb8be
commit 6a76ee26af
6 files changed
+48 -19

No files matched your search

+5 -1
View File
@@ -1,5 +1,5 @@
# Gitea Actions workflow for StarPunk # Gitea Actions workflow for StarPunk
# Builds and pushes container images on version tags. # Runs the tests, then builds and pushes container images on version tags.
# #
# The runner has no Docker daemon (that would give workflows root on the # The runner has no Docker daemon (that would give workflows root on the
# server). Images are built by the rootless BuildKit container next to it, # server). Images are built by the rootless BuildKit container next to it,
@@ -30,6 +30,10 @@ jobs:
run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "$REGISTRY" -u "${{ github.repository_owner }}" --password-stdin run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "$REGISTRY" -u "${{ github.repository_owner }}" --password-stdin
- name: Use the BuildKit socket - name: Use the BuildKit socket
run: docker buildx create --name ci --driver remote "$BUILDKIT" --use run: docker buildx create --name ci --driver remote "$BUILDKIT" --use
# Builds the Containerfile's test stage, which runs pytest; a failure
# stops the workflow before anything is pushed
- name: Run tests
run: docker buildx build --target test --progress plain -f Containerfile .
- name: Build and push - name: Build and push
run: | run: |
image="$REGISTRY/$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" image="$REGISTRY/$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')"
+10
View File
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [2.7.1] - 2026-11-03
### Changed
- Releases run the full test suite first: CI builds the Containerfile's new `test` stage (same Python image as production) and stops before pushing an image if any test fails
### Fixed
- Eight tests that had been failing: the image validation tests still expected bytes (validation has returned an image object since v1.5.0), and a migration test started the app in production mode
## [2.7.0] - 2026-11-03 ## [2.7.0] - 2026-11-03
Webmention now follows the [W3C Recommendation](https://www.w3.org/TR/webmention/) throughout. Webmention now follows the [W3C Recommendation](https://www.w3.org/TR/webmention/) throughout.
+21 -1
View File
@@ -23,7 +23,27 @@ RUN uv venv /opt/venv && \
uv pip install --no-cache -r requirements.txt uv pip install --no-cache -r requirements.txt
# ============================================================================ # ============================================================================
# Runtime Stage - Minimal production image # Test Stage - Runs the test suite (CI builds it with --target test)
# ============================================================================
FROM python:3.11-slim AS test
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
COPY --from=builder /opt/venv /opt/venv
RUN uv pip install --no-cache --python /opt/venv/bin/python pytest pytest-mock
ENV PATH="/opt/venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
SESSION_SECRET=ci-test-secret \
SITE_URL=http://localhost:5000 \
ADMIN_ME=https://test.example.com
WORKDIR /app
COPY . .
RUN python -m pytest -q -p no:cacheprovider tests
# ============================================================================
# Runtime Stage - Minimal production image (default target: keep it last)
# ============================================================================ # ============================================================================
FROM python:3.11-slim FROM python:3.11-slim
+2 -2
View File
@@ -459,5 +459,5 @@ def create_app(config=None):
# Package version (Semantic Versioning 2.0.0) # Package version (Semantic Versioning 2.0.0)
# See docs/standards/versioning-strategy.md for details # See docs/standards/versioning-strategy.md for details
__version__ = "2.7.0" __version__ = "2.7.1"
__version_info__ = (2, 7, 0) __version_info__ = (2, 7, 1)
+9 -14
View File
@@ -110,7 +110,7 @@ class TestImageValidation:
assert mime_type == 'image/jpeg' assert mime_type == 'image/jpeg'
assert width == 800 assert width == 800
assert height == 600 assert height == 600
assert file_data == image_data # No conversion assert isinstance(file_data, Image.Image) # validate_image returns a PIL Image (v1.5.0)
def test_valid_png(self): def test_valid_png(self):
"""Test validation of valid PNG image""" """Test validation of valid PNG image"""
@@ -120,7 +120,7 @@ class TestImageValidation:
assert mime_type == 'image/png' assert mime_type == 'image/png'
assert width == 800 assert width == 800
assert height == 600 assert height == 600
assert file_data == image_data # No conversion assert isinstance(file_data, Image.Image) # validate_image returns a PIL Image (v1.5.0)
def test_valid_gif(self): def test_valid_gif(self):
"""Test validation of valid GIF image""" """Test validation of valid GIF image"""
@@ -130,7 +130,7 @@ class TestImageValidation:
assert mime_type == 'image/gif' assert mime_type == 'image/gif'
assert width == 800 assert width == 800
assert height == 600 assert height == 600
assert file_data == image_data # No conversion assert isinstance(file_data, Image.Image) # validate_image returns a PIL Image (v1.5.0)
def test_valid_webp(self): def test_valid_webp(self):
"""Test validation of valid WebP image""" """Test validation of valid WebP image"""
@@ -140,7 +140,7 @@ class TestImageValidation:
assert mime_type == 'image/webp' assert mime_type == 'image/webp'
assert width == 800 assert width == 800
assert height == 600 assert height == 600
assert file_data == image_data # No conversion assert isinstance(file_data, Image.Image) # validate_image returns a PIL Image (v1.5.0)
def test_file_too_large(self): def test_file_too_large(self):
"""Test rejection of >10MB file (per Q6)""" """Test rejection of >10MB file (per Q6)"""
@@ -183,11 +183,8 @@ class TestHEICSupport:
assert mime_type == 'image/jpeg' assert mime_type == 'image/jpeg'
assert width == 800 assert width == 800
assert height == 600 assert height == 600
# file_data should be different (converted to JPEG) # Converted to JPEG (validate_image returns a PIL Image)
assert file_data != heic_data assert file_data.format == 'JPEG'
# Verify it's actually JPEG by opening it
img = Image.open(io.BytesIO(file_data))
assert img.format == 'JPEG'
def test_heic_with_rgba_mode(self): def test_heic_with_rgba_mode(self):
"""Test HEIC with alpha channel is converted to RGB JPEG""" """Test HEIC with alpha channel is converted to RGB JPEG"""
@@ -209,8 +206,7 @@ class TestHEICSupport:
# Should be converted to JPEG (no alpha) # Should be converted to JPEG (no alpha)
assert mime_type == 'image/jpeg' assert mime_type == 'image/jpeg'
# Verify it's RGB (no alpha) # Verify it's RGB (no alpha)
img = Image.open(io.BytesIO(file_data)) assert file_data.mode == 'RGB'
assert img.mode == 'RGB'
def test_heic_dimensions_preserved(self): def test_heic_dimensions_preserved(self):
"""Test HEIC conversion preserves dimensions""" """Test HEIC conversion preserves dimensions"""
@@ -273,9 +269,8 @@ class TestMPOSupport:
assert mime_type == 'image/jpeg' assert mime_type == 'image/jpeg'
assert width == 800 assert width == 800
assert height == 600 assert height == 600
# Verify it's actually JPEG by opening it # Converted to JPEG (validate_image returns a PIL Image)
img = Image.open(io.BytesIO(file_data)) assert file_data.format == 'JPEG'
assert img.format == 'JPEG'
# Note: MPO with single frame may have identical bytes to JPEG # Note: MPO with single frame may have identical bytes to JPEG
# The important part is the format detection and MIME type correction # The important part is the format detection and MIME type correction
+1 -1
View File
@@ -43,7 +43,7 @@ class TestRetryLogic:
from starpunk.database import init_db from starpunk.database import init_db
from starpunk import create_app from starpunk import create_app
app = create_app({'DATABASE_PATH': str(temp_db)}) app = create_app({'DATABASE_PATH': str(temp_db), 'TESTING': True})
init_db(app) init_db(app)
# Verify migrations table exists and has records # Verify migrations table exists and has records