Files
Scrobbler/.gitea/workflows/ci.yml
T
mattandClaude Opus 5.5 40f1974f3d
CI / validate-monitoring (push) Successful in 7s
CI / lint (push) Successful in 12s
CI / test (push) Successful in 36s
CI / assets (push) Successful in 6s
CI / python-package (push) Successful in 11s
CI / images (push) Successful in 27s
CI / notify (push) Successful in 5s
CI: upload assets with POST (overwrites) and correct content types
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
2026-09-25 14:33:49 +01:00

207 lines
8.4 KiB
YAML

name: CI
# Checks run on every push and PR. Pushes to main and v* tags then publish, but only
# once every check has passed: container images and the monitoring/API-docs bundle
# on both, the Python package on tags. Every run is reported to ntfy.
on:
push:
branches: ["**"]
tags: ["v*"]
pull_request:
workflow_dispatch:
env:
UV_VERSION: "0.7.21"
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: https://github.com/astral-sh/setup-uv@v6
with:
# Exact version: avoids an unauthenticated GitHub API lookup for "latest".
version: ${{ env.UV_VERSION }}
- run: uv sync --locked
- run: uv run ruff check
- run: uv run ruff format --check
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: scrobbler
POSTGRES_PASSWORD: scrobbler
POSTGRES_DB: scrobbler_test
options: >-
--health-cmd "pg_isready -U scrobbler"
--health-interval 5s
--health-timeout 3s
--health-retries 10
env:
DATABASE_URL: postgresql+psycopg://scrobbler:scrobbler@postgres:5432/scrobbler_test
TEST_DATABASE_URL: postgresql+psycopg://scrobbler:scrobbler@postgres:5432/scrobbler_test
steps:
- uses: actions/checkout@v4
- uses: https://github.com/astral-sh/setup-uv@v6
with:
# Exact version: avoids an unauthenticated GitHub API lookup for "latest".
version: ${{ env.UV_VERSION }}
- run: uv sync --locked
- name: Migrations are in sync with the models
run: |
uv run flask --app scrobbler db upgrade
uv run flask --app scrobbler db check
- run: uv run pytest
validate-monitoring:
runs-on: ubuntu-latest
env:
PROMETHEUS_VERSION: "3.5.0"
steps:
- uses: actions/checkout@v4
- name: Install promtool
run: |
case "$(uname -m)" in x86_64) arch=amd64 ;; aarch64|arm64) arch=arm64 ;; *) arch=$(uname -m) ;; esac
name="prometheus-${PROMETHEUS_VERSION}.linux-${arch}"
curl -fsSL "https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/${name}.tar.gz" \
| tar -xz -C /tmp "${name}/promtool"
sudo mv "/tmp/${name}/promtool" /usr/local/bin/ 2>/dev/null || mv "/tmp/${name}/promtool" /usr/local/bin/
- name: Check Prometheus config and alert rules
# The config references alerts.yml relative to itself; targets are compose hostnames.
run: |
promtool check config deploy/prometheus/prometheus.yml
promtool check rules deploy/prometheus/alerts.yml
- name: Dashboards are valid JSON
run: for f in deploy/grafana/dashboards/*.json; do python3 -m json.tool "$f" > /dev/null; done
# ---- Publishing (main and v* tags only) -------------------------------------
images:
needs: [lint, test, validate-monitoring]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.version.outputs.image_tags }}
steps:
- uses: actions/checkout@v4
- uses: https://github.com/astral-sh/setup-uv@v6
with:
version: ${{ env.UV_VERSION }}
- id: version
name: Work out the version and image tags
run: |
short="${GITHUB_SHA::7}"
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
version="${GITHUB_REF_NAME#v}"
tags="$version latest sha-$short"
else
version="$(uv version --short)+g$short"
tags="main sha-$short"
fi
uv version "$version" # baked into the image (scrobbler_build_info)
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "image_tags=$tags" >> "$GITHUB_OUTPUT"
- name: Log in to ProGet
run: echo "${{ secrets.PKGS_PASSWORD }}" | docker login "${{ vars.PKGS_HOST }}" -u "${{ secrets.PKGS_USER }}" --password-stdin
- name: Build and push
env:
REGISTRY: ${{ vars.PKGS_HOST }}/${{ vars.PKGS_DOCKER_FEED }}
TAGS: ${{ steps.version.outputs.image_tags }}
run: |
for image in api ui; do
args=()
for tag in $TAGS; do args+=(-t "$REGISTRY/scrobbler-$image:$tag"); done
docker build -f "docker/$image.Dockerfile" "${args[@]}" \
--label "org.opencontainers.image.revision=$GITHUB_SHA" \
--label "org.opencontainers.image.version=${{ steps.version.outputs.version }}" .
for tag in $TAGS; do docker push "$REGISTRY/scrobbler-$image:$tag"; done
done
- if: always()
run: docker logout "${{ vars.PKGS_HOST }}" || true
assets:
needs: [lint, test, validate-monitoring]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Upload API spec, dashboards and Prometheus config
env:
API_KEY: ${{ secrets.PKGS_API_KEY }}
BASE: https://${{ vars.PKGS_HOST }}/endpoints/${{ vars.PKGS_ASSET_FEED }}/content/scrobbler
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then dirs="${GITHUB_REF_NAME#v}"; else dirs="main sha-${GITHUB_SHA::7}"; fi
files="docs/openapi.json docker-compose.yml deploy/prometheus/prometheus.yml deploy/prometheus/alerts.yml
deploy/grafana/provisioning/datasources/prometheus.yml deploy/grafana/provisioning/dashboards/dashboards.yml
$(ls deploy/grafana/dashboards/*.json)"
# POST creates or overwrites (ProGet rejects PUT to an existing path).
for dir in $dirs; do
for file in $files; do
case "$file" in *.json) type=application/json ;; *) type=application/yaml ;; esac
curl -fsS -X POST -H "X-ApiKey: $API_KEY" -H "Content-Type: $type" --data-binary "@$file" "$BASE/$dir/$file"
echo "uploaded $dir/$file"
done
done
python-package:
needs: [lint, test, validate-monitoring]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: https://github.com/astral-sh/setup-uv@v6
with:
version: ${{ env.UV_VERSION }}
- run: uv version "${GITHUB_REF_NAME#v}"
- run: uv build
- name: Publish to ProGet
run: >-
uv publish
--publish-url "https://${{ vars.PKGS_HOST }}/pypi/${{ vars.PKGS_PYPI_FEED }}/legacy"
--username api --password "${{ secrets.PKGS_API_KEY }}"
notify:
needs: [lint, test, validate-monitoring, images, assets, python-package]
if: always()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: summary
name: Summarise the run
env:
NEEDS: ${{ toJSON(needs) }}
IMAGE_TAGS: ${{ needs.images.outputs.tags }}
run: |
python3 - <<'PY'
import json, os
needs = json.loads(os.environ["NEEDS"])
results = {job: info["result"] for job, info in needs.items()}
if "failure" in results.values():
status = "failure"
elif "cancelled" in results.values():
status = "cancelled"
else:
status = "success"
ran = [f"{job}: {result}" for job, result in results.items() if result != "skipped"]
lines = [" · ".join(ran)]
if os.environ.get("IMAGE_TAGS"):
lines.append("images: " + ", ".join(os.environ["IMAGE_TAGS"].split()))
ref = os.environ["GITHUB_REF"]
title = f"Release {os.environ['GITHUB_REF_NAME']}" if ref.startswith("refs/tags/") else f"CI {os.environ['GITHUB_REF_NAME']}"
with open(os.environ["GITHUB_OUTPUT"], "a") as out:
out.write(f"status={status}\ntitle={title}\n")
out.write("message<<EOF\n" + "\n".join(lines) + "\nEOF\n")
PY
- uses: ./.gitea/actions/notify
with:
status: ${{ steps.summary.outputs.status }}
title: ${{ steps.summary.outputs.title }}
message: ${{ steps.summary.outputs.message }}
url: ${{ vars.NTFY_URL }}
topic: ${{ vars.NTFY_TOPIC }}
user: ${{ secrets.NTFY_USER }}
password: ${{ secrets.NTFY_PASSWORD }}