Move CI to Gitea Actions #1

Merged
michael merged 2 commits from gitea-actions into main 2026-11-25 04:01:43 +00:00
5 changed files with 82 additions and 38 deletions

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
name: Bump recipes
# Opens one pull request per recipe whose upstream has a newer stable release (scripts/bump.py).
# Pushes and pull requests made with the workflow's own token don't start other workflows, so
# the run uses BUMP_TOKEN: an access token of the "cottage-catalog-bot" Gitea user (write access
# to this repository only). Optional GH_TOKEN (a read-only GitHub token) lifts the API rate limit
# for reading upstream releases.
on:
schedule: [{ cron: "17 6 * * *" }]
workflow_dispatch:
jobs:
bump:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0, token: "${{ secrets.BUMP_TOKEN }}" }
- run: pip install --quiet pyyaml
- name: Open bump pull requests
env:
GITEA_URL: ${{ gitea.server_url }}
GITEA_REPO: ${{ gitea.repository }}
GITEA_TOKEN: ${{ secrets.BUMP_TOKEN }}
GH_TOKEN: ${{ secrets.UPSTREAM_GITHUB_TOKEN }}
run: |
git config user.name "cottage-catalog-bot"
git config user.email "[email protected]"
python3 scripts/bump.py run
@@ -1,4 +1,5 @@
name: Check recipes
# Gitea Actions. The helper scripts and platform.ref stay in .github/ (they aren't workflows).
on:
push:
pull_request:
@@ -15,6 +16,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pip install --quiet pyyaml
- name: Check every recipe's version
run: |
python3 - <<'PY'
@@ -65,6 +67,10 @@ jobs:
compose:
name: Docker Compose test
runs-on: ubuntu-latest
# The job talks to the runner's Docker (socket mounted) and reaches the recipes on
# 127.0.0.1, which is the host's loopback only on the host network.
container:
options: --network host
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
@@ -89,7 +95,8 @@ jobs:
done
# Cottage's own checks: the recipe is accepted by the platform and runs its full lifecycle.
# The platform isn't public, so this needs the PLATFORM_KEY secret (a read-only deploy key)
# The platform isn't public, so this needs the HARBOR_DEPLOY_KEY secret (a read-only deploy key
# on cottage/harbor)
# and is skipped for pull requests from forks; a maintainer runs it before merging.
platform:
name: Cottage checks
@@ -107,14 +114,15 @@ jobs:
exit 1
fi
mkdir -p ~/.ssh && printf '%s\n' "$PLATFORM_KEY" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null
git clone -q [email protected]:cottage-host/harbor.git /tmp/platform
ssh-keyscan -p 20001 ssh.git.cottage.host >> ~/.ssh/known_hosts 2>/dev/null
git clone -q ssh://[email protected].cottage.host:20001/cottage/harbor.git /tmp/platform
git -C /tmp/platform checkout -q "$(cat .github/platform.ref)"
(cd /tmp/platform && go build -o /tmp/harbord ./cmd/harbord)
rm -f ~/.ssh/id_ed25519
# Runs as root, as on a server: it hands volume directories to the containers'
# non-root users, which needs root or CAP_CHOWN. Capacity is fixed so the runner's
# disk size can't refuse a recipe.
- run: pip install --quiet pyyaml
- name: Check every recipe
run: |
export HARBOR_DATA_DIR=$RUNNER_TEMP/h HARBOR_RUNTIME=fake HARBOR_BASE_DOMAIN=pods.test
-27
View File
@@ -1,27 +0,0 @@
name: Bump recipes
# Opens one pull request per recipe whose upstream has a newer stable release (scripts/bump.py).
# Pull requests opened with the default GITHUB_TOKEN don't start other workflows, so the run
# signs in as the "Cottage catalog bot" GitHub App (installed on this repository only, contents
# and pull-requests write): the BUMP_APP_ID variable and the BUMP_APP_KEY secret (its private key).
on:
schedule: [{ cron: "17 6 * * *" }]
workflow_dispatch:
permissions: { contents: write, pull-requests: write }
jobs:
bump:
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v2
id: app
with:
app-id: ${{ vars.BUMP_APP_ID }}
private-key: ${{ secrets.BUMP_APP_KEY }}
- uses: actions/checkout@v4
with: { fetch-depth: 0, token: "${{ steps.app.outputs.token }}" }
- run: pip install --quiet pyyaml
- name: Open bump pull requests
env: { GH_TOKEN: "${{ steps.app.outputs.token }}" }
run: |
git config user.name "cottage-catalog-bot[bot]"
git config user.email "5885297+cottage-catalog-bot[bot]@users.noreply.github.com"
python3 scripts/bump.py run
+1 -1
View File
@@ -184,7 +184,7 @@ and their names and logos belong to their projects.
## Automatic updates
A daily workflow (`.github/workflows/bump.yml`, `scripts/bump.py`) opens one pull request for each
A daily workflow (`.gitea/workflows/bump.yml`, `scripts/bump.py`) opens one pull request for each
recipe whose upstream has published a newer stable release and a matching image. `bump/track.yml`
says where each project publishes releases and how its image tag is built from the version; a recipe
marked `manual` there is reported but never changed. The bot waits 3 days after a patch or minor
+44 -7
View File
@@ -8,15 +8,18 @@
scripts/bump.py guard BASE check that a bump branch only changes versions, tags and digests
Tracking data lives in bump/track.yml, not in cottage.yml: Hearth reads cottage.yml strictly, so
an extra key there would stop the catalog sync. Needs PyYAML, the gh CLI (logged in) and docker.
an extra key there would stop the catalog sync. Needs PyYAML and docker. Pull requests are opened on Gitea (GITEA_URL, GITEA_REPO, GITEA_TOKEN);
upstream GitHub releases are read with GH_TOKEN/GITHUB_TOKEN when set, else with the gh CLI.
"""
import glob
import json
import os
import re
import shutil
import subprocess
import sys
import urllib.error
import urllib.request
from datetime import datetime, timezone
@@ -77,10 +80,36 @@ def get_json(url, headers=None):
def gh_json(path):
"""GET from api.github.com (upstream projects publish there): a token when one is set, else the gh CLI."""
token = os.environ.get("GH_TOKEN") or os.environ.get("GITHUB_TOKEN")
if token or shutil.which("gh") is None:
req = urllib.request.Request("https://api.github.com/" + path, headers={"Accept": "application/vnd.github+json", "User-Agent": "cottage-catalog-bump", **({"Authorization": f"Bearer {token}"} if token else {})})
try:
with urllib.request.urlopen(req, timeout=30) as r:
return json.load(r)
except Exception:
return None
out = subprocess.run(["gh", "api", path], capture_output=True, text=True)
return json.loads(out.stdout) if out.returncode == 0 else None
def gitea(method, path, body=None):
"""Call this repository's Gitea API; returns (status, json)."""
base = os.environ.get("GITEA_URL", "https://git.cottage.host").rstrip("/")
repo = os.environ.get("GITEA_REPO", "cottage/catalog")
req = urllib.request.Request(f"{base}/api/v1/repos/{repo}/{path}", method=method,
data=json.dumps(body).encode() if body is not None else None,
headers={"Authorization": "token " + os.environ["GITEA_TOKEN"], "Content-Type": "application/json", "Accept": "application/json"})
try:
with urllib.request.urlopen(req, timeout=30) as r:
return r.status, json.load(r)
except urllib.error.HTTPError as e:
try:
return e.code, json.load(e)
except Exception:
return e.code, None
def latest_release(source, repo):
"""(tag, published datetime) of the newest stable release, or None."""
items = []
@@ -234,9 +263,17 @@ def apply_bump(slug, cur, new, t, images, version):
def run(only=()):
now = datetime.now(timezone.utc)
sh("git", "fetch", "-q", "origin")
labels, open_heads = {}, []
if not os.environ.get("DRY"):
_, have = gitea("GET", "labels?limit=50")
labels = {l["name"]: l["id"] for l in have or []}
for k in COOLDOWN_DAYS:
sh("gh", "label", "create", f"bump-{k}", "--color", "0e8a16", "--description", f"Automatic {k} update", check=False)
if f"bump-{k}" not in labels:
code, made = gitea("POST", "labels", {"name": f"bump-{k}", "color": "#0e8a16", "description": f"Automatic {k} update"})
if code == 201:
labels[f"bump-{k}"] = made["id"]
_, prs = gitea("GET", "pulls?state=open&limit=50")
open_heads = [p["head"]["ref"] for p in prs or []]
opened = failed = 0
start = sh("git", "branch", "--show-current").stdout.strip()
for slug, cur, rel, k, t, images, version in candidates(only):
@@ -251,7 +288,7 @@ def run(only=()):
print(f"{slug}: {new} is {age} days old, waiting for {COOLDOWN_DAYS[k]}")
continue
branch = f"bump/{slug}-{new}"
if not os.environ.get("DRY") and sh("gh", "pr", "list", "--state", "open", "--search", f"head:bump/{slug}-", "--json", "number").stdout.strip() != "[]":
if not os.environ.get("DRY") and any(h.startswith(f"bump/{slug}-") for h in open_heads):
print(f"{slug}: a bump pull request is already open")
continue
if not os.environ.get("DRY"):
@@ -274,11 +311,11 @@ def run(only=()):
f"Automatic {k} update from the bump bot.\n\n- {old_ref} -> {new_ref}\n- digest `{digest}`")
sh("git", "commit", "-q", "-m", f"{title}\n\n{body}")
sh("git", "push", "-q", "-f", "origin", branch)
pr = sh("gh", "pr", "create", "--base", "main", "--head", branch, "--title", title, "--body", body,
"--label", f"bump-{k}", check=False)
if pr.returncode:
code, pr = gitea("POST", "pulls", {"base": "main", "head": branch, "title": title, "body": body,
"labels": [labels[f"bump-{k}"]] if f"bump-{k}" in labels else []})
if code != 201:
failed += 1
print(f"{slug}: pushed {branch} but could not open the pull request: {pr.stderr.strip()}")
print(f"{slug}: pushed {branch} but could not open the pull request: {code} {pr}")
continue
opened += 1
print(f"{slug}: opened {title}")