Add Forgejo Actions CI/CD, ruff linting, and test foundation
- .forgejo/workflows/ci.yml: fast checks on every push (TS typecheck, Python lint via ruff, pytest) — no Docker build, ~30s with cache - .forgejo/workflows/build.yml: Docker build with registry-side layer caching + SSH deploy on main branch pushes only - pyproject.toml: add ruff to dev deps, configure pytest and ruff rules - tests/: conftest.py + first unit tests for _safe_filename (no DB needed) - Makefile: add lint, fmt, typecheck, test, check targets for local use Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
# Runs only on pushes to main.
|
||||
# Builds the Docker image, pushes it to the Forgejo container registry,
|
||||
# then SSHes into the deploy host and restarts the service.
|
||||
#
|
||||
# Required secrets (set in Forgejo repo → Settings → Secrets):
|
||||
# REGISTRY_USER — your Forgejo username
|
||||
# REGISTRY_TOKEN — Forgejo personal access token (write:packages scope)
|
||||
# DEPLOY_HOST — hostname or IP of the server running the app
|
||||
# DEPLOY_USER — SSH username on that server
|
||||
# DEPLOY_SSH_KEY — private SSH key (the public key must be in authorized_keys on the server)
|
||||
# DEPLOY_PATH — absolute path to the directory containing docker-compose.yml
|
||||
name: Build & Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
env:
|
||||
REGISTRY: git.fabledsword.com
|
||||
IMAGE: git.fabledsword.com/bvandeusen/fabledassistant
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build & push image
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to Forgejo registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.IMAGE }}:latest
|
||||
${{ env.IMAGE }}:${{ github.sha }}
|
||||
# Registry-side layer cache — dramatically speeds up rebuilds.
|
||||
# On first run there is no cache so it builds cold; after that
|
||||
# unchanged layers (npm install, pip install) are reused.
|
||||
cache-from: type=registry,ref=${{ env.IMAGE }}:cache
|
||||
cache-to: type=registry,ref=${{ env.IMAGE }}:cache,mode=max
|
||||
|
||||
deploy:
|
||||
name: Deploy
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Pull new image and restart
|
||||
uses: appleboy/ssh-action@v1
|
||||
with:
|
||||
host: ${{ secrets.DEPLOY_HOST }}
|
||||
username: ${{ secrets.DEPLOY_USER }}
|
||||
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
script: |
|
||||
set -e
|
||||
cd ${{ secrets.DEPLOY_PATH }}
|
||||
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.fabledsword.com \
|
||||
-u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
||||
docker compose pull app
|
||||
docker compose up -d --no-build app
|
||||
docker image prune -f
|
||||
@@ -0,0 +1,62 @@
|
||||
# Runs on every push and pull request.
|
||||
# Fast checks only — no Docker build. Second runs take ~30s due to caching.
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
typecheck:
|
||||
name: TypeScript typecheck
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
cache: "npm"
|
||||
cache-dependency-path: frontend/package-lock.json
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
working-directory: frontend
|
||||
|
||||
- name: Type check
|
||||
run: npx vue-tsc --noEmit
|
||||
working-directory: frontend
|
||||
|
||||
lint:
|
||||
name: Python lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install ruff
|
||||
run: pip install ruff
|
||||
|
||||
- name: Lint
|
||||
run: ruff check src/
|
||||
|
||||
test:
|
||||
name: Python tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
cache: "pip"
|
||||
cache-dependency-path: pyproject.toml
|
||||
|
||||
- name: Install package with dev deps
|
||||
run: pip install -e ".[dev]"
|
||||
|
||||
- name: Run tests
|
||||
run: pytest tests/ -v
|
||||
Reference in New Issue
Block a user