- Add SQLITE_DB_PATH env var to db_engine.py for test isolation - Create tests/conftest.py with in-memory SQLite fixture and sample data helpers - Add tests/test_dependencies.py: unit tests for valid_token, mround, param_char, get_req_url - Add tests/test_card_pricing.py: tests for Player.change_on_sell/buy and get_all_pos - Add tests/test_api_packs.py: integration tests for GET/POST/DELETE /api/v2/packs - Add requirements-test.txt with pytest and httpx - Add test job to CI workflow (build now requires tests to pass first) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
141 lines
5.2 KiB
YAML
141 lines
5.2 KiB
YAML
# Gitea Actions: Docker Build, Push, and Notify
|
|
#
|
|
# CI/CD pipeline for Paper Dynasty Database API:
|
|
# - Builds Docker images on every push/PR
|
|
# - Auto-generates CalVer version (YYYY.MM.BUILD) on main branch merges
|
|
# - Pushes to Docker Hub and creates git tag on main
|
|
# - Sends Discord notifications on success/failure
|
|
|
|
name: Build Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: https://github.com/actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: https://github.com/actions/setup-python@v5
|
|
with:
|
|
python-version: "3.12"
|
|
|
|
- name: Install test dependencies
|
|
run: pip install -r requirements-test.txt
|
|
|
|
- name: Create required directories
|
|
run: mkdir -p logs/database storage
|
|
|
|
- name: Run tests
|
|
env:
|
|
API_TOKEN: test_token_12345
|
|
run: pytest tests/ -v
|
|
|
|
build:
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: https://github.com/actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # Full history for tag counting
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: https://github.com/docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Docker Hub
|
|
uses: https://github.com/docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Generate CalVer version
|
|
id: calver
|
|
uses: cal/gitea-actions/calver@main
|
|
|
|
# Dev build: push with dev + dev-SHA tags (PR/feature branches)
|
|
- name: Build Docker image (dev)
|
|
if: github.ref != 'refs/heads/main'
|
|
uses: https://github.com/docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: |
|
|
manticorum67/paper-dynasty-database:dev
|
|
manticorum67/paper-dynasty-database:dev-${{ steps.calver.outputs.sha_short }}
|
|
cache-from: type=registry,ref=manticorum67/paper-dynasty-database:buildcache
|
|
cache-to: type=registry,ref=manticorum67/paper-dynasty-database:buildcache,mode=max
|
|
|
|
# Production build: push with latest + CalVer tags (main only)
|
|
- name: Build Docker image (production)
|
|
if: github.ref == 'refs/heads/main'
|
|
uses: https://github.com/docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: |
|
|
manticorum67/paper-dynasty-database:latest
|
|
manticorum67/paper-dynasty-database:${{ steps.calver.outputs.version }}
|
|
manticorum67/paper-dynasty-database:${{ steps.calver.outputs.version_sha }}
|
|
cache-from: type=registry,ref=manticorum67/paper-dynasty-database:buildcache
|
|
cache-to: type=registry,ref=manticorum67/paper-dynasty-database:buildcache,mode=max
|
|
|
|
- name: Tag release
|
|
if: success() && github.ref == 'refs/heads/main'
|
|
uses: cal/gitea-actions/gitea-tag@main
|
|
with:
|
|
version: ${{ steps.calver.outputs.version }}
|
|
token: ${{ github.token }}
|
|
|
|
- name: Build Summary
|
|
run: |
|
|
echo "## Docker Build Successful" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Image Tags:**" >> $GITHUB_STEP_SUMMARY
|
|
echo "- \`manticorum67/paper-dynasty-database:latest\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "- \`manticorum67/paper-dynasty-database:${{ steps.calver.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "- \`manticorum67/paper-dynasty-database:${{ steps.calver.outputs.version_sha }}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Build Details:**" >> $GITHUB_STEP_SUMMARY
|
|
echo "- Branch: \`${{ steps.calver.outputs.branch }}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "- Commit: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "- Timestamp: \`${{ steps.calver.outputs.timestamp }}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
|
echo "Pushed to Docker Hub!" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "Pull with: \`docker pull manticorum67/paper-dynasty-database:latest\`" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "_PR build - image not pushed to Docker Hub_" >> $GITHUB_STEP_SUMMARY
|
|
fi
|
|
|
|
- name: Discord Notification - Success
|
|
if: success() && github.ref == 'refs/heads/main'
|
|
uses: cal/gitea-actions/discord-notify@main
|
|
with:
|
|
webhook_url: ${{ secrets.DISCORD_WEBHOOK }}
|
|
title: "Paper Dynasty Database"
|
|
status: success
|
|
version: ${{ steps.calver.outputs.version }}
|
|
image_tag: ${{ steps.calver.outputs.version_sha }}
|
|
commit_sha: ${{ steps.calver.outputs.sha_short }}
|
|
timestamp: ${{ steps.calver.outputs.timestamp }}
|
|
|
|
- name: Discord Notification - Failure
|
|
if: failure() && github.ref == 'refs/heads/main'
|
|
uses: cal/gitea-actions/discord-notify@main
|
|
with:
|
|
webhook_url: ${{ secrets.DISCORD_WEBHOOK }}
|
|
title: "Paper Dynasty Database"
|
|
status: failure
|