diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..66aac69 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,31 @@ +name: Release +on: + schedule: + - cron: '17 * * * *' + workflow_dispatch: + inputs: + force: + description: Release now, skipping the 3 hour quiet period + type: boolean + default: false +concurrency: + group: release + cancel-in-progress: false +permissions: + contents: write +jobs: + release: + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - run: | + git config user.name 'github-actions[bot]' + git config user.email '41898282+github-actions[bot]@users.noreply.github.com' + bash scripts/release.sh + env: + GH_TOKEN: ${{ github.token }} + CATALOG_TOKEN: ${{ secrets.CATALOG_TOKEN }} + FORCE: ${{ inputs.force }} diff --git a/README.md b/README.md index 1ffdccb..f94b383 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,14 @@ hermes config set skills.external_dirs '["plugins/pstack/skills"]' Hermes loads it on next session start. +## Releasing + +Bump `version` in `plugin.yaml` in every PR, as CI requires. Nothing else is manual. + +`.github/workflows/release.yml` runs hourly. Once the `plugin.yaml` version on `main` has no GitHub release and `main` has been quiet for 3 hours, it tags that commit, publishes a release with generated notes, and opens (or updates) the `plugin-catalog/pstack.yaml` bump PR on `NousResearch/hermes-agent`. Several merges in one burst produce one release for the latest. To release immediately, use Actions, Release, Run workflow, with `force` checked. + +The catalog PR needs a `CATALOG_TOKEN` repository secret: a classic personal access token from Cloeille with the `public_repo` scope. Without it the workflow still tags and releases, and logs a warning. To preview a run, use `DRY_RUN=1 bash scripts/release.sh`. + ## License MIT diff --git a/plugin.yaml b/plugin.yaml index 069e506..332f136 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,4 +1,4 @@ name: pstack -version: "0.3.3" +version: "0.3.4" description: "Poteto's engineering rigor stack. Playbooks, principles, multi-model review." author: poteto (adapted by Madeleine) diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..449f10c --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,141 @@ +#!/usr/bin/env bash +# Tag and release the plugin.yaml version at HEAD, then open or update the Hermes catalog PR. +# +# A version counts as released once its GitHub release exists, so a run that failed after +# tagging resumes where it stopped. A failed catalog step is retried with FORCE=true. +# +# Env: FORCE=true skip the quiet-period wait; on a released version, rerun the catalog step only +# DEBOUNCE_HOURS=3 quiet period HEAD must have survived before releasing +# CATALOG_TOKEN classic PAT (public_repo) from Cloeille; without it the catalog step is skipped +# DRY_RUN=1 print every mutating command instead of running it +set -euo pipefail + +UPSTREAM=NousResearch/hermes-agent +FORK=Cloeille/hermes-agent +FILE=plugin-catalog/pstack.yaml +SELF=https://github.com/Cloeille/pstack +TITLE_PREFIX='chore(plugin-catalog): bump pstack' + +run() { + if [ "${DRY_RUN:-}" = 1 ]; then + printf '[dry-run]' + printf ' %q' "$@" + echo + else + "$@" + fi +} + +field() { sed -nE "s/^$2: \"?([^\"]*)\"?\$/\\1/p" "$1"; } + +VERSION=$(git show HEAD:plugin.yaml | + sed -nE "s/^version:[[:space:]]*[\"']?([0-9]+\.[0-9]+\.[0-9]+)[\"']?[[:space:]]*\$/\1/p") +[ -n "$VERSION" ] || { echo "plugin.yaml: no MAJOR.MINOR.PATCH version found" >&2; exit 1; } +git fetch --tags --quiet origin + +released() { gh release view "$VERSION" >/dev/null 2>&1; } + +if [ "${FORCE:-}" != true ] && released; then + echo "already released: $VERSION" + exit 0 +fi + +if git rev-parse -q --verify "refs/tags/$VERSION" >/dev/null; then + SHA=$(git rev-parse "$VERSION^{commit}") +else + SHA=$(git rev-parse HEAD) + age=$(( $(date +%s) - $(git log -1 --format=%ct HEAD) )) + limit=$(( ${DEBOUNCE_HOURS:-3} * 3600 )) + if [ "${FORCE:-}" != true ] && [ "$age" -lt "$limit" ]; then + echo "waiting: HEAD is $((age / 60)) min old, releasing $VERSION after $((limit / 60)) min of quiet" + exit 0 + fi + python3 scripts/check_refs.py + run git tag -a "$VERSION" -m "$VERSION" "$SHA" + run git push origin "refs/tags/$VERSION" +fi + +released || run gh release create "$VERSION" --verify-tag --title "$VERSION" --generate-notes --latest + +if [ -z "${CATALOG_TOKEN:-}" ]; then + echo "::warning::CATALOG_TOKEN is not set, skipping the Hermes catalog PR for $VERSION" + exit 0 +fi +export GH_TOKEN=$CATALOG_TOKEN + +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT + +raw=(-H 'Accept: application/vnd.github.raw+json') +gh api "${raw[@]}" "repos/$UPSTREAM/contents/$FILE?ref=main" >"$tmp/main.yaml" +old_sha=$(field "$tmp/main.yaml" sha) +old_version=$(field "$tmp/main.yaml" version) +if [ "$old_sha" = "$SHA" ]; then + echo "catalog already pins $SHA" + exit 0 +fi + +pr_number='' branch="chore/plugin-catalog-pstack-$VERSION" +found=$(gh pr list -R "$UPSTREAM" --author Cloeille --state open \ + --json number,headRefName,title \ + --jq "[.[] | select(.title | startswith(\"$TITLE_PREFIX\"))][0] // empty | \"\\(.number) \\(.headRefName)\"") +[ -z "$found" ] || read -r pr_number branch <<<"$found" + +# Edit the file where the PUT lands: a reused branch keeps its earlier edits, a new one starts from main. +src="repos/$UPSTREAM/contents/$FILE?ref=main" +if gh api "repos/$FORK/git/ref/heads/$branch" >/dev/null 2>&1; then + src="repos/$FORK/contents/$FILE?ref=$branch" +else + main_sha=$(gh api "repos/$UPSTREAM/git/ref/heads/main" --jq .object.sha) + run gh api "repos/$FORK/git/refs" -f "ref=refs/heads/$branch" -f "sha=$main_sha" +fi +blob=$(gh api "$src" --jq .sha) +gh api "${raw[@]}" "$src" >"$tmp/base.yaml" +sed -E "s/^sha: .*/sha: $SHA/; s/^version: .*/version: \"$VERSION\"/" "$tmp/base.yaml" >"$tmp/new.yaml" +[ "$(field "$tmp/new.yaml" sha)" = "$SHA" ] && [ "$(field "$tmp/new.yaml" version)" = "$VERSION" ] || + { echo "$FILE: missing sha or version line" >&2; exit 1; } +diff -u "$tmp/main.yaml" "$tmp/new.yaml" || true + +title="$TITLE_PREFIX entry sha to $VERSION" +cmp -s "$tmp/base.yaml" "$tmp/new.yaml" || + run gh api -X PUT "repos/$FORK/contents/$FILE" -f "message=$title" -f "branch=$branch" \ + -f "sha=$blob" -f "content=$(base64 -w0 "$tmp/new.yaml")" + +cat >"$tmp/body.md" <