Publish images, assets and the Python package from CI
CI / validate-monitoring (push) Successful in 7s
CI / lint (push) Successful in 10s
CI / test (push) Successful in 37s
CI / python-package (push) Skipped
CI / assets (push) Successful in 8s
CI / images (push) Failing after 21s
CI / notify (push) Successful in 5s
CI / validate-monitoring (push) Successful in 7s
CI / lint (push) Successful in 10s
CI / test (push) Successful in 37s
CI / python-package (push) Skipped
CI / assets (push) Successful in 8s
CI / images (push) Failing after 21s
CI / notify (push) Successful in 5s
- Pushes to main and v* tags publish only after every check passes: API and UI images to the ProGet Docker feed, the OpenAPI spec, dashboards and Prometheus config to the asset feed - v* tags also publish the wheel/sdist to the ProGet PyPI feed - The version comes from the tag (main builds: <version>+g<sha>) and __version__ reads it from package metadata - One ntfy notification per run summarising every job that ran and the image tags published Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
1 parent
d7c6830cf7
commit
c44f7ec722
3 files changed
+139
-14
No files matched your search
+123
-8
@@ -1,12 +1,17 @@
|
||||
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-ignore: ["**"]
|
||||
tags: ["v*"]
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
workflow_call:
|
||||
|
||||
env:
|
||||
UV_VERSION: "0.7.21"
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
@@ -16,7 +21,7 @@ jobs:
|
||||
- uses: https://github.com/astral-sh/setup-uv@v6
|
||||
with:
|
||||
# Exact version: avoids an unauthenticated GitHub API lookup for "latest".
|
||||
version: "0.7.21"
|
||||
version: ${{ env.UV_VERSION }}
|
||||
- run: uv sync --locked
|
||||
- run: uv run ruff check
|
||||
- run: uv run ruff format --check
|
||||
@@ -43,7 +48,7 @@ jobs:
|
||||
- uses: https://github.com/astral-sh/setup-uv@v6
|
||||
with:
|
||||
# Exact version: avoids an unauthenticated GitHub API lookup for "latest".
|
||||
version: "0.7.21"
|
||||
version: ${{ env.UV_VERSION }}
|
||||
- run: uv sync --locked
|
||||
- name: Migrations are in sync with the models
|
||||
run: |
|
||||
@@ -72,17 +77,127 @@ jobs:
|
||||
- name: Dashboards are valid JSON
|
||||
run: for f in deploy/grafana/dashboards/*.json; do python3 -m json.tool "$f" > /dev/null; done
|
||||
|
||||
notify:
|
||||
# ---- 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)"
|
||||
for dir in $dirs; do
|
||||
for file in $files; do
|
||||
curl -fsS -X PUT -H "X-ApiKey: $API_KEY" --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: ${{ (needs.lint.result == 'success' && needs.test.result == 'success' && needs.validate-monitoring.result == 'success') && 'success' || ((needs.lint.result == 'cancelled' || needs.test.result == 'cancelled' || needs.validate-monitoring.result == 'cancelled') && 'cancelled' || 'failure') }}
|
||||
title: CI ${{ github.ref_name }}
|
||||
message: "lint: ${{ needs.lint.result }} · test: ${{ needs.test.result }} · monitoring: ${{ needs.validate-monitoring.result }}"
|
||||
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 }}
|
||||
|
||||
@@ -126,17 +126,22 @@ Tests check that every metric a dashboard or alert uses actually exists.
|
||||
|
||||
## CI/CD (Gitea Actions)
|
||||
|
||||
- **`ci.yml`** runs on every push and PR:
|
||||
Everything runs from `.gitea/workflows/ci.yml`:
|
||||
|
||||
- **Every push and PR**:
|
||||
- lint
|
||||
- the migrations check
|
||||
- tests against Postgres
|
||||
- `promtool` checks of the Prometheus config and alert rules
|
||||
- **`publish.yml`** runs on `main` and on `v*` tags. It builds and pushes both images to the ProGet `scrobbler` Docker feed, and uploads the OpenAPI spec, dashboards and Prometheus config to the `scrobbler-assets` feed. On tags it also publishes the wheel to the `scrobbler-python` PyPI feed.
|
||||
- **Notifications**: every workflow run is posted to the `ScrobblingService` topic on notify.daubney.dev.
|
||||
- **Pushes to `main` and `v*` tags**, once every check has passed:
|
||||
- both images are pushed to the ProGet `scrobbler` Docker feed. `main` builds are tagged `main` and `sha-<commit>`; tags are tagged `<version>`, `latest` and `sha-<commit>`.
|
||||
- the OpenAPI spec, dashboards and Prometheus config are uploaded to the `scrobbler-assets` feed under `scrobbler/<version>/` or `scrobbler/main/`.
|
||||
- **`v*` tags** also publish the wheel and sdist to the `scrobbler-python` PyPI feed.
|
||||
- **Every run** is posted to the `ScrobblingService` topic on notify.daubney.dev.
|
||||
|
||||
The workflows need these repository secrets and variables:
|
||||
The workflow needs these repository secrets and variables:
|
||||
|
||||
- **Secrets**: `PKGS_USER`, `PKGS_PASSWORD`, `PKGS_API_KEY`, `NTFY_USER`, `NTFY_PASSWORD`
|
||||
- **Variables**: `PKGS_HOST`, `PKGS_DOCKER_FEED`, `PKGS_PYPI_FEED`, `PKGS_ASSET_FEED`, `NTFY_URL`, `NTFY_TOPIC`
|
||||
|
||||
To release, tag `vX.Y.Z` on `main`. The tag sets the package version.
|
||||
To release, tag `vX.Y.Z` on `main` and push the tag. The tag sets the package and image version.
|
||||
@@ -1,6 +1,11 @@
|
||||
"""Self-hosted, Last.fm-compatible music scrobbling service."""
|
||||
|
||||
__version__ = "0.1.0"
|
||||
from importlib.metadata import PackageNotFoundError, version
|
||||
|
||||
try:
|
||||
__version__ = version("scrobbler") # set from the release tag at build time
|
||||
except PackageNotFoundError: # running from a source tree without installing
|
||||
__version__ = "0.0.0+unknown"
|
||||
|
||||
|
||||
def create_app(config_object=None):
|
||||
|
||||
Reference in new issue
Block a user