From dd3d98752194662bb25ca07b3eceb67c3d668aa2 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 6 Nov 2026 16:06:01 -0500 Subject: [PATCH] feat: allow a custom draft release tag prefix (#159) --- actions/draft-release/action.yml | 6 +++++- tests/test_release_tag_prefix.py | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/test_release_tag_prefix.py diff --git a/actions/draft-release/action.yml b/actions/draft-release/action.yml index 1e91b24..cb7d0e9 100644 --- a/actions/draft-release/action.yml +++ b/actions/draft-release/action.yml @@ -15,6 +15,9 @@ inputs: github-token: description: "GitHub token for authenticating gh CLI" required: true + tag-prefix: + description: "Release tag prefix" + default: "v" signing-key: description: "ASCII-armored OpenPGP secret key (LINUX_SIGNING_KEY) that signs the Linux packages and SHA256SUMS.txt; empty publishes them unsigned" required: false @@ -72,13 +75,14 @@ runs: shell: bash working-directory: artifacts env: + TAG_PREFIX: ${{ inputs.tag-prefix }} VERSION: ${{ inputs.version }} APP_TITLE: ${{ inputs.app-title }} PRERELEASE: ${{ inputs.prerelease }} GH_TOKEN: ${{ inputs.github-token }} GH_REPO: ${{ github.repository }} run: | - tag="v$VERSION" + tag="${TAG_PREFIX}$VERSION" title="$APP_TITLE v$VERSION" pre=() if [ "$PRERELEASE" = "true" ]; then pre=(--prerelease); fi diff --git a/tests/test_release_tag_prefix.py b/tests/test_release_tag_prefix.py new file mode 100644 index 0000000..cafe302 --- /dev/null +++ b/tests/test_release_tag_prefix.py @@ -0,0 +1,33 @@ +"""Exercise draft release tag selection without contacting GitHub.""" +import json +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + +import yaml + + +class ReleaseTagPrefixTests(unittest.TestCase): + def test_default_and_custom_tags(self): + action = yaml.load( + (Path(__file__).resolve().parents[1] / "actions/draft-release/action.yml").read_text(), + Loader=yaml.BaseLoader, + ) + step = next(s for s in action["runs"]["steps"] if s["name"] == "Create or update draft release") + self.assertEqual(step["env"]["TAG_PREFIX"], "${{ inputs.tag-prefix }}") + for prefix in (action["inputs"]["tag-prefix"]["default"], "artcraft-linux-v"): + with self.subTest(prefix=prefix), tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + gh = root / "gh" + gh.write_text('#!/usr/bin/env python3\nimport json,sys\nfrom pathlib import Path\nwith Path("calls").open("a") as f: f.write(json.dumps(sys.argv[1:])+"\\n")\nsys.exit(1 if sys.argv[1:3] == ["release", "view"] else 0)\n') + gh.chmod(0o755) + (root / "SHA256SUMS.txt").write_text("checksum package.deb\n") + subprocess.run(["bash", "-e", "-c", step["run"]], cwd=root, check=True, + capture_output=True, env=dict(os.environ, PATH=f"{root}:{os.environ['PATH']}", + TAG_PREFIX=prefix, VERSION="0.42.0", APP_TITLE="Studio", PRERELEASE="false", + GITHUB_SHA="a" * 40, GITHUB_STEP_SUMMARY=str(root / "summary"))) + calls = [json.loads(line) for line in (root / "calls").read_text().splitlines()] + self.assertEqual(calls[0][:3], ["release", "view", prefix + "0.42.0"]) + self.assertEqual(calls[1][:3], ["release", "create", prefix + "0.42.0"])