diff --git a/.github/scripts/release_check.py b/.github/scripts/release_check.py new file mode 100644 index 0000000..54a24bc --- /dev/null +++ b/.github/scripts/release_check.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +"""Check that the release version is consistent, and extract its release notes. + +The version lives in three places that must agree: .claude-plugin/plugin.json ("version"), +skills/context7-add/SKILL.md (metadata.version) and a "## [X.Y.Z]" section in CHANGELOG.md. + + release_check.py check the three agree (CI runs this on every PR) + release_check.py --tag vX.Y.Z also check the tag matches the version + release_check.py --notes-out FILE write that version's CHANGELOG section to FILE + +Exit codes: 0 consistent, 1 mismatch or missing section, 2 bad input. +""" +import argparse +import json +import os +import re +import sys + +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) +SEMVER = re.compile(r"^\d+\.\d+\.\d+$") + + +def read(rel): + with open(os.path.join(ROOT, rel), encoding="utf-8") as f: + return f.read() + + +def plugin_version(): + return json.loads(read(".claude-plugin/plugin.json"))["version"] + + +def skill_version(): + text = read("skills/context7-add/SKILL.md") + front = text.split("---")[1] if text.startswith("---") else "" + m = re.search(r'^\s+version:\s*"?([^"\n]+)"?\s*$', front, re.M) + return m.group(1).strip() if m else None + + +def changelog_section(version): + """The body of '## [version] ...' up to the next '## ' heading, or None.""" + text = read("CHANGELOG.md") + m = re.search(r"^## \[" + re.escape(version) + r"\][^\n]*\n(.*?)(?=^## |^\[[^\]]+\]: |\Z)", text, re.M | re.S) + if not m: + return None + body = m.group(1).strip() + return body or None + + +def check(tag=None): + """Return (version, list of problems).""" + problems = [] + pv, sv = plugin_version(), skill_version() + if not SEMVER.match(pv or ""): + problems.append(f"plugin.json version {pv!r} is not X.Y.Z") + if sv != pv: + problems.append(f"SKILL.md metadata.version {sv!r} differs from plugin.json {pv!r}") + if changelog_section(pv) is None: + problems.append(f"CHANGELOG.md has no non-empty '## [{pv}]' section") + if tag is not None and tag != "v" + pv: + problems.append(f"tag {tag!r} does not match version v{pv}") + return pv, problems + + +def main(argv=None): + p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + p.add_argument("--tag", help="the release tag, e.g. v1.2.0 (in Actions: $GITHUB_REF_NAME)") + p.add_argument("--notes-out", metavar="FILE", help="write the version's CHANGELOG section to FILE") + args = p.parse_args(argv) + if args.tag is not None and not re.match(r"^v\d+\.\d+\.\d+$", args.tag): + print(f"tag {args.tag!r} is not vX.Y.Z", file=sys.stderr) + return 2 + version, problems = check(args.tag) + for problem in problems: + print(problem, file=sys.stderr) + if problems: + return 1 + if args.notes_out: + with open(args.notes_out, "w", encoding="utf-8") as f: + f.write(changelog_section(version) + "\n") + print(json.dumps({"version": version, "tag": args.tag, "ok": True})) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f955423 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,36 @@ +name: Release + +on: + push: + tags: ["v*.*.*"] + +permissions: + contents: write # needed to create the release + +jobs: + release: + name: Publish release + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-python@v7 + with: + python-version: "3.12" + - name: Tests (offline, API stubbed) + run: python -m unittest discover -s tests -v + - name: Check versions and extract release notes + run: python .github/scripts/release_check.py --tag "$GITHUB_REF_NAME" --notes-out notes.md + - name: Package the skill folder + run: | + cd skills + zip -r "../context7-add-${GITHUB_REF_NAME}.zip" context7-add \ + -x 'context7-add/registry.jsonl' '*/__pycache__/*' + - name: Create the GitHub release + env: + GH_TOKEN: ${{ github.token }} + run: | + gh release create "$GITHUB_REF_NAME" \ + "context7-add-${GITHUB_REF_NAME}.zip#context7-add skill folder (unzip into your agent's skills directory)" \ + --title "context7-add ${GITHUB_REF_NAME}" \ + --notes-file notes.md \ + --verify-tag diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..cd7d22c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,39 @@ +# Changelog + +All notable changes to this project. Versions follow [Semantic Versioning](https://semver.org); +each release is tagged `vX.Y.Z` and published on the +[releases page](https://github.com/saalse/context7-add/releases). + +## [1.2.0] - 2026-11-22 + +### Added +- `add` takes several URLs and validates all of them before sending any. It prints one + progress line per URL, and Ctrl-C or SIGTERM prints the partial summary (exit 130). +- `add --queue` waits for a free slot when Context7's queue of 5 submissions per user is + full (`--queue-timeout` per URL). +- `upload` checks the file size before sending, with a split hint per file type, and + `--skip-size-check` to override it. +- `--help` text for every command and flag. +- Docs: the **Upload a file** page, the **Add many sources** section, new gotchas and exit + codes. +- Offline tests (Context7 API stubbed), CI on Python 3.8 to 3.14 with skill validation and + coverage, a release workflow, and README badges. + +### Changed +- A full queue now exits 9, not 2; a 429 or a 401 stops the run. The inputs still to send + are listed in `notSubmitted`; other refusals and network errors in `failed`. +- Uploads over 4.4 MB are refused before sending (Context7 answers 413 above about 4.5 MB). +- Examples use this repo where a real source fits. + +### Fixed +- Network failures come back as JSON instead of a traceback. +- A git token is sent with repositories only, never with websites. +- `log` keeps stdout JSON when nothing has been logged. + +## [1.1.0] - 2026-11-17 + +First public version (not tagged): `whoami`, `check`, `allow`, `add`, `upload`, `refresh`, +`wait` and `log`. + +[1.2.0]: https://github.com/saalse/context7-add/releases/tag/v1.2.0 +[1.1.0]: https://github.com/saalse/context7-add/tree/a6f1fb7 diff --git a/README.md b/README.md index b9190ab..134cab1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # context7-add [![CI](https://github.com/saalse/context7-add/actions/workflows/ci.yml/badge.svg)](https://github.com/saalse/context7-add/actions/workflows/ci.yml) +[![Release](https://img.shields.io/github/v/release/saalse/context7-add)](https://github.com/saalse/context7-add/releases/latest) [![Python 3.8+](https://img.shields.io/badge/python-3.8%2B-blue)](skills/context7-add/scripts/c7.py) [![License: MIT](https://img.shields.io/github/license/saalse/context7-add)](LICENSE) [![Last commit](https://img.shields.io/github/last-commit/saalse/context7-add)](https://github.com/saalse/context7-add/commits/main) @@ -46,7 +47,8 @@ npx ctx7 skills install /saalse/context7-add context7-add ``` or copy `skills/context7-add/` into `~/.claude/skills/` (Claude Code), `~/.agents/skills/`, -or your agent's skills folder. +or your agent's skills folder. Each [release](https://github.com/saalse/context7-add/releases) +has the skill folder as a zip, for a fixed version. ## Requirements @@ -94,6 +96,21 @@ python3 -m unittest discover -s tests -v CI runs them on Python 3.8 to 3.14, validates the skill against the Agent Skills specification, and prints a coverage report. +To release a new version: + +1. Set the same version in `.claude-plugin/plugin.json` and in `metadata.version` in + `skills/context7-add/SKILL.md`, and add a `## [X.Y.Z]` section to + [CHANGELOG.md](CHANGELOG.md). CI checks that the three agree. +2. After the change is merged into `main`, tag it and push the tag: + + ```bash + git tag vX.Y.Z + git push origin vX.Y.Z + ``` + +The release workflow reruns the tests, checks that the tag matches the version, and publishes +a GitHub release with that version's changelog section and the zipped skill folder. + ## Notes - Submitting a public source adds it to Context7's public index. Use `--private` for internal diff --git a/skills/context7-add/SKILL.md b/skills/context7-add/SKILL.md index 891265a..9727e0d 100644 --- a/skills/context7-add/SKILL.md +++ b/skills/context7-add/SKILL.md @@ -7,7 +7,7 @@ metadata: author: Alex Samson homepage: https://saalse.com repository: https://github.com/saalse/context7-add - version: "1.2" + version: "1.2.0" --- # Context7: add and allow diff --git a/tests/test_release.py b/tests/test_release.py new file mode 100644 index 0000000..b1f69e8 --- /dev/null +++ b/tests/test_release.py @@ -0,0 +1,95 @@ +"""Tests for .github/scripts/release_check.py, plus a check that the repo's versions agree.""" +import contextlib +import importlib.util +import io +import json +import os +import shutil +import tempfile +import unittest + +REPO = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) +SCRIPT = os.path.join(REPO, ".github", "scripts", "release_check.py") + + +def load(): + spec = importlib.util.spec_from_file_location("release_check", SCRIPT) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def run(module, argv): + out, err = io.StringIO(), io.StringIO() + with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err): + code = module.main(argv) + return code, out.getvalue(), err.getvalue() + + +class TestThisRepo(unittest.TestCase): + """Runs on every PR: plugin.json, SKILL.md and CHANGELOG.md must agree.""" + + def test_versions_agree_and_changelog_has_the_section(self): + rc = load() + version, problems = rc.check() + self.assertEqual(problems, []) + self.assertRegex(version, r"^\d+\.\d+\.\d+$") + + def test_notes_for_the_matching_tag(self): + rc = load() + version = rc.plugin_version() + notes = os.path.join(tempfile.mkdtemp(), "notes.md") + self.addCleanup(shutil.rmtree, os.path.dirname(notes)) + code, out, _ = run(rc, ["--tag", "v" + version, "--notes-out", notes]) + self.assertEqual(code, 0) + self.assertTrue(json.loads(out)["ok"]) + with open(notes, encoding="utf-8") as f: + text = f.read() + self.assertTrue(text.strip()) + self.assertNotIn("## [", text) # only this version's section + + +class TestMismatches(unittest.TestCase): + """Runs the script against a scratch copy of the three files.""" + + def setUp(self): + self.root = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, self.root) + for rel in (".claude-plugin/plugin.json", "skills/context7-add/SKILL.md", "CHANGELOG.md"): + os.makedirs(os.path.dirname(os.path.join(self.root, rel)), exist_ok=True) + shutil.copy(os.path.join(REPO, rel), os.path.join(self.root, rel)) + self.rc = load() + self.rc.ROOT = self.root + self.version = self.rc.plugin_version() + + def rewrite(self, rel, old, new): + path = os.path.join(self.root, rel) + with open(path, encoding="utf-8") as f: + text = f.read() + self.assertIn(old, text) + with open(path, "w", encoding="utf-8") as f: + f.write(text.replace(old, new, 1)) + + def test_wrong_tag(self): + code, _, err = run(self.rc, ["--tag", "v0.0.1"]) + self.assertEqual(code, 1) + self.assertIn("does not match", err) + + def test_malformed_tag(self): + self.assertEqual(run(self.rc, ["--tag", "1.2"])[0], 2) + + def test_skill_version_differs(self): + self.rewrite("skills/context7-add/SKILL.md", f'version: "{self.version}"', 'version: "9.9.9"') + code, _, err = run(self.rc, []) + self.assertEqual(code, 1) + self.assertIn("SKILL.md", err) + + def test_missing_changelog_section(self): + self.rewrite("CHANGELOG.md", f"## [{self.version}]", "## [0.0.0]") + code, _, err = run(self.rc, []) + self.assertEqual(code, 1) + self.assertIn("CHANGELOG.md", err) + + +if __name__ == "__main__": + unittest.main()