Nothing runs weekly: nightly scan and updates from the homelab, Trivy after a release
This commit is contained in:
1 parent
3e8a73d3da
commit
a5e640b31b
9 files changed
+26
-466
No files matched your search
@@ -10,6 +10,8 @@ Pull requests go to a release branch or to production, never to develop.
|
|||||||
and the pull request does not come from production, develop or another release branch.
|
and the pull request does not come from production, develop or another release branch.
|
||||||
- to `production`: only from `release/vX.Y.Z`, with a version above the latest tag, a section
|
- to `production`: only from `release/vX.Y.Z`, with a version above the latest tag, a section
|
||||||
for it in CHANGELOG.md, and no "version" in composer.json (Packagist reads the tag).
|
for it in CHANGELOG.md, and no "version" in composer.json (Packagist reads the tag).
|
||||||
|
The one other way in is `renovate/*`: the nightly dependency update of the homelab (it makes no release;
|
||||||
|
the change reaches develop with the next sync).
|
||||||
|
|
||||||
Environment: BASE_REF, HEAD_REF. Run in a checkout with the tags (fetch-depth 0).
|
Environment: BASE_REF, HEAD_REF. Run in a checkout with the tags (fetch-depth 0).
|
||||||
Standard library + git only.
|
Standard library + git only.
|
||||||
@@ -34,6 +36,8 @@ def problems(base, head, existing_tags, changelog, composer):
|
|||||||
newest = semver.latest(existing_tags)
|
newest = semver.latest(existing_tags)
|
||||||
|
|
||||||
if base == "production":
|
if base == "production":
|
||||||
|
if head.startswith("renovate/"):
|
||||||
|
return []
|
||||||
version = semver.release_version(head)
|
version = semver.release_version(head)
|
||||||
if version is None:
|
if version is None:
|
||||||
return [f"A pull request to production comes from a branch named release/vX.Y.Z, not from {head or '?'}."]
|
return [f"A pull request to production comes from a branch named release/vX.Y.Z, not from {head or '?'}."]
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|||||||
import check_flow # noqa: E402
|
import check_flow # noqa: E402
|
||||||
import packagist # noqa: E402
|
import packagist # noqa: E402
|
||||||
import prune_branches # noqa: E402
|
import prune_branches # noqa: E402
|
||||||
import update_dependencies # noqa: E402
|
|
||||||
import semver # noqa: E402
|
import semver # noqa: E402
|
||||||
|
|
||||||
TAGS = ["v0.1.0", "v0.2.0", "v0.10.0", "not-a-version"]
|
TAGS = ["v0.1.0", "v0.2.0", "v0.10.0", "not-a-version"]
|
||||||
@@ -42,6 +41,10 @@ class Flow(unittest.TestCase):
|
|||||||
def test_release_to_production(self):
|
def test_release_to_production(self):
|
||||||
self.assertEqual(self.check("production", "release/v0.11.0"), [])
|
self.assertEqual(self.check("production", "release/v0.11.0"), [])
|
||||||
|
|
||||||
|
def test_production_also_takes_the_nightly_renovate_branch(self):
|
||||||
|
self.assertEqual(self.check("production", "renovate/deps-20261205"), [])
|
||||||
|
self.assertTrue(self.check("production", "renovate"))
|
||||||
|
|
||||||
def test_production_only_from_a_release_branch(self):
|
def test_production_only_from_a_release_branch(self):
|
||||||
self.assertTrue(self.check("production", "feature/x"))
|
self.assertTrue(self.check("production", "feature/x"))
|
||||||
self.assertTrue(self.check("production", "develop"))
|
self.assertTrue(self.check("production", "develop"))
|
||||||
@@ -136,75 +139,6 @@ class HermesTokens(unittest.TestCase):
|
|||||||
self.assertTrue(self.hermes.lines(per_model, "Work", "2026-12-04", "", None)[0].endswith("| 4.000 | |"))
|
self.assertTrue(self.hermes.lines(per_model, "Work", "2026-12-04", "", None)[0].endswith("| 4.000 | |"))
|
||||||
|
|
||||||
|
|
||||||
class DependencyUpdates(unittest.TestCase):
|
|
||||||
def test_only_a_release_above_the_latest_tag_is_open(self):
|
|
||||||
branches = ["develop", "production", "release/v0.1.0", "release/v0.2.0", "release/v0.3.0", "feature/x"]
|
|
||||||
self.assertEqual(update_dependencies.open_release(branches, ["v0.1.0", "v0.2.0"]), "release/v0.3.0")
|
|
||||||
self.assertIsNone(update_dependencies.open_release(branches, ["v0.3.0"]))
|
|
||||||
self.assertEqual(update_dependencies.open_release(["release/v0.1.0"], []), "release/v0.1.0")
|
|
||||||
|
|
||||||
def test_widening_adds_the_new_major_once(self):
|
|
||||||
self.assertEqual(update_dependencies.widen("^13.0", "14.2.1"), "^13.0||^14.0")
|
|
||||||
self.assertEqual(update_dependencies.widen("^12.0 || ^13.0", "14.0.0"), "^12.0 || ^13.0||^14.0")
|
|
||||||
self.assertIsNone(update_dependencies.widen("^13.0||^14.0", "14.2.1"))
|
|
||||||
self.assertEqual(update_dependencies.widen("^0.5", "0.6.3"), "^0.5||^0.6")
|
|
||||||
|
|
||||||
def test_odd_constraints_are_left_to_a_person(self):
|
|
||||||
for odd in (">=1.0", "dev-main", "*", "1.2.*"):
|
|
||||||
self.assertIsNone(update_dependencies.widen(odd, "9.0.0"))
|
|
||||||
|
|
||||||
def test_only_what_is_outside_the_constraint_changes(self):
|
|
||||||
composer = {"require": {"a/a": "^1.0", "b/b": "^2.0"}, "require-dev": {"c/c": "^3.0"}}
|
|
||||||
outdated = [
|
|
||||||
{"name": "a/a", "latest": "2.0.0", "latest-status": "update-possible"},
|
|
||||||
{"name": "b/b", "latest": "2.4.0", "latest-status": "semver-safe-update"},
|
|
||||||
{"name": "c/c", "latest": "4.1.0", "latest-status": "update-possible"},
|
|
||||||
]
|
|
||||||
changes = update_dependencies.widened(composer, outdated)
|
|
||||||
self.assertEqual(sorted(changes), ["a/a", "c/c"])
|
|
||||||
self.assertEqual(composer["require"]["a/a"], "^1.0||^2.0")
|
|
||||||
self.assertEqual(composer["require"]["b/b"], "^2.0")
|
|
||||||
self.assertEqual(composer["require-dev"]["c/c"], "^3.0||^4.0")
|
|
||||||
|
|
||||||
|
|
||||||
class NpmUpdates(unittest.TestCase):
|
|
||||||
NOW = __import__("datetime").datetime(2026, 12, 8, 12, 0, tzinfo=__import__("datetime").timezone.utc)
|
|
||||||
|
|
||||||
def published(self, ages):
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
return lambda name, version: None if (name, version) not in ages else self.NOW - datetime.timedelta(hours=ages[(name, version)])
|
|
||||||
|
|
||||||
def test_a_release_must_be_public_for_two_days(self):
|
|
||||||
outdated = {"vue": {"current": "3.5.0", "wanted": "3.5.9", "latest": "4.0.0"}}
|
|
||||||
# The newest is a day old: the newest one inside the range is taken instead.
|
|
||||||
targets = update_dependencies.npm_targets(outdated, self.published({("vue", "4.0.0"): 24, ("vue", "3.5.9"): 200}), self.NOW)
|
|
||||||
self.assertEqual(targets, {"vue": ("3.5.0", "3.5.9")})
|
|
||||||
# Both too new: nothing this week.
|
|
||||||
self.assertEqual(update_dependencies.npm_targets(outdated, self.published({("vue", "4.0.0"): 24, ("vue", "3.5.9"): 47}), self.NOW), {})
|
|
||||||
|
|
||||||
def test_the_newest_is_taken_when_it_is_old_enough(self):
|
|
||||||
outdated = {"vite": {"current": "7.0.0", "wanted": "7.1.0", "latest": "8.0.0"}}
|
|
||||||
targets = update_dependencies.npm_targets(outdated, self.published({("vite", "8.0.0"): 49}), self.NOW)
|
|
||||||
self.assertEqual(targets["vite"], ("7.0.0", "8.0.0"))
|
|
||||||
|
|
||||||
def test_a_held_back_package_stays_on_its_major(self):
|
|
||||||
outdated = {"typescript": {"current": "5.9.3", "wanted": "5.9.3", "latest": "7.0.2"}}
|
|
||||||
self.assertEqual(update_dependencies.npm_targets(outdated, self.published({("typescript", "7.0.2"): 999}), self.NOW), {})
|
|
||||||
outdated["typescript"]["wanted"] = "5.9.9"
|
|
||||||
targets = update_dependencies.npm_targets(outdated, self.published({("typescript", "7.0.2"): 999, ("typescript", "5.9.9"): 999}), self.NOW)
|
|
||||||
self.assertEqual(targets, {"typescript": ("5.9.3", "5.9.9")})
|
|
||||||
|
|
||||||
def test_unknown_dates_prereleases_and_missing_installs_are_left_alone(self):
|
|
||||||
outdated = {
|
|
||||||
"a": {"current": "1.0.0", "wanted": "1.0.0", "latest": "2.0.0"},
|
|
||||||
"b": {"current": "1.0.0", "wanted": "1.0.0", "latest": "2.0.0-beta.1"},
|
|
||||||
"c": {"wanted": "1.0.0", "latest": "2.0.0"},
|
|
||||||
}
|
|
||||||
ages = {("b", "2.0.0-beta.1"): 999, ("c", "2.0.0"): 999}
|
|
||||||
self.assertEqual(update_dependencies.npm_targets(outdated, self.published(ages), self.NOW), {})
|
|
||||||
|
|
||||||
|
|
||||||
class PackagistNotice(unittest.TestCase):
|
class PackagistNotice(unittest.TestCase):
|
||||||
def run_notice(self, answers):
|
def run_notice(self, answers):
|
||||||
"""Runs notify() with fake answers per endpoint (a status number, or an HTTP error code as a string)."""
|
"""Runs notify() with fake answers per endpoint (a status number, or an HTTP error code as a string)."""
|
||||||
|
|||||||
@@ -1,294 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""Weekly dependency update for a library: widens the version constraints of composer.json.
|
|
||||||
|
|
||||||
A package has no composer.lock, so there is nothing to bump: what can go stale is the range of
|
|
||||||
versions it accepts. When a direct dependency has a release outside its constraint (a new major,
|
|
||||||
say Laravel 14), the constraint is widened to accept it as well (`^13.0||^14.0`) and a pull request
|
|
||||||
is opened to the open release branch (`release/vX.Y.Z` above the latest tag). PR CI then tests the
|
|
||||||
new version; the pull request merges by itself when everything is green, and stays open when
|
|
||||||
it is not, so a red pull request is the signal that the package does not work with it yet.
|
|
||||||
|
|
||||||
Nothing happens when no release is open (start one first), when a pull request of this script is
|
|
||||||
still open, or when nothing is outside its constraint.
|
|
||||||
|
|
||||||
The screens have their own dependencies (`ui/package.json`, with a lock file). `update_dependencies.py ui` moves
|
|
||||||
every npm package that has a newer release (a new major too) to it, but only to a release that has been public for
|
|
||||||
48 hours (a supply-chain guard: a hijacked release is usually pulled within days), rebuilds `resources/dist`, and opens
|
|
||||||
a pull request the same way. PR CI type-checks and builds it, so a red pull request is the signal.
|
|
||||||
|
|
||||||
Environment: GT_URL, GT_OWNER, GT_REPO, GT_TOKEN (the deploy bot: pushes a branch, opens a pull
|
|
||||||
request). Needs git and composer (npm and node for `ui`). Standard library only.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import datetime
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
import tempfile
|
|
||||||
import time
|
|
||||||
import urllib.error
|
|
||||||
import urllib.request
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
import semver # noqa: E402
|
|
||||||
|
|
||||||
URL = os.environ.get("GT_URL", "").rstrip("/")
|
|
||||||
OWNER = os.environ.get("GT_OWNER", "")
|
|
||||||
REPO = os.environ.get("GT_REPO", "")
|
|
||||||
TOKEN = os.environ.get("GT_TOKEN", "")
|
|
||||||
USER = "deploy-bot"
|
|
||||||
BRANCH_PREFIX = "renovate/deps-"
|
|
||||||
UI_BRANCH_PREFIX = "renovate/ui-deps-"
|
|
||||||
MIN_AGE = datetime.timedelta(hours=48)
|
|
||||||
# npm packages held at a major until what depends on them works with the next one (remove the line then).
|
|
||||||
HELD = {"typescript": 5} # vue-tsc (the type check of the screens) does not run on TypeScript 7 yet
|
|
||||||
SECTIONS = ("require", "require-dev")
|
|
||||||
|
|
||||||
|
|
||||||
def api(method, path, body=None):
|
|
||||||
request = urllib.request.Request(
|
|
||||||
f"{URL}/api/v1/repos/{OWNER}/{REPO}/{path}",
|
|
||||||
data=json.dumps(body).encode() if body is not None else None,
|
|
||||||
method=method,
|
|
||||||
headers={"Authorization": f"token {TOKEN}", "Content-Type": "application/json"},
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
with urllib.request.urlopen(request, timeout=30) as response:
|
|
||||||
text = response.read().decode()
|
|
||||||
except urllib.error.HTTPError as e:
|
|
||||||
sys.exit(f"Gitea API {method} {path} failed: {e.code} {e.read().decode()}")
|
|
||||||
return json.loads(text) if text else None
|
|
||||||
|
|
||||||
|
|
||||||
def open_release(branches, tags):
|
|
||||||
"""The release branch that is not released yet (its version is above the latest tag); the highest one."""
|
|
||||||
newest = semver.latest(tags)
|
|
||||||
open_ones = [(semver.release_version(name), name) for name in branches]
|
|
||||||
open_ones = [(version, name) for version, name in open_ones if version and (newest is None or version > newest)]
|
|
||||||
return max(open_ones)[1] if open_ones else None
|
|
||||||
|
|
||||||
|
|
||||||
def caret(version):
|
|
||||||
"""`^14.0` for 14.2.1; `^0.6` for 0.6.3 (a caret on a 0.x version only allows the minor)."""
|
|
||||||
parts = version.lstrip("v").split(".")
|
|
||||||
return f"^{parts[0]}.{parts[1] if parts[0] == '0' else '0'}"
|
|
||||||
|
|
||||||
|
|
||||||
def widen(constraint, latest):
|
|
||||||
"""The constraint with the version of `latest` added, or None when it is (already) accepted or not a plain range."""
|
|
||||||
# Only the plain forms: a caret, a tilde or a list of those. Anything else is left to a person.
|
|
||||||
if not re.fullmatch(r"[\^~][\w.\-]+(\s*\|\|?\s*[\^~][\w.\-]+)*", constraint.strip()):
|
|
||||||
return None
|
|
||||||
|
|
||||||
added = caret(latest)
|
|
||||||
|
|
||||||
if added in constraint.replace(" ", "").split("||"):
|
|
||||||
return None
|
|
||||||
|
|
||||||
return f"{constraint.strip()}||{added}"
|
|
||||||
|
|
||||||
|
|
||||||
def widened(composer, outdated):
|
|
||||||
"""Applies the packages that `composer outdated` says have a release outside their constraint; returns what changed."""
|
|
||||||
changes = {}
|
|
||||||
|
|
||||||
for package in outdated:
|
|
||||||
name, latest = package.get("name"), package.get("latest")
|
|
||||||
|
|
||||||
if package.get("latest-status") != "update-possible" or not latest:
|
|
||||||
continue
|
|
||||||
|
|
||||||
for section in SECTIONS:
|
|
||||||
current = composer.get(section, {}).get(name)
|
|
||||||
new = widen(current, latest) if current else None
|
|
||||||
|
|
||||||
if new:
|
|
||||||
composer[section][name] = new
|
|
||||||
changes[name] = (current, new)
|
|
||||||
|
|
||||||
return changes
|
|
||||||
|
|
||||||
|
|
||||||
def npm_targets(outdated, published, now):
|
|
||||||
"""What each outdated npm package moves to: its newest release (or the newest inside its range) that is old enough.
|
|
||||||
|
|
||||||
`outdated` is `npm outdated --json` (name -> current, wanted, latest); `published(name, version)` is the time that
|
|
||||||
release came out (a datetime, or None when unknown, which counts as too new).
|
|
||||||
"""
|
|
||||||
targets = {}
|
|
||||||
|
|
||||||
for name, info in sorted(outdated.items()):
|
|
||||||
if not isinstance(info, dict) or not info.get("current"):
|
|
||||||
continue
|
|
||||||
|
|
||||||
for candidate in (info.get("latest"), info.get("wanted")):
|
|
||||||
if not candidate or candidate == info["current"] or "-" in candidate:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if name in HELD and int(candidate.split(".")[0]) > HELD[name]:
|
|
||||||
continue
|
|
||||||
|
|
||||||
when = published(name, candidate)
|
|
||||||
|
|
||||||
if when is not None and now - when >= MIN_AGE:
|
|
||||||
targets[name] = (info["current"], candidate)
|
|
||||||
break
|
|
||||||
|
|
||||||
return targets
|
|
||||||
|
|
||||||
|
|
||||||
def main_ui():
|
|
||||||
"""The same cycle for ui/: bump what is outdated and old enough, rebuild the bundle, open a pull request."""
|
|
||||||
work, release, remote = prepare(UI_BRANCH_PREFIX)
|
|
||||||
ui = os.path.join(work, "ui")
|
|
||||||
|
|
||||||
install = run(["npm", "ci", "--no-audit", "--no-fund", "--ignore-scripts"], ui, retries=3)
|
|
||||||
|
|
||||||
if install.returncode != 0:
|
|
||||||
sys.exit(f"npm ci failed:\n{install.stderr[-2000:]}")
|
|
||||||
|
|
||||||
listed = run(["npm", "outdated", "--json"], ui) # exit code 1 means "something is outdated"
|
|
||||||
outdated = json.loads(listed.stdout or "{}")
|
|
||||||
times = {}
|
|
||||||
|
|
||||||
def published(name, version):
|
|
||||||
if name not in times:
|
|
||||||
view = run(["npm", "view", name, "time", "--json"], ui, retries=2)
|
|
||||||
try:
|
|
||||||
times[name] = json.loads(view.stdout or "{}")
|
|
||||||
except ValueError:
|
|
||||||
times[name] = {}
|
|
||||||
|
|
||||||
stamp = times[name].get(version) if isinstance(times[name], dict) else None
|
|
||||||
|
|
||||||
try:
|
|
||||||
return datetime.datetime.fromisoformat(stamp.replace("Z", "+00:00")) if stamp else None
|
|
||||||
except ValueError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
targets = npm_targets(outdated, published, datetime.datetime.now(datetime.timezone.utc))
|
|
||||||
|
|
||||||
if not targets:
|
|
||||||
print("Every npm package is up to date, or too new to adopt yet: nothing to do.")
|
|
||||||
return
|
|
||||||
|
|
||||||
applied = {}
|
|
||||||
|
|
||||||
for name, (old, new) in targets.items():
|
|
||||||
result = run(["npm", "install", f"{name}@{new}", "--save-prefix=^", "--no-audit", "--no-fund", "--ignore-scripts"], ui)
|
|
||||||
|
|
||||||
if result.returncode == 0:
|
|
||||||
applied[name] = (old, new)
|
|
||||||
else:
|
|
||||||
run(["git", "checkout", "--", "ui/package.json", "ui/package-lock.json"], work)
|
|
||||||
print(f"{name} {new} does not install: left as it was.")
|
|
||||||
|
|
||||||
if not applied:
|
|
||||||
print("Nothing could be installed.")
|
|
||||||
return
|
|
||||||
|
|
||||||
# A new bundle with the new dependencies; when it does not build the pull request still opens, red, with the old bundle.
|
|
||||||
if run(["npm", "run", "build"], ui).returncode != 0:
|
|
||||||
print("The build failed with the new packages: the pull request will be red.")
|
|
||||||
|
|
||||||
publish(work, release, remote, UI_BRANCH_PREFIX, applied, "Update the dependencies of the screens", ["ui/package.json", "ui/package-lock.json", "resources/dist"])
|
|
||||||
|
|
||||||
|
|
||||||
def prepare(prefix):
|
|
||||||
"""Finds the open release, makes sure no pull request of this kind is open, and clones the release branch."""
|
|
||||||
if not (URL and OWNER and REPO and TOKEN):
|
|
||||||
sys.exit("GT_URL, GT_OWNER, GT_REPO and GT_TOKEN are required.")
|
|
||||||
|
|
||||||
branches = [item["name"] for item in api("GET", "branches?limit=50") or []]
|
|
||||||
tags = [item["name"] for item in api("GET", "tags?limit=50") or []]
|
|
||||||
release = open_release(branches, tags)
|
|
||||||
|
|
||||||
if release is None:
|
|
||||||
print("No release is open: nothing to update. Start a release first.")
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
for pull in api("GET", "pulls?state=open&limit=50") or []:
|
|
||||||
if pull["head"]["ref"].startswith(prefix):
|
|
||||||
print(f"Pull request #{pull['number']} of this workflow is still open: not making another.")
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
remote = f"https://{USER}:{TOKEN}@{URL.split('://', 1)[1]}/{OWNER}/{REPO}.git"
|
|
||||||
work = os.path.join(tempfile.mkdtemp(), "repo")
|
|
||||||
clone = subprocess.run(["git", "clone", "--quiet", "--branch", release, remote, work], capture_output=True, text=True)
|
|
||||||
|
|
||||||
if clone.returncode != 0:
|
|
||||||
sys.exit("git clone failed.")
|
|
||||||
|
|
||||||
return work, release, remote
|
|
||||||
|
|
||||||
|
|
||||||
def publish(work, release, remote, prefix, changes, title, paths):
|
|
||||||
"""Commits `paths`, pushes a branch and opens the pull request to the release."""
|
|
||||||
branch = prefix + datetime.date.today().strftime("%Y%m%d")
|
|
||||||
|
|
||||||
for command in (
|
|
||||||
["git", "config", "user.name", USER],
|
|
||||||
["git", "config", "user.email", f"{USER}@iriks-it.nl"],
|
|
||||||
["git", "checkout", "-b", branch],
|
|
||||||
["git", "add", "--", *paths],
|
|
||||||
["git", "commit", "-m", f"{title}: " + ", ".join(sorted(changes))],
|
|
||||||
["git", "push", "--quiet", "origin", branch],
|
|
||||||
):
|
|
||||||
result = subprocess.run(command, cwd=work, capture_output=True, text=True)
|
|
||||||
|
|
||||||
if result.returncode != 0:
|
|
||||||
sys.exit(f"{' '.join(command[:2])} failed: {result.stderr.strip()}")
|
|
||||||
|
|
||||||
pull = api("POST", "pulls", {"title": f"{title}: " + ", ".join(sorted(changes)), "head": branch, "base": release, "body": body(changes, release)})
|
|
||||||
print(f"Pull request #{pull['number']} to {release}: {', '.join(sorted(changes))}.")
|
|
||||||
|
|
||||||
|
|
||||||
def run(command, cwd, retries=1):
|
|
||||||
for attempt in range(1, retries + 1):
|
|
||||||
result = subprocess.run(command, cwd=cwd, capture_output=True, text=True)
|
|
||||||
|
|
||||||
if result.returncode == 0 or attempt == retries:
|
|
||||||
return result
|
|
||||||
|
|
||||||
time.sleep(attempt * 10)
|
|
||||||
|
|
||||||
|
|
||||||
def body(changes, release):
|
|
||||||
lines = "\n".join(f"- `{name}`: `{old}` → `{new}`" for name, (old, new) in sorted(changes.items()))
|
|
||||||
return f"""Automatic update of the dependencies, by the weekly workflow `Dependency updates`.
|
|
||||||
|
|
||||||
{lines}
|
|
||||||
|
|
||||||
PR CI tests the package with the newer versions (and rebuilds the screens when it is about npm). It merges into `{release}` by itself when everything is green; when it is red, the package does not work with them yet."""
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
work, release, remote = prepare(BRANCH_PREFIX)
|
|
||||||
|
|
||||||
update = run(["composer", "update", "--prefer-stable", "--prefer-dist", "--no-scripts", "--no-interaction"], work, retries=3)
|
|
||||||
|
|
||||||
if update.returncode != 0:
|
|
||||||
sys.exit(f"composer update failed:\n{update.stderr[-2000:]}")
|
|
||||||
|
|
||||||
listed = run(["composer", "outdated", "--direct", "--format=json", "--no-interaction"], work)
|
|
||||||
outdated = json.loads(listed.stdout or "{}").get("installed", [])
|
|
||||||
|
|
||||||
path = os.path.join(work, "composer.json")
|
|
||||||
composer = json.load(open(path))
|
|
||||||
changes = widened(composer, outdated)
|
|
||||||
|
|
||||||
if not changes:
|
|
||||||
print("Every direct dependency is inside its constraint: nothing to do.")
|
|
||||||
return
|
|
||||||
|
|
||||||
with open(path, "w") as file:
|
|
||||||
json.dump(composer, file, indent=4, ensure_ascii=False)
|
|
||||||
file.write("\n")
|
|
||||||
|
|
||||||
publish(work, release, remote, BRANCH_PREFIX, changes, "Dependency updates", ["composer.json"])
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main_ui() if sys.argv[1:] == ["ui"] else main()
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
name: Dependency updates
|
|
||||||
|
|
||||||
# A package has no composer.lock, so what goes stale is the range of versions it accepts. Every
|
|
||||||
# Monday this looks for a direct dependency with a release outside its constraint (a new major) and
|
|
||||||
# opens a pull request to the open release branch that accepts it as well; PR CI then tests it and the
|
|
||||||
# pull request merges by itself when it is green. The second job does the same for the npm packages of the
|
|
||||||
# screens (ui/), to a release that has been public for 48 hours, and rebuilds resources/dist. Nothing happens
|
|
||||||
# while no release is open.
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: '0 5 * * 1'
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
update:
|
|
||||||
runs-on: docker
|
|
||||||
container:
|
|
||||||
image: webdevops/php:8.4
|
|
||||||
steps:
|
|
||||||
- name: checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: cache composer downloads
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: ~/.composer/cache
|
|
||||||
key: composer-dependencies-${{ hashFiles('composer.json') }}
|
|
||||||
restore-keys: |
|
|
||||||
composer-dependencies-
|
|
||||||
|
|
||||||
- name: widen the constraints
|
|
||||||
run: python3 .gitea/scripts/update_dependencies.py
|
|
||||||
env:
|
|
||||||
COMPOSER_MAX_PARALLEL_HTTP: '4'
|
|
||||||
GT_URL: https://git.iriks.casa
|
|
||||||
GT_OWNER: iriks-it
|
|
||||||
GT_REPO: laravel-manager
|
|
||||||
GT_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
|
|
||||||
|
|
||||||
# The screens: npm packages that have a newer release (a new major too), once it has been public for 48 hours.
|
|
||||||
# The node image has git and python3; PR CI type-checks and builds the result.
|
|
||||||
ui:
|
|
||||||
runs-on: docker
|
|
||||||
container:
|
|
||||||
image: node:22-bookworm
|
|
||||||
steps:
|
|
||||||
- name: checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: update the packages of the screens
|
|
||||||
run: python3 .gitea/scripts/update_dependencies.py ui
|
|
||||||
env:
|
|
||||||
GT_URL: https://git.iriks.casa
|
|
||||||
GT_OWNER: iriks-it
|
|
||||||
GT_REPO: laravel-manager
|
|
||||||
GT_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
name: Scheduled checks
|
|
||||||
|
|
||||||
# What was released does not stay safe: new vulnerabilities are found in old dependencies. Every
|
|
||||||
# Monday the released code is checked again; a red run is the signal.
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: '30 5 * * 1'
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
audit:
|
|
||||||
runs-on: docker
|
|
||||||
container:
|
|
||||||
image: webdevops/php:8.4
|
|
||||||
steps:
|
|
||||||
- name: checkout production
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: production
|
|
||||||
|
|
||||||
- name: cache composer downloads
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: ~/.composer/cache
|
|
||||||
key: composer-scheduled-${{ hashFiles('composer.json') }}
|
|
||||||
restore-keys: |
|
|
||||||
composer-scheduled-
|
|
||||||
|
|
||||||
- name: install dependencies
|
|
||||||
env:
|
|
||||||
COMPOSER_MAX_PARALLEL_HTTP: '4'
|
|
||||||
run: |
|
|
||||||
for attempt in 1 2 3; do
|
|
||||||
composer update --prefer-stable --prefer-dist --no-scripts && exit 0
|
|
||||||
echo "composer failed (attempt $attempt of 3), trying again" >&2
|
|
||||||
sleep $((attempt * 10))
|
|
||||||
done
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
- name: composer audit
|
|
||||||
run: composer audit
|
|
||||||
|
|
||||||
@@ -15,6 +15,7 @@ between lil-koneko.com, CarsHub, iriks-it.nl and bouwbedrijf.iriks-it.nl, as one
|
|||||||
- **Pull request description.** Every pull request has the eight headings of `.gitea/PULL_REQUEST_TEMPLATE.md`, in that order (`## Vraag`, `## Wat is er gedaan`, `## Zo test je het`, `## Zelf getest`, `## Tijd en tokens`, `## Onderhoud`, `## Met de hand te doen`, `## Vervolgstappen`); a section with nothing to say gets `Niets.` or `Geen.`. Open it from a branch in Gitea or through the API, never with push options (`refs/for/…`): such a pull request gets no secrets in its jobs and its auto-merge fails.
|
- **Pull request description.** Every pull request has the eight headings of `.gitea/PULL_REQUEST_TEMPLATE.md`, in that order (`## Vraag`, `## Wat is er gedaan`, `## Zo test je het`, `## Zelf getest`, `## Tijd en tokens`, `## Onderhoud`, `## Met de hand te doen`, `## Vervolgstappen`); a section with nothing to say gets `Niets.` or `Geen.`. Open it from a branch in Gitea or through the API, never with push options (`refs/for/…`): such a pull request gets no secrets in its jobs and its auto-merge fails.
|
||||||
- **Every pull request adds its row to `TOKENS.md`** (PR CI fails without one; exempt: `release/*`, `renovate/*`, syncs). Measure it with `dev/token-usage.py LOG --since <when it began> --row "<what was made>"` (for work done by a Hermes agent: `dev/token-usage-hermes.py SESSION_ID… --include-children --hours <h> --row "…"`, from `~/.hermes/state.db`; its hours are a human figure, never invented), starting after the end of the previous row so rows do not overlap; the last cell is the hours. Never make up a row or hours, and keep no totals in the file.
|
- **Every pull request adds its row to `TOKENS.md`** (PR CI fails without one; exempt: `release/*`, `renovate/*`, syncs). Measure it with `dev/token-usage.py LOG --since <when it began> --row "<what was made>"` (for work done by a Hermes agent: `dev/token-usage-hermes.py SESSION_ID… --include-children --hours <h> --row "…"`, from `~/.hermes/state.db`; its hours are a human figure, never invented), starting after the end of the previous row so rows do not overlap; the last cell is the hours. Never make up a row or hours, and keep no totals in the file.
|
||||||
- **The two bot accounts.** `deploy-bot` is for the pipeline (`DEPLOY_TOKEN`: auto-merge, tag, release, sync). `renovate-bot` is only for Renovate: no workflow or script here uses its token, and never add a secret for it.
|
- **The two bot accounts.** `deploy-bot` is for the pipeline (`DEPLOY_TOKEN`: auto-merge, tag, release, sync). `renovate-bot` is only for Renovate: no workflow or script here uses its token, and never add a secret for it.
|
||||||
|
- **Nothing runs weekly in a repository.** Security and updates are the homelab's: Trivy every night (03:00) and after every release, the dependency round every night (04:00, branches `renovate/*`). A repository's own pipeline does `composer audit` (or the equivalent) on every pull request and on every release, and nothing on a schedule. Do not add a `schedule:` trigger; the nightly branch pruning is the one exception.
|
||||||
- **Security first.** Validate at system boundaries, never trust raw request data, and never introduce the OWASP top-10 (injection, XSS, …). This package is public: no real addresses, names, tokens or client details in code, tests, docs or defaults. In a migration a moment that may not be null is `dateTime`, never `timestamp` (the MySQL of the servers gives such a `timestamp` a default by itself and refuses a second one in a table).
|
- **Security first.** Validate at system boundaries, never trust raw request data, and never introduce the OWASP top-10 (injection, XSS, …). This package is public: no real addresses, names, tokens or client details in code, tests, docs or defaults. In a migration a moment that may not be null is `dateTime`, never `timestamp` (the MySQL of the servers gives such a `timestamp` a default by itself and refuses a second one in a table).
|
||||||
|
|
||||||
## Open decisions
|
## Open decisions
|
||||||
|
|||||||
+3
-1
@@ -35,7 +35,9 @@ the section is the text of the release in Gitea.
|
|||||||
Cloudflare Turnstile is built in (two env keys). No two-factor login in the package itself.
|
Cloudflare Turnstile is built in (two env keys). No two-factor login in the package itself.
|
||||||
- Roles of the host: `manager.permissions` (`mode` groups/host/merge, `roles` map or a `resolver` implementing `PermissionResolver`) lets a site
|
- Roles of the host: `manager.permissions` (`mode` groups/host/merge, `roles` map or a `resolver` implementing `PermissionResolver`) lets a site
|
||||||
with its own roles say what an account may do; groups stay the default.
|
with its own roles say what an account may do; groups stay the default.
|
||||||
- CI: Trivy no longer runs in the jobs (the runner disk filled up with its database). `composer audit` stays in every pull request; Trivy scans production from the homelab (nightly, and after a deploy).
|
- CI: nothing runs weekly any more, and Trivy no longer runs in the jobs (the runner disk filled up with its database). `composer audit` stays in every
|
||||||
|
pull request and every release; Trivy scans production from the homelab, every night and after every release. The nightly dependency round of the
|
||||||
|
homelab replaces the weekly *Dependency updates* workflow (and `update_dependencies.py`); its `renovate/*` pull requests may go to `production`.
|
||||||
- `manager:doctor` has a `names` check: it warns when the site uses a route name or an address of the manager and says to set `route_name` or `path`.
|
- `manager:doctor` has a `names` check: it warns when the site uses a route name or an address of the manager and says to set `route_name` or `path`.
|
||||||
|
|
||||||
## v0.4.0 - 2026-12-04
|
## v0.4.0 - 2026-12-04
|
||||||
|
|||||||
@@ -261,11 +261,21 @@ Nobody opens a pull request to `develop`, and `production` and the release branc
|
|||||||
| When | What runs |
|
| When | What runs |
|
||||||
|---|---|
|
|---|---|
|
||||||
| Pull request to a release branch or to production | *flow* (right branches, version above the latest tag, changelog section, tests of these scripts), *ledger* (`TOKENS.md`), *test* (Pint, Pest with the newest and the oldest dependencies, `composer validate`), *security* (`composer audit`: the job fails on any advisory). The check `PR CI / pr-ci` is green when all are. |
|
| Pull request to a release branch or to production | *flow* (right branches, version above the latest tag, changelog section, tests of these scripts), *ledger* (`TOKENS.md`), *test* (Pint, Pest with the newest and the oldest dependencies, `composer validate`), *security* (`composer audit`: the job fails on any advisory). The check `PR CI / pr-ci` is green when all are. |
|
||||||
| Push to production | verify (Pest, audit), tag and release, Packagist, sync develop |
|
| Push to production | verify (Pest, `composer audit`), tag and release, Packagist, sync develop; then the homelab scans production with Trivy |
|
||||||
| Every Monday | `composer audit` on production |
|
| Every night | the homelab scans every repository with Trivy (03:00) and updates its dependencies (04:00): nothing runs weekly in this repository |
|
||||||
| Every Monday | *Dependency updates*: a direct dependency with a release outside its constraint (a new major) gets its constraint widened in a pull request `renovate/deps-DATE` to the open release branch; the npm packages of the screens (`ui/`) move to their newest release that has been public for 48 hours, with a rebuilt `resources/dist`, in `renovate/ui-deps-DATE`. PR CI tests them and they merge when green. Nothing happens while no release is open. The central Trivy (every night 03:00 UTC) and Renovate (04:00 UTC) of the homelab also pass over this repo, but read a `composer.lock` and a package has none, so they find little here. |
|
|
||||||
| Every night | *Prune branches*: removes `feature/*` and `fix/*` branches whose last commit is over 30 days old and that have no open pull request (a branch of a pull request can be restored from it in Gitea) |
|
| Every night | *Prune branches*: removes `feature/*` and `fix/*` branches whose last commit is over 30 days old and that have no open pull request (a branch of a pull request can be restored from it in Gitea) |
|
||||||
|
|
||||||
|
### Security and updates
|
||||||
|
|
||||||
|
Nothing here runs on a weekly schedule; the checks hang on the moments that matter, and the homelab does the rest every night.
|
||||||
|
|
||||||
|
- **Every pull request:** `composer audit` (it fails on any advisory).
|
||||||
|
- **Every release:** `composer audit` again on the merge to `production`.
|
||||||
|
- **After every release to production:** Trivy scans `production` from the homelab (LXC 120, no database to download in a job).
|
||||||
|
- **Every night:** Trivy scans every repository of the organisation (03:00), and the dependency round (04:00) opens a pull request
|
||||||
|
`renovate/deps-DATE` straight to `production` for updates that have been public for 48 hours. PR CI tests it; it makes no release
|
||||||
|
and reaches `develop` with the next sync. A critical advisory on the installed version skips the 48 hours.
|
||||||
|
|
||||||
Secrets of the repository for this: `DEPLOY_TOKEN` (the organisation has it), and `PACKAGIST_USERNAME` and
|
Secrets of the repository for this: `DEPLOY_TOKEN` (the organisation has it), and `PACKAGIST_USERNAME` and
|
||||||
`PACKAGIST_TOKEN` (until they are set that step only says so). When Packagist does not know the package yet, that step
|
`PACKAGIST_TOKEN` (until they are set that step only says so). When Packagist does not know the package yet, that step
|
||||||
submits it through the create-package API; after that it only tells Packagist about each new tag.
|
submits it through the create-package API; after that it only tells Packagist about each new tag.
|
||||||
|
|||||||
@@ -45,3 +45,4 @@ Per stuk werk een rij; zie `dev/token-usage.py`.
|
|||||||
| 2026-12-04 | Rollen van de site naast de groepen van het pakket | - | claude-sonnet-5-5 | 3 | 5.308 | 6 | 8.235 | 921.246 | 0,01 |
|
| 2026-12-04 | Rollen van de site naast de groepen van het pakket | - | claude-sonnet-5-5 | 3 | 5.308 | 6 | 8.235 | 921.246 | 0,01 |
|
||||||
| 2026-12-04 | Controle op namen die de site al gebruikt, en de documenten van 0.5.0 rechtgezet | - | claude-sonnet-5-5 | 9 | 7.281 | 18 | 12.115 | 2.881.457 | 0,03 |
|
| 2026-12-04 | Controle op namen die de site al gebruikt, en de documenten van 0.5.0 rechtgezet | - | claude-sonnet-5-5 | 9 | 7.281 | 18 | 12.115 | 2.881.457 | 0,03 |
|
||||||
| 2026-12-04 | Trivy uit de PR-jobs (schijf van de runners vol), opruimen en wekelijkse prune | - | claude-sonnet-5-5 | 20 | 9.723 | 44 | 94.863 | 1.460.150 | 0,15 |
|
| 2026-12-04 | Trivy uit de PR-jobs (schijf van de runners vol), opruimen en wekelijkse prune | - | claude-sonnet-5-5 | 20 | 9.723 | 44 | 94.863 | 1.460.150 | 0,15 |
|
||||||
|
| 2026-12-04 | Niets meer wekelijks: nachtelijke scan en updates, Trivy na een release, docs | - | claude-sonnet-5-5 | 27 | 19.377 | 58 | 41.226 | 2.879.048 | 0,63 |
|
||||||
Reference in new issue
Block a user