chore: add the fleet package template files this repo is missing (git-release.yml, release-notify.yml, release.yml, AGENTS.md, CLAUDE.md) (#42)

* chore: add the fleet package template files this repo is missing (git-release.yml, release-notify.yml, release.yml, AGENTS.md, CLAUDE.md)

Files from bitbaum/fleet `templates/package` that this repository does not have yet:

- `.github/workflows/git-release.yml`
- `.github/workflows/release-notify.yml`
- `.github/workflows/release.yml`
- `AGENTS.md`
- `CLAUDE.md`

Only missing files are added — no file this repository already has is changed. `release.yml` is what lets the package owner release a new version from Loki (the package page: "Release vX.Y.Z"), or from the Actions tab.

Opened by bitbaum/fleet `scripts/packages/sync-package-template.mjs` (`.github/workflows/package-repos.yml`). It merges itself when this repository's CI is green.

* chore: current release.yml template, prettier-stable under this repo's config

---------

Co-authored-by: bitbaum-fleet <fleet@bitbaum.invalid>
This commit is contained in:
Catoandbitbaum-fleet authored and GitHub committed 2026-10-28 02:30:17 +01:00
1 parent 8d2ef7f9a4
commit bfb969cb5b
4 files changed
+314

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
name: Verified Git release
on:
workflow_run:
workflows: [CI]
types: [completed]
branches: [main]
permissions:
contents: write
concurrency:
group: verified-git-release
cancel-in-progress: false
jobs:
release:
if: >-
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_repository.full_name == github.repository &&
github.event.workflow_run.head_branch == 'main' &&
github.event.workflow_run.event != 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.event.workflow_run.head_sha }}
fetch-depth: 0
- name: Tag the verified immutable artifact, even before npm bootstrap
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERIFIED_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
set -euo pipefail
version=$(node -p "require('./package.json').version")
if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Only stable package versions get a Git release" >&2
exit 1
fi
tag="v$version"
if git show-ref --verify --quiet "refs/tags/$tag"; then
echo "$tag already exists; immutable tags are never moved."
exit 0
fi
git tag "$tag" "$VERIFIED_SHA"
git push origin "refs/tags/$tag"
gh release create "$tag" --repo "$GITHUB_REPOSITORY" \
--verify-tag --title "$tag" --generate-notes
+55
View File
@@ -0,0 +1,55 @@
# A release is useful only when the registry and consumers learn about it.
# No checkout or execution of the completed workflow's code: metadata only.
name: Notify Fleet of verified release
on:
workflow_run:
workflows: [CI, Release, Publish]
types: [completed]
permissions:
contents: read
actions: read
concurrency:
group: release-notify
cancel-in-progress: false
jobs:
notify:
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event != 'pull_request' && github.event.workflow_run.head_repository.full_name == github.repository
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Resolve a verified immutable release before requesting reconciliation
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
SHA: ${{ github.event.workflow_run.head_sha }}
FLEET_TOKEN: ${{ secrets.FLEET_PAT }}
shell: bash
run: |
set -euo pipefail
manifest="$(gh api "repos/$GH_REPO/contents/package.json?ref=$SHA" --jq .content | base64 --decode)"
version="$(jq -r .version <<< "$manifest")"
if [[ ! "$version" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
echo 'No stable version; no reconciliation requested.'
exit 0
fi
# Source commits with no matching release tag are not releases.
if ! tagged="$(gh api "repos/$GH_REPO/commits/v$version" --jq .sha 2>/dev/null)" || [ "$tagged" != "$SHA" ]; then
echo 'This commit is not the versioned release; no reconciliation requested.'
exit 0
fi
ci="$(gh api "repos/$GH_REPO/actions/runs?head_sha=$SHA&per_page=100" --jq '[.workflow_runs[] | select(.path == ".github/workflows/ci.yml" and (.event == "push" or .event == "workflow_dispatch"))] | first | .conclusion')"
if [ "$ci" != success ]; then
echo 'Release CI is not successful yet; its completion will retry notification.'
exit 0
fi
if [ -z "$FLEET_TOKEN" ]; then
echo '::error::FLEET_PAT is required to notify Fleet; scheduled reconciliation remains the fallback.'
exit 1
fi
payload="$(jq -n --arg repository "$GH_REPO" --arg version "$version" --arg commit "$SHA" '{event_type:"shared-package-release",client_payload:{repository:$repository,version:$version,commit:$commit}}')"
GH_TOKEN="$FLEET_TOKEN" gh api --method POST repos/bitbaum/fleet/dispatches --input - <<< "$payload"
echo "Requested authoritative registry and consumer reconciliation for $GH_REPO v$version ($SHA)." >> "$GITHUB_STEP_SUMMARY"
+213
View File
@@ -0,0 +1,213 @@
# Release — a new version of this package, from one button.
#
# Rendered from bitbaum/fleet templates/package. Loki's package page starts it
# ("Release vX.Y.Z"), and so can anyone from the Actions tab. It:
#
# 1. refuses unless main's CI is green on the exact commit it starts from,
# 2. raises the version in package.json (the bump, or the exact version
# asked for) — `npm version --no-git-tag-version`, so npm makes no commit
# and no tag of its own,
# 3. runs the package's own `verify`, which rebuilds the committed dist/,
# 4. commits "release vX.Y.Z" with the rebuilt dist/, tags vX.Y.Z, and pushes
# both in one atomic push,
# 5. creates a GitHub release with generated notes.
#
# Consumers pick the tag up through Dependabot (`github:bitbaum/{{name}}#vX.Y.Z`),
# and publish.yml ships it to npm once npm publishing is switched on.
#
# WHY THE PUSH USES FLEET_PAT. A push made with GITHUB_TOKEN starts no workflow.
# publish.yml listens for the tag push, and CI must run on the release commit
# (the auto-merge sweep merges nothing onto a main whose CI it cannot see). So
# the release commit and tag are pushed with FLEET_PAT, the org secret every
# bitbaum repo already has (auto-merge.yml passes it to the sweep), and both
# workflows fire exactly as they would for a person's push. Calling publish.yml
# from here instead was the other option and is not the honest one: package
# repos keep the publish.yml they were created with (the template sync adds
# missing files and never rewrites one), so the tag push is the only path every
# repo's publish.yml is guaranteed to answer. No FLEET_PAT → no release, said
# plainly, rather than a tag that silently publishes nothing.
#
# If main is ever protected against direct pushes, FLEET_PAT's identity must be
# allowed to bypass it, or this fails at the push — after verify, before any
# tag exists, so nothing half-ships.
# prettier-ignore
name: Release
run-name: Release ${{ inputs.version != '' && format('v{0}', inputs.version) || inputs.bump }}
on:
workflow_dispatch:
inputs:
bump:
description: Which part of the version to raise (ignored when an exact version is given)
type: choice
options: [patch, minor, major]
default: patch
version:
description: Exact version to release, e.g. 0.3.0 (optional — wins over bump)
type: string
required: false
default: ""
# One release at a time, never cancelled: a cancelled release is a commit
# without its tag, or a tag without its notes.
concurrency:
group: release
cancel-in-progress: false
permissions:
contents: write # the GitHub release (the push itself uses FLEET_PAT)
actions: read # main's CI runs
checks: read
jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Only from main
run: |
if [ "$GITHUB_REF" != "refs/heads/main" ]; then
echo "::error::A release starts from main, not $GITHUB_REF."
exit 1
fi
- name: FLEET_PAT is available
env:
PAT: ${{ secrets.FLEET_PAT }}
run: |
if [ -z "$PAT" ]; then
echo "::error::FLEET_PAT is not available to this repo. A tag pushed without it starts no workflow, so publish.yml would never run — refusing instead."
exit 1
fi
# The commit this run would release is github.sha: main's head when the
# run was started. Its CI must have FINISHED green — running is not green,
# and no run at all is not green either.
- name: Main's CI is green on this commit
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
SHA: ${{ github.sha }}
run: |
set -euo pipefail
run="$(gh run list --workflow ci.yml --branch main --commit "$SHA" --limit 1 \
--json status,conclusion,url --jq '.[0] // empty')"
if [ -z "$run" ]; then
echo "::error::CI has not run on main at ${SHA:0:7}. Nothing proves this commit works, so it is not released."
exit 1
fi
status="$(jq -r .status <<<"$run")"
conclusion="$(jq -r .conclusion <<<"$run")"
url="$(jq -r .url <<<"$run")"
if [ "$status" != "completed" ]; then
echo "::error::CI is still running on ${SHA:0:7} ($url). Start the release again when it finishes."
exit 1
fi
if [ "$conclusion" != "success" ]; then
echo "::error::CI on ${SHA:0:7} ended '$conclusion' ($url). Fix main first; a red commit is not released."
exit 1
fi
echo "CI on ${SHA:0:7} is green: $url"
- uses: actions/checkout@v7
with:
ref: ${{ github.sha }}
token: ${{ secrets.FLEET_PAT }}
fetch-depth: 0
fetch-tags: true
# pnpm version comes from "packageManager" in package.json (SSOT).
- uses: pnpm/action-setup@v6
- uses: actions/setup-node@v7
with:
node-version: "24"
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Install Chromium when the package uses Playwright
run: |
if node -e 'const p = require("./package.json"); const d = { ...p.dependencies, ...p.devDependencies }; process.exit(d.playwright || d["@playwright/test"] ? 0 : 1)'; then
pnpm exec playwright install --with-deps chromium
fi
# Inputs reach the shell as environment variables, never pasted into the
# script: a `version` is free text typed by whoever started the run.
- name: Decide the version
id: version
env:
BUMP: ${{ inputs.bump }}
EXACT: ${{ inputs.version }}
run: |
set -euo pipefail
next="$(node -e '
const cur = require("./package.json").version;
const bump = process.env.BUMP, exact = process.env.EXACT.trim().replace(/^v/, "");
const parse = (v) => /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.exec(v)?.slice(1).map(Number);
const c = parse(cur);
if (!c) { console.error(`package.json version "${cur}" is not x.y.z`); process.exit(1); }
let n;
if (exact) {
n = parse(exact);
if (!n) { console.error(`"${exact}" is not a version like 0.3.0`); process.exit(1); }
} else if (bump === "major") n = [c[0] + 1, 0, 0];
else if (bump === "minor") n = [c[0], c[1] + 1, 0];
else if (bump === "patch") n = [c[0], c[1], c[2] + 1];
else { console.error(`bump must be patch, minor or major, not "${bump}"`); process.exit(1); }
const cmp = n[0] - c[0] || n[1] - c[1] || n[2] - c[2];
if (cmp <= 0) { console.error(`${n.join(".")} is not newer than ${cur}`); process.exit(1); }
console.log(n.join("."));
')"
if git rev-parse -q --verify "refs/tags/v$next" >/dev/null \
|| [ -n "$(git ls-remote --tags origin "refs/tags/v$next")" ]; then
echo "::error::v$next is already tagged. Nothing to do — Loki shows it on the next read."
exit 1
fi
echo "next=$next" >> "$GITHUB_OUTPUT"
echo "Releasing v$next (package.json was $(node -p 'require("./package.json").version'))."
- name: Raise the version
env:
NEXT: ${{ steps.version.outputs.next }}
run: npm version "$NEXT" --no-git-tag-version
# The package's own gate. It rebuilds dist/, which is committed so a
# `github:` install needs no build step.
- run: pnpm run verify
- name: Commit, tag and push
env:
NEXT: ${{ steps.version.outputs.next }}
run: |
set -euo pipefail
# Only the version and the build it implies may change. Anything else
# means verify rewrote source, and that is a change to review, not to
# release.
stray="$(git status --porcelain --untracked-files=all | awk '{print $2}' | grep -v -E '^(package\.json|dist/)' || true)"
if [ -n "$stray" ]; then
echo "::error::verify changed files outside package.json and dist/: $stray"
exit 1
fi
git config user.name "bitbaum-fleet"
git config user.email "fleet@bitbaum.invalid"
git add package.json dist
git commit -q -m "release v$NEXT"
git tag -a "v$NEXT" -m "v$NEXT"
# Atomic: the commit and the tag land together or not at all. A main
# that moved since this run started refuses the push (not a fast
# forward), and the release is simply started again.
git push --atomic origin "HEAD:refs/heads/main" "refs/tags/v$NEXT"
- name: GitHub release
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
NEXT: ${{ steps.version.outputs.next }}
run: |
set -euo pipefail
gh release create "v$NEXT" --verify-tag --title "v$NEXT" --generate-notes
{
echo "## Released v$NEXT"
echo
echo "Install: \`github:$GITHUB_REPOSITORY#v$NEXT\`. Dependabot proposes it to every project that uses this package."
} >> "$GITHUB_STEP_SUMMARY"
+1
View File
@@ -0,0 +1 @@
Read and follow [AGENTS.md](AGENTS.md).