From db2df34efc2bcf627e643163586c12c868082d42 Mon Sep 17 00:00:00 2001 From: contr Date: Fri, 23 Oct 2026 22:43:47 +0300 Subject: [PATCH] build: automate draft releases from version tags --- .github/workflows/release.yml | 50 +++++++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 1 + CHANGELOG.md | 1 + docs/UPDATING.md | 18 ++++++++++++- docs/releases/v0.1.0.md | 6 ++++- scripts/check_release.py | 47 ++++++++++++++++++++++++++++++++ tests/test_check_release.py | 46 ++++++++++++++++++++++++++++++++ 7 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 scripts/check_release.py create mode 100644 tests/test_check_release.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..86c60cb --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,50 @@ +name: Draft release +on: + push: + tags: ['v*'] +permissions: + contents: read +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: false +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-python@v5 + with: + python-version: '3.13' + - name: Validate release metadata + env: + RELEASE_TAG: ${{ github.ref_name }} + run: python scripts/check_release.py --tag "$RELEASE_TAG" + - name: Require a commit on main + run: | + git fetch origin main + git merge-base --is-ancestor HEAD origin/main + tests: + needs: validate + uses: ./.github/workflows/tests.yml + draft: + needs: [validate, tests] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - name: Create draft from curated notes + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + RELEASE_TAG: ${{ github.ref_name }} + run: | + if gh release view "$RELEASE_TAG" --json id > /dev/null 2>&1; then + echo "Release already exists; leaving it unchanged." + else + gh release create "$RELEASE_TAG" --verify-tag --draft \ + --title "Minecraft Source Kit $RELEASE_TAG" \ + --notes-file "docs/releases/$RELEASE_TAG.md" + fi diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 485f9ec..16f2ea9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,5 +1,6 @@ name: Tests on: + workflow_call: push: branches: [main] pull_request: diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c56ae2..f7b7b60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,5 +9,6 @@ See the [v0.1.0 release notes](docs/releases/v0.1.0.md) for scope and validation - Provides provenance checks against Mojang's official client metadata. Verification is explicit and required when `--verify-official` is selected. - Uses pinned decompiler tools with integrity checks, with optional conservative recovery for reported CFR failures. - Provides project checks and binding resolution for review. Setup and binding do not write to the target mod project. +- Adds tag-triggered release validation and draft creation after the reusable unit-test matrix passes; publication remains manual. - Adds `python scripts/mcsource.py --version` to identify the checked-out kit version. The kit does not update itself. - Licenses the kit's original code and documentation under `GPL-3.0-only`. diff --git a/docs/UPDATING.md b/docs/UPDATING.md index 1f32de7..bbb7d7c 100644 --- a/docs/UPDATING.md +++ b/docs/UPDATING.md @@ -41,7 +41,23 @@ To return to the prior code revision, switch to the tag or commit recorded befor Tags use `vMAJOR.MINOR.PATCH` and identify fixed release commits; published tags must not be moved. During `0.x` development, minor releases may change commands or local data formats, while patch releases are intended for compatible fixes. Release notes must identify migration requirements. A version string alone does not prove a pristine checkout or broader Minecraft compatibility. -For maintainers: finalize the changelog date, CLI version, support scope, and release notes in a reviewed PR before tagging its merged commit. Publish a matching GitHub Release after required checks complete. Do not include Minecraft inputs, reconstructed sources, or local tool caches. +For maintainers, prepare each release in a reviewed PR: + +- Set `VERSION` in `scripts/mcsource.py`. +- Add a dated changelog heading exactly as `## vX.Y.Z - YYYY-MM-DD`. +- Add `docs/releases/vX.Y.Z.md` with the heading `# vX.Y.Z` and nonempty notes. + +After the PR is merged and the successful `main` checks finish, update a clean local `main` with `git pull --ff-only`, then validate and tag the merged commit. For example, for v0.1.0: + +```text +python scripts/check_release.py --tag v0.1.0 +git tag -a v0.1.0 -m "Release v0.1.0" +git push origin v0.1.0 +``` + +The `release.yml` workflow runs for `v*` tags. It accepts only stable `vMAJOR.MINOR.PATCH` tags, checks the version, date, notes file, and that the tagged commit is on `main`, runs the existing four-job unit-test matrix, then creates a draft GitHub Release from the curated notes file. Review the draft and publish it manually; select Latest manually as appropriate. Never move a tag. If a workflow run fails, inspect it and rerun the same tag workflow after a transient failure; content corrections require a new corrected release tag and version. Do not poll CI from an agent; report the pending run for the user to check. A rerun skips release creation if that release already exists. GitHub's standard source ZIP and tar archives are the only source archives; do not add custom binaries or Minecraft caches. + +Do not include Minecraft inputs, reconstructed sources, or local tool caches. ## Agent update request diff --git a/docs/releases/v0.1.0.md b/docs/releases/v0.1.0.md index f2732a6..bcde52c 100644 --- a/docs/releases/v0.1.0.md +++ b/docs/releases/v0.1.0.md @@ -10,7 +10,7 @@ Minecraft Source Kit is a local, agent-guided reference workflow. It inspects a - `prepare` generates a reference. `--repair` optionally attempts conservative recovery for CFR-reported classes. Standalone `repair` handles an existing kit reference after verifying the original input hash. - `bind` records a local project binding; `resolve` checks it and reports the reference location. -See the [updating guide](../UPDATING.md) for installation and upgrade instructions. The kit requires Python 3.10+, Git, and a full JDK capable of reading the input bytecode; the Java runtime and compiler must have matching major versions. +See the [updating guide](https://github.com/Lightre/minecraft-source-kit/blob/v0.1.0/docs/UPDATING.md) for installation and upgrade instructions. The kit requires Python 3.10+, Git, and a full JDK capable of reading the input bytecode; the Java runtime and compiler must have matching major versions. ## Validation and limits @@ -18,6 +18,10 @@ Full preparation was exercised with Minecraft 26.2 on Windows using Python 3.13 Successful generation does not establish decompiled-source correctness, behavioral equivalence, or runtime and Mixin correctness. Decompiled sources are reconstructed and unverified. Review reference reports and validate behavior separately as needed. +## Release process + +Stable version tags trigger metadata validation and the four-job unit-test matrix before a draft release is created from these curated notes. Publication remains manual. Existing releases are preserved on reruns. + ## Distribution and license Users supply their own Minecraft JARs. The release bundles no Minecraft materials, generated sources, or binary artifacts. The kit's original code and documentation use `GPL-3.0-only`; external tools and Minecraft materials retain their own licenses and terms. diff --git a/scripts/check_release.py b/scripts/check_release.py new file mode 100644 index 0000000..a4a8377 --- /dev/null +++ b/scripts/check_release.py @@ -0,0 +1,47 @@ +"""Validate curated metadata for a stable kit release without network access.""" +import argparse +import ast +from datetime import date +from pathlib import Path +import re + +ROOT = Path(__file__).resolve().parents[1] + + +def check_release(root, tag): + if not re.fullmatch(r"v(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)", tag): + raise ValueError("Release tag must use stable vMAJOR.MINOR.PATCH format") + root = Path(root) + tree = ast.parse((root / "scripts/mcsource.py").read_text(encoding="utf-8")) + versions = [node.value.value for node in tree.body + if isinstance(node, ast.Assign) + and any(isinstance(target, ast.Name) and target.id == "VERSION" for target in node.targets) + and isinstance(node.value, ast.Constant) and isinstance(node.value.value, str)] + if versions != [tag[1:]]: + raise ValueError("Release tag does not match the CLI VERSION constant") + changelog = (root / "CHANGELOG.md").read_text(encoding="utf-8") + entries = re.findall(r"^## " + re.escape(tag) + r" - (.+)$", changelog, re.MULTILINE) + if len(entries) != 1 or not re.fullmatch(r"[0-9]{4}-[0-9]{2}-[0-9]{2}", entries[0]): + raise ValueError("Changelog must contain exactly one dated heading for this release") + date.fromisoformat(entries[0]) + notes = root / "docs/releases" / (tag + ".md") + lines = notes.read_text(encoding="utf-8").strip().splitlines() + if not lines or lines[0] != "# " + tag or not any(line.strip() for line in lines[1:]): + raise ValueError("Release notes require the matching title and a nonempty body") + return notes + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--tag", required=True, help="Stable release tag to validate") + args = parser.parse_args() + try: + notes = check_release(ROOT, args.tag) + except (OSError, ValueError, SyntaxError) as error: + parser.exit(1, f"Release validation failed: {error}\n") + print(f"Release metadata validated: {args.tag} ({notes.relative_to(ROOT).as_posix()})") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tests/test_check_release.py b/tests/test_check_release.py new file mode 100644 index 0000000..63ffadc --- /dev/null +++ b/tests/test_check_release.py @@ -0,0 +1,46 @@ +import sys +import tempfile +import unittest +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) +from check_release import check_release + + +class ReleaseTests(unittest.TestCase): + def setUp(self): + self.temp = tempfile.TemporaryDirectory() + self.addCleanup(self.temp.cleanup) + self.root = Path(self.temp.name) + (self.root / "scripts").mkdir() + (self.root / "docs/releases").mkdir(parents=True) + (self.root / "scripts/mcsource.py").write_text('VERSION = "0.1.0"\n', encoding="utf-8") + (self.root / "CHANGELOG.md").write_text("## v0.1.0 - 2026-10-23\n", encoding="utf-8") + self.notes = self.root / "docs/releases/v0.1.0.md" + self.notes.write_text("# v0.1.0\n\nInitial release.\n", encoding="utf-8") + + def test_matching_metadata(self): + self.assertEqual(check_release(self.root, "v0.1.0"), self.notes) + + def test_unsupported_tag_and_version_mismatch(self): + for tag in ("v0.1.0-rc1", "v01.1.0", "../notes", "v0.2.0"): + with self.subTest(tag=tag), self.assertRaises(ValueError): + check_release(self.root, tag) + + def test_dated_changelog_required(self): + for text in ("## v0.1.0 - Unreleased", "## v0.1.0 - 2026-02-30", + "## v0.1.0 - 2026-10-23\n## v0.1.0 - 2026-10-24"): + with self.subTest(text=text): + (self.root / "CHANGELOG.md").write_text(text, encoding="utf-8") + with self.assertRaises(ValueError): + check_release(self.root, "v0.1.0") + + def test_missing_wrong_or_empty_notes_rejected(self): + for text in ("# v0.2.0\nNotes", "# v0.1.0\n\n", ""): + with self.subTest(text=text): + self.notes.write_text(text, encoding="utf-8") + with self.assertRaises(ValueError): + check_release(self.root, "v0.1.0") + self.notes.unlink() + with self.assertRaises(FileNotFoundError): + check_release(self.root, "v0.1.0")