Move CI to Gitea Actions
Check recipes / Bump guard (push) Skipped
Check recipes / Bump guard (pull_request) Skipped
Check recipes / Version format (push) Failing after 4s
Check recipes / Parameters (push) Successful in 8s
Check recipes / Listing images (push) Successful in 5s
Check recipes / Docker Compose test (push) Successful in 4s
Check recipes / Cottage checks (push) Failing after 28s
Check recipes / Version format (pull_request) Failing after 4s
Check recipes / Listing images (pull_request) Successful in 7s
Check recipes / Parameters (pull_request) Successful in 10s
Check recipes / Docker Compose test (pull_request) Successful in 5s
Check recipes / Cottage checks (pull_request) Failing after 30s
Check recipes / Bump guard (push) Skipped
Check recipes / Bump guard (pull_request) Skipped
Check recipes / Version format (push) Failing after 4s
Check recipes / Parameters (push) Successful in 8s
Check recipes / Listing images (push) Successful in 5s
Check recipes / Docker Compose test (push) Successful in 4s
Check recipes / Cottage checks (push) Failing after 28s
Check recipes / Version format (pull_request) Failing after 4s
Check recipes / Listing images (pull_request) Successful in 7s
Check recipes / Parameters (pull_request) Successful in 10s
Check recipes / Docker Compose test (pull_request) Successful in 5s
Check recipes / Cottage checks (pull_request) Failing after 30s
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.
This commit is contained in:
1 parent
9c1093e736
commit
2f8d76ac00
5 files changed
+80
-38
No files matched your search
+44
-7
@@ -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}")
|
||||
|
||||
Reference in new issue
Block a user