From 2f8d76ac009081f68637b5ae936e58096ea72c8c Mon Sep 17 00:00:00 2001 From: Michael Kinder <60057409+FoggyMtnDrifter@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:14:09 -0500 Subject: [PATCH 1/2] Move CI to Gitea Actions Workflows live in .gitea/workflows. The bump bot opens its pull requests through the Gitea API with a bot access token, and the platform check clones Harbor from git.cottage.host over SSH. --- .gitea/workflows/bump.yml | 26 +++++++++++ {.github => .gitea}/workflows/validate.yml | 12 +++-- .github/workflows/bump.yml | 27 ------------ README.md | 2 +- scripts/bump.py | 51 +++++++++++++++++++--- 5 files changed, 80 insertions(+), 38 deletions(-) create mode 100644 .gitea/workflows/bump.yml rename {.github => .gitea}/workflows/validate.yml (91%) delete mode 100644 .github/workflows/bump.yml diff --git a/.gitea/workflows/bump.yml b/.gitea/workflows/bump.yml new file mode 100644 index 0000000..bb8c51e --- /dev/null +++ b/.gitea/workflows/bump.yml @@ -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 "cottage-catalog-bot@users.noreply.git.cottage.host" + python3 scripts/bump.py run diff --git a/.github/workflows/validate.yml b/.gitea/workflows/validate.yml similarity index 91% rename from .github/workflows/validate.yml rename to .gitea/workflows/validate.yml index 9b6310a..ca38f00 100644 --- a/.github/workflows/validate.yml +++ b/.gitea/workflows/validate.yml @@ -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: @@ -65,6 +66,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 +94,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,8 +113,8 @@ 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 git@github.com:cottage-host/harbor.git /tmp/platform + ssh-keyscan -p 20001 ssh.git.cottage.host >> ~/.ssh/known_hosts 2>/dev/null + git clone -q ssh://git@ssh.git.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 diff --git a/.github/workflows/bump.yml b/.github/workflows/bump.yml deleted file mode 100644 index 11041d3..0000000 --- a/.github/workflows/bump.yml +++ /dev/null @@ -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 diff --git a/README.md b/README.md index b62eb19..e6291ed 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/scripts/bump.py b/scripts/bump.py index 9efd34c..2eebd57 100755 --- a/scripts/bump.py +++ b/scripts/bump.py @@ -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}") From b8a8fd4bff23b98bad87d8e30095558d1111da6a Mon Sep 17 00:00:00 2001 From: Michael Kinder <60057409+FoggyMtnDrifter@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:54:03 -0500 Subject: [PATCH 2/2] CI: install PyYAML in the jobs that need it (the Gitea runner image lacks it) --- .gitea/workflows/validate.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitea/workflows/validate.yml b/.gitea/workflows/validate.yml index ca38f00..0a7e126 100644 --- a/.gitea/workflows/validate.yml +++ b/.gitea/workflows/validate.yml @@ -16,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' @@ -121,6 +122,7 @@ jobs: # 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