Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 69 additions & 34 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,60 @@
name: release

# Publishing a GitHub Release (tag vX.Y.Z) is the single source of truth for a
# version bump. This workflow writes that version into both manifests and the
# changelog so they can never drift, then commits the result back to main.
# A human cuts a release by running this workflow and typing the version they
# chose. That version is written into the manifests, committed, and only then
# tagged — so the tag's tree always reports its own version. Doing it the other
# way round (tag first, bump after) leaves every tag reporting the *previous*
# version, which is why `on: release` is deliberately absent: publishing from
# the GitHub UI creates the tag before this workflow can bump anything.

on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: "Version to release, e.g. 0.2.0 (no leading v)"
description: "Version to release, e.g. 0.3.1 (no leading v)"
required: true

permissions:
contents: write

jobs:
bump:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0

- name: Resolve version from tag or input
- name: Resolve and check version
id: ver
env:
RAW: ${{ github.event.inputs.version }}
run: |
if [ "${{ github.event_name }}" = "release" ]; then
RAW="${{ github.event.release.tag_name }}"
else
RAW="${{ github.event.inputs.version }}"
fi
VERSION="${RAW#v}"
if ! echo "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::'$VERSION' is not valid semver (X.Y.Z)"
exit 1
fi
if git rev-parse -q --verify "refs/tags/v$VERSION" >/dev/null; then
echo "::error::Tag v$VERSION already exists"
exit 1
fi
PREV=$(jq -r '.version' .claude-plugin/plugin.json)
# Clients cache by the version main advertises, so a release must move
# strictly forward from it — never sideways, never backwards.
LOWEST=$(printf '%s\n%s\n' "$PREV" "$VERSION" | sort -V | head -1)
if [ "$VERSION" = "$PREV" ] || [ "$LOWEST" != "$PREV" ]; then
echo "::error::$VERSION does not come after the current version $PREV"
exit 1
fi
# The CHANGELOG compare link has to point at a tag that exists. That is
# the newest tag, not necessarily the previous manifest version — 0.3.0
# was advertised from main without ever being released.
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || true)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "prev=$PREV" >> "$GITHUB_OUTPUT"
echo "last_tag=$LAST_TAG" >> "$GITHUB_OUTPUT"
echo "date=$(date -u +%Y-%m-%d)" >> "$GITHUB_OUTPUT"

- name: Bump plugin.json
Expand All @@ -57,7 +71,7 @@ jobs:
- name: Update CHANGELOG
env:
V: ${{ steps.ver.outputs.version }}
PREV: ${{ steps.ver.outputs.prev }}
LAST_TAG: ${{ steps.ver.outputs.last_tag }}
DATE: ${{ steps.ver.outputs.date }}
REPO: ${{ github.server_url }}/${{ github.repository }}
run: |
Expand All @@ -78,7 +92,11 @@ jobs:
{
grep -v -E '^\[Unreleased\]:|^\['"$V"'\]:' CHANGELOG.md
echo "[Unreleased]: ${REPO}/compare/v${V}...HEAD"
echo "[${V}]: ${REPO}/compare/v${PREV}...v${V}"
if [ -n "$LAST_TAG" ]; then
echo "[${V}]: ${REPO}/compare/${LAST_TAG}...v${V}"
else
echo "[${V}]: ${REPO}/releases/tag/v${V}"
fi
} > tmp && mv tmp CHANGELOG.md

- name: Update README version badge
Expand All @@ -94,32 +112,49 @@ jobs:
npm install -g @anthropic-ai/claude-code
claude plugin validate .

- name: Build web-uploadable skill archive
run: |
# claude.ai's web skill uploader needs SKILL.md at the archive root,
# so zip the *contents* of each skill folder (not the folder itself).
VERSION="${{ steps.ver.outputs.version }}"
( cd skills/crowdsec && zip -r "../../crowdsec-skill-v${VERSION}.zip" . )
( cd skills/crowdsec-hub-authoring && zip -r "../../crowdsec-hub-authoring-skill-v${VERSION}.zip" . )

- name: Attach archive to the release
if: github.event_name == 'release'
- name: Commit the bump
id: commit
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${{ steps.ver.outputs.version }}"
gh release upload "${{ github.event.release.tag_name }}" \
"crowdsec-skill-v${VERSION}.zip" \
"crowdsec-hub-authoring-skill-v${VERSION}.zip" --clobber

- name: Commit bumped files
V: ${{ steps.ver.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .claude-plugin/plugin.json .claude-plugin/marketplace.json CHANGELOG.md README.md
if git diff --cached --quiet; then
echo "Nothing to commit."
else
git commit -m "chore(release): v${{ steps.ver.outputs.version }}"
git commit -m "chore(release): v${V}"
git push origin main
fi
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"

- name: Build web-uploadable skill archives
env:
V: ${{ steps.ver.outputs.version }}
run: |
# claude.ai's web skill uploader needs SKILL.md at the archive root,
# so zip the *contents* of each skill folder (not the folder itself).
( cd skills/crowdsec && zip -r "../../crowdsec-skill-v${V}.zip" . )
( cd skills/crowdsec-hub-authoring && zip -r "../../crowdsec-hub-authoring-skill-v${V}.zip" . )

- name: Tag and publish the release
env:
GH_TOKEN: ${{ github.token }}
V: ${{ steps.ver.outputs.version }}
SHA: ${{ steps.commit.outputs.sha }}
run: |
# Release notes are the CHANGELOG section this run just wrote.
awk -v pat="## [$V]" '
index($0, pat) == 1 { inside = 1; next }
inside && /^## \[/ { exit }
inside { print }
' CHANGELOG.md > "$RUNNER_TEMP/notes.md"
if [ ! -s "$RUNNER_TEMP/notes.md" ]; then
echo "See CHANGELOG.md." > "$RUNNER_TEMP/notes.md"
fi
gh release create "v${V}" \
--target "$SHA" \
--title "v${V}" \
--notes-file "$RUNNER_TEMP/notes.md" \
"crowdsec-skill-v${V}.zip" \
"crowdsec-hub-authoring-skill-v${V}.zip"
24 changes: 22 additions & 2 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: validate

# Runs on every PR and push to main: lints the plugin and asserts the two
# manifests agree on the version, so drift can never reach main.
# Runs on every PR and push to main: lints the plugin and guards the version
# field, so drift can never reach main. The release workflow is the only thing
# allowed to change that field; a PR that edits it by hand is rejected here.

on:
pull_request:
Expand All @@ -13,6 +14,25 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

# The version a human typed when cutting a release is written by
# .github/workflows/release.yml and nowhere else. A hand-edited bump in a
# PR puts main ahead of the newest tag, which is how 0.3.0 ended up
# advertised with no release behind it.
- name: Reject hand-edited version bumps
if: github.event_name == 'pull_request'
env:
BASE: ${{ github.event.pull_request.base.sha }}
run: |
BEFORE=$(git show "$BASE:.claude-plugin/plugin.json" | jq -r '.version')
AFTER=$(jq -r '.version' .claude-plugin/plugin.json)
if [ "$BEFORE" != "$AFTER" ]; then
echo "::error::This PR changes the plugin version ($BEFORE -> $AFTER). Versions are set by the release workflow; drop the change and cut a release instead."
exit 1
fi
echo "version unchanged: $AFTER"

- name: Check version consistency
run: |
Expand Down
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ When you run a doc's commands and see them work, stamp it in the same change.

| Check | Fails the build? |
|---|---|
| PR does not hand-edit the plugin version | yes |
| `plugin.json` and `marketplace.json` versions agree | yes |
| `claude plugin validate .` | yes |
| Malformed `verified:` frontmatter | yes |
Expand All @@ -35,6 +36,21 @@ Run the verification report locally with:
python3 skills/crowdsec/scripts/check-verification.py
```

## Cutting a release

Versions are set by a human at release time, never in a feature PR — CI rejects a PR that
edits the version field. Leave your notes under `[Unreleased]` in the changelog and let the
release do the rest.

To release: run the **release** workflow from the Actions tab and type the version
(`0.3.1`, no leading `v`). It writes that version into both manifests, the changelog and the
README badge, commits to `main`, and tags *that commit* — so `git show v0.3.1:.claude-plugin/plugin.json`
always reports `0.3.1`. The GitHub Release and the skill archives are created from the same
commit.

Do not publish a release from the GitHub UI. That creates the tag before the workflow can
bump anything, which is what left tags v0.1.0–v0.2.3 each reporting the previous version.

## Scope

This is an **operational** skill: install, configure, operate, debug. Authoring detection
Expand Down
Loading