Add a bump bot that opens update pull requests for recipes (#30)
A daily workflow compares each recipe with its upstream's newest stable release and opens one pull request when the image for it is published: version, image tag and multi-arch digest only. bump/track.yml holds where each project releases and how its image tag follows the version; it lives outside cottage.yml because Hearth reads that file strictly. Patch and minor releases wait 3 days, majors 14. A guard check fails a bump branch that changes anything else, and 'scripts/bump.py audit' shows how far behind each recipe is.
This commit is contained in:
1 parent
ad8148af74
commit
5796d0eebb
5 files changed
+770
No files matched your search
@@ -0,0 +1,22 @@
|
||||
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 set the
|
||||
# BUMP_TOKEN secret (a GitHub App installation token or a fine-grained token with contents and
|
||||
# pull-requests write) for CI to run on them.
|
||||
on:
|
||||
schedule: [{ cron: "17 6 * * *" }]
|
||||
workflow_dispatch:
|
||||
permissions: { contents: write, pull-requests: write }
|
||||
jobs:
|
||||
bump:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with: { fetch-depth: 0, token: "${{ secrets.BUMP_TOKEN || secrets.GITHUB_TOKEN }}" }
|
||||
- run: pip install --quiet pyyaml
|
||||
- name: Open bump pull requests
|
||||
env: { GH_TOKEN: "${{ secrets.BUMP_TOKEN || secrets.GITHUB_TOKEN }}" }
|
||||
run: |
|
||||
git config user.name "Cottage catalog bot"
|
||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
python3 scripts/bump.py run
|
||||
@@ -28,6 +28,18 @@ jobs:
|
||||
sys.exit(1 if bad else 0)
|
||||
PY
|
||||
|
||||
# Automatic bump branches may only change versions, image tags and digests, and never an image's
|
||||
# repository, so they can't widen what the platform's image allowlist accepts.
|
||||
bump-guard:
|
||||
name: Bump guard
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'pull_request' && startsWith(github.head_ref, 'bump/')
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with: { fetch-depth: 0 }
|
||||
- run: pip install --quiet pyyaml
|
||||
- run: python3 scripts/bump.py guard "origin/${{ github.base_ref }}"
|
||||
|
||||
# Parameters follow schema/cottage.schema.json ($defs/parameter), and recipes that send mail
|
||||
# use the shared SMTP_* fields in group "email".
|
||||
parameters:
|
||||
|
||||
@@ -126,3 +126,13 @@ Open an issue or a pull request. Please don't include secrets, real credentials
|
||||
|
||||
[Apache-2.0](LICENSE). The apps themselves keep their own licences (listed in each `cottage.yml`),
|
||||
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
|
||||
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
|
||||
release (14 for a major) and bumps only the first image, never the database or cache beside it.
|
||||
Bump branches may only change versions, image tags and digests: the "Bump guard" check fails
|
||||
anything else. Run `scripts/bump.py audit` to see how far behind each recipe is.
|
||||
+402
@@ -0,0 +1,402 @@
|
||||
# What the bump bot follows for each recipe (scripts/bump.py).
|
||||
# source/repo where upstream publishes releases
|
||||
# image_tag how the first image's tag is built from the release; {version} is the
|
||||
# dotted version. Companion images (databases, caches) are never bumped.
|
||||
# manual the bot reports this recipe but never changes it
|
||||
# skip not followed at all
|
||||
activepieces:
|
||||
image_tag: '{version}'
|
||||
repo: activepieces/activepieces
|
||||
source: github
|
||||
actual-budget:
|
||||
image_tag: '{version}'
|
||||
repo: actualbudget/actual
|
||||
source: github
|
||||
answer:
|
||||
image_tag: '{version}'
|
||||
repo: apache/answer
|
||||
source: github
|
||||
archivebox:
|
||||
image_tag: '{version}'
|
||||
repo: ArchiveBox/ArchiveBox
|
||||
source: github
|
||||
audiobookshelf:
|
||||
image_tag: '{version}'
|
||||
repo: advplyr/audiobookshelf
|
||||
source: github
|
||||
baserow:
|
||||
image_tag: '{version}'
|
||||
repo: baserow/baserow
|
||||
source: github
|
||||
beszel:
|
||||
image_tag: '{version}'
|
||||
repo: henrygd/beszel
|
||||
source: github
|
||||
blinko:
|
||||
image_tag: '{version}'
|
||||
repo: blinkospace/blinko
|
||||
source: github
|
||||
bytestash:
|
||||
image_tag: '{version}'
|
||||
repo: jordan-dalby/ByteStash
|
||||
source: github
|
||||
changedetection-io:
|
||||
image_tag: '{version}'
|
||||
repo: dgtlmoon/changedetection.io
|
||||
source: github
|
||||
checkmate:
|
||||
image_tag: '{version}'
|
||||
repo: bluewave-labs/Checkmate
|
||||
source: github
|
||||
chevereto:
|
||||
image_tag: '{version}'
|
||||
repo: chevereto/chevereto
|
||||
source: github
|
||||
code-server:
|
||||
image_tag: '{version}'
|
||||
repo: coder/code-server
|
||||
source: github
|
||||
commafeed:
|
||||
image_tag: '{version}-h2'
|
||||
repo: Athou/commafeed
|
||||
source: github
|
||||
convos:
|
||||
image_tag: v{version}
|
||||
repo: convos-chat/convos
|
||||
source: github
|
||||
dashy:
|
||||
image_tag: '{version}'
|
||||
repo: Lissy93/dashy
|
||||
source: github
|
||||
docmost:
|
||||
image_tag: '{version}'
|
||||
repo: docmost/docmost
|
||||
source: github
|
||||
docuseal:
|
||||
image_tag: '{version}'
|
||||
repo: docusealco/docuseal
|
||||
source: github
|
||||
dokuwiki:
|
||||
manual: image tag '2026-07-14c' doesn't follow version '2026.07.14.3'; the bot will not touch it
|
||||
repo: dokuwiki/dokuwiki
|
||||
source: github
|
||||
easyappointments:
|
||||
image_tag: '{version}'
|
||||
repo: alextselegidis/easyappointments
|
||||
source: github
|
||||
etherpad:
|
||||
image_tag: '{version}'
|
||||
repo: ether/etherpad
|
||||
source: github
|
||||
firefly-iii:
|
||||
manual: image tag 'version-6.7.9' doesn't follow version '6.7.9'; the bot will not touch it
|
||||
repo: firefly-iii/firefly-iii
|
||||
source: github
|
||||
flatnotes:
|
||||
image_tag: v{version}
|
||||
repo: dullage/flatnotes
|
||||
source: github
|
||||
forgejo:
|
||||
image_tag: '{version}-rootless'
|
||||
repo: forgejo/forgejo
|
||||
source: codeberg
|
||||
freshrss:
|
||||
image_tag: '{version}'
|
||||
repo: FreshRSS/FreshRSS
|
||||
source: github
|
||||
fusion:
|
||||
image_tag: '{version}'
|
||||
repo: 0x2E/fusion
|
||||
source: github
|
||||
ghost:
|
||||
image_tag: '{version}'
|
||||
repo: TryGhost/Ghost
|
||||
source: github
|
||||
gitea:
|
||||
image_tag: '{version}-rootless'
|
||||
repo: go-gitea/gitea
|
||||
source: github
|
||||
glitchtip:
|
||||
image_tag: '{version}'
|
||||
repo: glitchtip/glitchtip-backend
|
||||
source: gitlab
|
||||
gokapi:
|
||||
image_tag: v{version}
|
||||
repo: Forceu/Gokapi
|
||||
source: github
|
||||
gotify:
|
||||
image_tag: '{version}'
|
||||
repo: gotify/server
|
||||
source: github
|
||||
grimmory:
|
||||
image_tag: v{version}
|
||||
repo: grimmory-tools/grimmory
|
||||
source: github
|
||||
hedgedoc:
|
||||
image_tag: '{version}'
|
||||
repo: hedgedoc/hedgedoc
|
||||
source: github
|
||||
homarr:
|
||||
image_tag: v{version}
|
||||
repo: homarr-labs/homarr
|
||||
source: github
|
||||
homebox:
|
||||
image_tag: '{version}-rootless'
|
||||
repo: sysadminsmedia/homebox
|
||||
source: github
|
||||
immich:
|
||||
image_tag: v{version}
|
||||
repo: immich-app/immich
|
||||
source: github
|
||||
kan:
|
||||
image_tag: '{version}'
|
||||
repo: kanbn/kan
|
||||
source: github
|
||||
karakeep:
|
||||
image_tag: '{version}'
|
||||
repo: karakeep-app/karakeep
|
||||
source: github
|
||||
keycloak:
|
||||
image_tag: '{version}'
|
||||
repo: keycloak/keycloak
|
||||
source: github
|
||||
leantime:
|
||||
image_tag: '{version}'
|
||||
repo: Leantime/leantime
|
||||
source: github
|
||||
linkding:
|
||||
image_tag: '{version}'
|
||||
repo: sissbruecker/linkding
|
||||
source: github
|
||||
linkwarden:
|
||||
image_tag: v{version}
|
||||
repo: linkwarden/linkwarden
|
||||
source: github
|
||||
lubelogger:
|
||||
image_tag: v{version}
|
||||
repo: hargata/lubelog
|
||||
source: github
|
||||
lychee:
|
||||
image_tag: v{version}
|
||||
repo: LycheeOrg/Lychee
|
||||
source: github
|
||||
matomo:
|
||||
image_tag: '{version}-apache'
|
||||
repo: matomo-org/matomo
|
||||
source: github
|
||||
mattermost:
|
||||
image_tag: '{version}'
|
||||
repo: mattermost/mattermost
|
||||
source: github
|
||||
mealie:
|
||||
image_tag: v{version}
|
||||
repo: mealie-recipes/mealie
|
||||
source: github
|
||||
mediawiki:
|
||||
image_tag: '{version}'
|
||||
repo: wikimedia/mediawiki
|
||||
source: github
|
||||
memos:
|
||||
image_tag: '{version}'
|
||||
repo: usememos/memos
|
||||
source: github
|
||||
metabase:
|
||||
image_tag: v{version}
|
||||
repo: metabase/metabase
|
||||
source: github
|
||||
microbin:
|
||||
image_tag: '{version}'
|
||||
repo: szabodanika/microbin
|
||||
source: github
|
||||
miniflux:
|
||||
image_tag: '{version}'
|
||||
repo: miniflux/v2
|
||||
source: github
|
||||
monica:
|
||||
image_tag: '{version}-apache'
|
||||
repo: monicahq/monica
|
||||
source: github
|
||||
nextcloud:
|
||||
image_tag: '{version}-apache'
|
||||
repo: nextcloud/server
|
||||
source: github
|
||||
notediscovery:
|
||||
image_tag: '{version}'
|
||||
repo: gamosoft/NoteDiscovery
|
||||
source: github
|
||||
ntfy:
|
||||
image_tag: v{version}
|
||||
repo: binwiederhier/ntfy
|
||||
source: github
|
||||
ocular:
|
||||
image_tag: v{version}
|
||||
repo: simonwep/ocular
|
||||
source: github
|
||||
open-dronelog:
|
||||
image_tag: '{version}'
|
||||
repo: arpanghosh8453/open-dronelog
|
||||
source: github
|
||||
open-webui:
|
||||
image_tag: v{version}
|
||||
repo: open-webui/open-webui
|
||||
source: github
|
||||
opengym:
|
||||
image_tag: '{version}'
|
||||
repo: DuarteSantos8/openGym
|
||||
source: github
|
||||
opentodo:
|
||||
image_tag: '{version}'
|
||||
repo: OpenTodoApp/OpenTodo
|
||||
source: github
|
||||
paisa:
|
||||
image_tag: v{version}
|
||||
repo: ananthakumaran/paisa
|
||||
source: github
|
||||
paperless-ngx:
|
||||
image_tag: '{version}'
|
||||
repo: paperless-ngx/paperless-ngx
|
||||
source: github
|
||||
pdfding:
|
||||
image_tag: v{version}
|
||||
repo: mrmn/PdfDing
|
||||
source: codeberg
|
||||
photoprism:
|
||||
manual: image tag '261029' doesn't follow version '2026.10.29'; the bot will not touch it
|
||||
repo: photoprism/photoprism
|
||||
source: github
|
||||
pocket-id:
|
||||
manual: image tag 'v2.19.3-distroless' doesn't follow version '2.19.3'; the bot will not touch it
|
||||
repo: pocket-id/pocket-id
|
||||
source: github
|
||||
poznote:
|
||||
image_tag: '{version}-rootless'
|
||||
repo: timothepoznanski/poznote
|
||||
source: github
|
||||
privatebin:
|
||||
image_tag: '{version}'
|
||||
repo: PrivateBin/PrivateBin
|
||||
source: github
|
||||
pwpush:
|
||||
image_tag: '{version}'
|
||||
repo: pglombardo/PasswordPusher
|
||||
source: github
|
||||
pydio-cells:
|
||||
image_tag: '{version}'
|
||||
repo: pydio/cells
|
||||
source: github
|
||||
readeck:
|
||||
image_tag: '{version}'
|
||||
repo: readeck/readeck
|
||||
source: codeberg
|
||||
rocket-chat:
|
||||
image_tag: '{version}'
|
||||
repo: RocketChat/Rocket.Chat
|
||||
source: github
|
||||
roundcube:
|
||||
image_tag: '{version}-apache-nonroot'
|
||||
repo: roundcube/roundcubemail
|
||||
source: github
|
||||
rss-bridge:
|
||||
manual: image tag '2025-08-05' doesn't follow version '2025.08.05'; the bot will not touch it
|
||||
repo: RSS-Bridge/rss-bridge
|
||||
source: github
|
||||
rsshub:
|
||||
manual: image tag '2026-11-21' doesn't follow version '2026.11.21'; the bot will not touch it
|
||||
repo: DIYgod/RSSHub
|
||||
source: github
|
||||
serpbear:
|
||||
image_tag: '{version}'
|
||||
repo: towfiqi/serpbear
|
||||
source: github
|
||||
shiori:
|
||||
image_tag: v{version}
|
||||
repo: go-shiori/shiori
|
||||
source: github
|
||||
shlink:
|
||||
image_tag: '{version}'
|
||||
repo: shlinkio/shlink
|
||||
source: github
|
||||
silverbullet:
|
||||
image_tag: '{version}-slim'
|
||||
repo: silverbulletmd/silverbullet
|
||||
source: github
|
||||
slink:
|
||||
image_tag: v{version}
|
||||
repo: andrii-kryvoviaz/slink
|
||||
source: github
|
||||
snipe-it:
|
||||
image_tag: v{version}
|
||||
repo: grokability/snipe-it
|
||||
source: github
|
||||
storyteller:
|
||||
manual: image tag 'web-v2.14.23' doesn't follow version '2.14.23'; the bot will not touch it
|
||||
repo: storyteller-platform/storyteller
|
||||
source: gitlab
|
||||
sure:
|
||||
manual: image tag '0.7.6-hotfix.2' doesn't follow version '0.7.6.2'; the bot will not touch it
|
||||
repo: we-promise/sure
|
||||
source: github
|
||||
thelounge:
|
||||
image_tag: '{version}'
|
||||
repo: thelounge/thelounge
|
||||
source: github
|
||||
traggo:
|
||||
image_tag: '{version}'
|
||||
repo: traggo/server
|
||||
source: github
|
||||
transmute:
|
||||
image_tag: '{version}'
|
||||
repo: transmute-app/transmute
|
||||
source: github
|
||||
trilium-next:
|
||||
image_tag: v{version}
|
||||
repo: TriliumNext/Trilium
|
||||
source: github
|
||||
tt-rss:
|
||||
manual: image tag '20261121-201339' doesn't follow version '20261121.201339'; the bot will not touch it
|
||||
repo: tt-rss/tt-rss
|
||||
source: github
|
||||
tududi:
|
||||
image_tag: '{version}'
|
||||
repo: chrisvel/tududi
|
||||
source: github
|
||||
twenty:
|
||||
image_tag: v{version}
|
||||
repo: twentyhq/twenty
|
||||
source: github
|
||||
umami:
|
||||
image_tag: '{version}'
|
||||
repo: umami-software/umami
|
||||
source: github
|
||||
uptime-kuma:
|
||||
image_tag: '{version}'
|
||||
repo: louislam/uptime-kuma
|
||||
source: github
|
||||
vaultwarden:
|
||||
image_tag: '{version}'
|
||||
repo: dani-garcia/vaultwarden
|
||||
source: github
|
||||
vikunja:
|
||||
image_tag: '{version}'
|
||||
repo: go-vikunja/vikunja
|
||||
source: github
|
||||
wallabag:
|
||||
image_tag: '{version}'
|
||||
repo: wallabag/wallabag
|
||||
source: github
|
||||
wealthfolio:
|
||||
image_tag: '{version}'
|
||||
repo: wealthfolio/wealthfolio
|
||||
source: github
|
||||
wekan:
|
||||
image_tag: v{version}
|
||||
repo: wekan/wekan
|
||||
source: github
|
||||
wiki-js:
|
||||
image_tag: '{version}'
|
||||
repo: requarks/wiki
|
||||
source: github
|
||||
wordpress:
|
||||
image_tag: '{version}-php8.4-apache'
|
||||
repo: WordPress/WordPress
|
||||
source: github
|
||||
Executable
+324
@@ -0,0 +1,324 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Keeps recipes on the newest upstream release.
|
||||
|
||||
scripts/bump.py infer write bump/track.yml from the recipes (run once, then review)
|
||||
scripts/bump.py audit print how far each recipe is behind upstream
|
||||
scripts/bump.py run [slug...] open one pull request per recipe that has a newer release
|
||||
DRY=1 scripts/bump.py run show what run would do, changing nothing on GitHub
|
||||
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.
|
||||
"""
|
||||
|
||||
import glob
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import urllib.request
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import yaml
|
||||
|
||||
TRACK = "bump/track.yml"
|
||||
COOLDOWN_DAYS = {"patch": 3, "minor": 3, "major": 14} # how old a release must be before we bump
|
||||
PRERELEASE = re.compile(r"(alpha|beta|rc|preview|nightly|dev|snapshot|canary|pre)", re.I)
|
||||
|
||||
|
||||
# ---- recipes ---------------------------------------------------------------------------------
|
||||
|
||||
def recipes():
|
||||
for p in sorted(glob.glob("apps/*/template.yml")):
|
||||
slug = p.split("/")[1]
|
||||
t = yaml.safe_load(open(p))
|
||||
c = yaml.safe_load(open(f"apps/{slug}/cottage.yml"))
|
||||
yield slug, str(t["x-harbor"]["version"]), c.get("upstream", ""), [i["ref"] for i in c.get("images", [])]
|
||||
|
||||
|
||||
def split_version(v):
|
||||
up, _, rev = v.rpartition("-c")
|
||||
return up, int(rev)
|
||||
|
||||
|
||||
def nums(s):
|
||||
return tuple(int(x) for x in s.split("."))
|
||||
|
||||
|
||||
def kind(cur, new):
|
||||
a, b = nums(cur), nums(new)
|
||||
if b <= a:
|
||||
return "current" if b == a else "ahead"
|
||||
if a[0] != b[0]:
|
||||
return "major"
|
||||
if (a[1:2] or (0,)) != (b[1:2] or (0,)):
|
||||
return "minor"
|
||||
return "patch"
|
||||
|
||||
|
||||
def normalize(tag):
|
||||
"""A release tag as dotted numbers, or None when it isn't a plain release."""
|
||||
t = re.sub(r"^[^0-9]*", "", tag)
|
||||
if PRERELEASE.search(tag):
|
||||
return None
|
||||
m = re.fullmatch(r"(\d{4})-(\d{2})-(\d{2})", t)
|
||||
if m:
|
||||
return ".".join(str(int(x)) for x in m.groups())
|
||||
return t if re.fullmatch(r"[0-9]+(\.[0-9]+)*", t) else None
|
||||
|
||||
|
||||
# ---- upstream releases -----------------------------------------------------------------------
|
||||
|
||||
def get_json(url, headers=None):
|
||||
req = urllib.request.Request(url, headers={"User-Agent": "cottage-catalog-bump", **(headers or {})})
|
||||
with urllib.request.urlopen(req, timeout=30) as r:
|
||||
return json.load(r)
|
||||
|
||||
|
||||
def gh_json(path):
|
||||
out = subprocess.run(["gh", "api", path], capture_output=True, text=True)
|
||||
return json.loads(out.stdout) if out.returncode == 0 else None
|
||||
|
||||
|
||||
def latest_release(source, repo):
|
||||
"""(tag, published datetime) of the newest stable release, or None."""
|
||||
items = []
|
||||
try:
|
||||
if source == "github":
|
||||
rel = gh_json(f"repos/{repo}/releases?per_page=30") or []
|
||||
items = [(r["tag_name"], r["published_at"]) for r in rel if not r["prerelease"] and not r["draft"]]
|
||||
if not items: # projects that only push tags
|
||||
tags = gh_json(f"repos/{repo}/tags?per_page=30") or []
|
||||
items = [(t["name"], None) for t in tags]
|
||||
elif source == "codeberg":
|
||||
rel = get_json(f"https://codeberg.org/api/v1/repos/{repo}/releases?limit=30")
|
||||
items = [(r["tag_name"], r["published_at"]) for r in rel if not r["prerelease"] and not r["draft"]]
|
||||
elif source == "gitlab":
|
||||
rel = get_json(f"https://gitlab.com/api/v4/projects/{repo.replace('/', '%2F')}/releases")
|
||||
items = [(r["tag_name"], r["released_at"]) for r in rel]
|
||||
except Exception as e:
|
||||
print(f" {repo}: {e}", file=sys.stderr)
|
||||
return None
|
||||
best = None
|
||||
for tag, when in items:
|
||||
n = normalize(tag)
|
||||
if n and (best is None or nums(n) > nums(best[0])):
|
||||
best = (n, tag, when)
|
||||
return best
|
||||
|
||||
|
||||
# ---- images ----------------------------------------------------------------------------------
|
||||
|
||||
def image_digest(ref):
|
||||
"""The multi-arch (index) digest of an image, or None when the tag isn't published."""
|
||||
out = subprocess.run(["docker", "buildx", "imagetools", "inspect", ref], capture_output=True, text=True)
|
||||
m = re.search(r"^Digest:\s+(sha256:[0-9a-f]{64})", out.stdout, re.M)
|
||||
return m.group(1) if m else None
|
||||
|
||||
|
||||
# ---- infer -----------------------------------------------------------------------------------
|
||||
|
||||
def infer():
|
||||
tracks = {}
|
||||
for slug, version, upstream, images in recipes():
|
||||
m = re.match(r"https://(github\.com|codeberg\.org|gitlab\.com)/([^/]+/[^/#?]+)", upstream)
|
||||
entry = {}
|
||||
if not m:
|
||||
tracks[slug] = {"skip": "no upstream repository to follow"}
|
||||
continue
|
||||
entry["source"] = {"github.com": "github", "codeberg.org": "codeberg", "gitlab.com": "gitlab"}[m.group(1)]
|
||||
entry["repo"] = re.sub(r"\.git$", "", m.group(2))
|
||||
repo, _, tag = images[0].rpartition(":")
|
||||
up, _ = split_version(version)
|
||||
if tag == up:
|
||||
fmt = "{version}"
|
||||
elif tag == "v" + up:
|
||||
fmt = "v{version}"
|
||||
elif tag.startswith(up) and re.fullmatch(r"[-.\w]*", tag[len(up):]):
|
||||
fmt = "{version}" + tag[len(up):]
|
||||
else:
|
||||
fmt = None
|
||||
if fmt is None:
|
||||
entry["manual"] = f"image tag {tag!r} doesn't follow version {up!r}; the bot will not touch it"
|
||||
else:
|
||||
entry["image_tag"] = fmt
|
||||
tracks[slug] = entry
|
||||
os.makedirs("bump", exist_ok=True)
|
||||
with open(TRACK, "w") as f:
|
||||
f.write("# What the bump bot follows for each recipe (scripts/bump.py).\n"
|
||||
"# source/repo where upstream publishes releases\n"
|
||||
"# image_tag how the first image's tag is built from the release; {version} is the\n"
|
||||
"# dotted version. Companion images (databases, caches) are never bumped.\n"
|
||||
"# manual the bot reports this recipe but never changes it\n"
|
||||
"# skip not followed at all\n")
|
||||
yaml.safe_dump(tracks, f, sort_keys=True, width=140)
|
||||
print(f"wrote {TRACK}: {len(tracks)} recipes, {sum('manual' in v for v in tracks.values())} manual, "
|
||||
f"{sum('skip' in v for v in tracks.values())} skipped")
|
||||
|
||||
|
||||
# ---- audit -----------------------------------------------------------------------------------
|
||||
|
||||
def load_track():
|
||||
return yaml.safe_load(open(TRACK))
|
||||
|
||||
|
||||
def candidates(only=()):
|
||||
track = load_track()
|
||||
for slug, version, _, images in recipes():
|
||||
if only and slug not in only:
|
||||
continue
|
||||
t = track.get(slug, {})
|
||||
cur, _ = split_version(version)
|
||||
if "skip" in t or "repo" not in t:
|
||||
yield slug, cur, None, "skip", t, images, version
|
||||
continue
|
||||
rel = latest_release(t["source"], t["repo"])
|
||||
if rel is None:
|
||||
yield slug, cur, None, "no-release", t, images, version
|
||||
continue
|
||||
yield slug, cur, rel, kind(cur, rel[0]), t, images, version
|
||||
|
||||
|
||||
def audit(only=()):
|
||||
rows = []
|
||||
for slug, cur, rel, k, t, _, _ in candidates(only):
|
||||
new = rel[0] if rel else "-"
|
||||
flag = "manual" if "manual" in t else ""
|
||||
rows.append((slug, cur, new, k, flag))
|
||||
order = {"major": 0, "minor": 1, "patch": 2}
|
||||
rows.sort(key=lambda r: (order.get(r[3], 9), r[0]))
|
||||
print(f"{'recipe':22} {'recipe is on':16} {'upstream':16} {'behind by':10} note")
|
||||
for r in rows:
|
||||
print(f"{r[0]:22} {r[1]:16} {r[2]:16} {r[3]:10} {r[4]}")
|
||||
behind = [r for r in rows if r[3] in order]
|
||||
print(f"\n{len(behind)} of {len(rows)} recipes are behind "
|
||||
f"({sum(r[3] == 'major' for r in rows)} major, {sum(r[3] == 'minor' for r in rows)} minor, "
|
||||
f"{sum(r[3] == 'patch' for r in rows)} patch)")
|
||||
|
||||
|
||||
# ---- run -------------------------------------------------------------------------------------
|
||||
|
||||
def sh(*a, check=True):
|
||||
return subprocess.run(a, capture_output=True, text=True, check=check)
|
||||
|
||||
|
||||
def apply_bump(slug, cur, new, t, images, version):
|
||||
"""Edits the recipe's files in place; returns (old_ref, new_ref, digest) or a reason string."""
|
||||
old_ref = images[0]
|
||||
repo = old_ref.rpartition(":")[0]
|
||||
new_ref = f"{repo}:{t['image_tag'].format(version=new)}"
|
||||
digest = image_digest(new_ref)
|
||||
if digest is None:
|
||||
return f"{new_ref} isn't published yet"
|
||||
tp, cp = f"apps/{slug}/template.yml", f"apps/{slug}/cottage.yml"
|
||||
tpl, cot = open(tp).read(), open(cp).read()
|
||||
if tpl.count(old_ref) < 1:
|
||||
return f"{old_ref} not found in template.yml"
|
||||
old_tag = old_ref.rpartition(":")[2]
|
||||
rest = tpl.replace(old_ref, "").replace(version, "")
|
||||
if cur in rest or old_tag in rest:
|
||||
return "the old version is used elsewhere in template.yml"
|
||||
tpl = tpl.replace(old_ref, new_ref).replace(f'version: "{version}"', f'version: "{new}-c1"')
|
||||
pat = re.compile(r"(- ref: " + re.escape(old_ref) + r"\n\s+digest: )sha256:[0-9a-f]{64}")
|
||||
if not pat.search(cot):
|
||||
return "digest line not found in cottage.yml"
|
||||
cot = pat.sub(lambda m: m.group(1) + digest, cot)
|
||||
open(tp, "w").write(tpl)
|
||||
open(cp, "w").write(cot)
|
||||
return old_ref, new_ref, digest
|
||||
|
||||
|
||||
def run(only=()):
|
||||
now = datetime.now(timezone.utc)
|
||||
sh("git", "fetch", "-q", "origin")
|
||||
if not os.environ.get("DRY"):
|
||||
for k in COOLDOWN_DAYS:
|
||||
sh("gh", "label", "create", f"bump-{k}", "--color", "0e8a16", "--description", f"Automatic {k} update", check=False)
|
||||
opened = 0
|
||||
start = sh("git", "branch", "--show-current").stdout.strip()
|
||||
for slug, cur, rel, k, t, images, version in candidates(only):
|
||||
if k not in COOLDOWN_DAYS or "manual" in t:
|
||||
if k in COOLDOWN_DAYS:
|
||||
print(f"{slug}: {cur} -> {rel[0]} needs a person ({t['manual']})")
|
||||
continue
|
||||
new, tag, when = rel
|
||||
if when:
|
||||
age = (now - datetime.fromisoformat(when.replace("Z", "+00:00"))).days
|
||||
if age < COOLDOWN_DAYS[k] and not os.environ.get("NO_COOLDOWN"):
|
||||
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() != "[]":
|
||||
print(f"{slug}: a bump pull request is already open")
|
||||
continue
|
||||
if not os.environ.get("DRY"):
|
||||
sh("git", "switch", "-q", "-C", branch, "origin/main")
|
||||
res = apply_bump(slug, cur, new, t, images, version)
|
||||
if isinstance(res, str):
|
||||
print(f"{slug}: {cur} -> {new} skipped, {res}")
|
||||
sh("git", "checkout", "-q", "--", ".")
|
||||
continue
|
||||
old_ref, new_ref, digest = res
|
||||
if os.environ.get("DRY"):
|
||||
print(f"{slug}: would open an update to {new} ({old_ref} -> {new_ref})")
|
||||
print(sh("git", "diff", "--stat").stdout)
|
||||
sh("git", "checkout", "-q", "--", ".")
|
||||
continue
|
||||
sh("git", "add", f"apps/{slug}/template.yml", f"apps/{slug}/cottage.yml")
|
||||
title = f"Update {slug} to {new}"
|
||||
body = (f"Automatic {k} update from the bump bot.\n\n- {old_ref} -> {new_ref}\n- digest `{digest}`\n"
|
||||
f"- release: https://github.com/{t['repo']}/releases/tag/{tag}" if t["source"] == "github" else
|
||||
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)
|
||||
sh("gh", "pr", "create", "--base", "main", "--head", branch, "--title", title, "--body", body,
|
||||
"--label", f"bump-{k}", check=False)
|
||||
opened += 1
|
||||
print(f"{slug}: opened {title}")
|
||||
if start and not os.environ.get("DRY"):
|
||||
sh("git", "switch", "-q", start, check=False)
|
||||
print(f"{opened} pull requests opened")
|
||||
|
||||
|
||||
# ---- guard -----------------------------------------------------------------------------------
|
||||
|
||||
def guard(base):
|
||||
"""A bump branch may only change version lines, image tags and digests."""
|
||||
files = sh("git", "diff", "--name-only", f"{base}...HEAD").stdout.split()
|
||||
bad = [f for f in files if not re.fullmatch(r"apps/[^/]+/(template|cottage)\.yml", f)]
|
||||
problems = [f"{f}: bump pull requests may only change template.yml and cottage.yml" for f in bad]
|
||||
for f in files:
|
||||
if f in bad:
|
||||
continue
|
||||
diff = sh("git", "diff", "-U0", f"{base}...HEAD", "--", f).stdout.splitlines()
|
||||
minus = [l[1:] for l in diff if l.startswith("-") and not l.startswith("---")]
|
||||
plus = [l[1:] for l in diff if l.startswith("+") and not l.startswith("+++")]
|
||||
for a, b in zip(minus, plus):
|
||||
if re.match(r'\s*version: "', a) and re.match(r'\s*version: "', b):
|
||||
continue
|
||||
if re.match(r"\s*digest: sha256:", a) and re.match(r"\s*digest: sha256:[0-9a-f]{64}$", b):
|
||||
continue
|
||||
ma = re.match(r"(\s*(?:- ref|image): )(\S+?):(\S+)$", a)
|
||||
mb = re.match(r"(\s*(?:- ref|image): )(\S+?):(\S+)$", b)
|
||||
if ma and mb and ma.group(2) == mb.group(2):
|
||||
continue # same image repository, new tag
|
||||
problems.append(f"{f}: unexpected change\n - {a.strip()}\n + {b.strip()}")
|
||||
if len(minus) != len(plus):
|
||||
problems.append(f"{f}: the change adds or removes lines")
|
||||
print("\n".join(problems) or "bump only changes versions, tags and digests")
|
||||
sys.exit(1 if problems else 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cmd, args = (sys.argv[1] if len(sys.argv) > 1 else ""), sys.argv[2:]
|
||||
if cmd == "infer":
|
||||
infer()
|
||||
elif cmd == "audit":
|
||||
audit(args)
|
||||
elif cmd == "run":
|
||||
run(args)
|
||||
elif cmd == "guard" and args:
|
||||
guard(args[0])
|
||||
else:
|
||||
sys.exit(__doc__)
|
||||
Reference in new issue
Block a user