From b2d9e4a24bc046e1cd649ed529f672231755b909 Mon Sep 17 00:00:00 2001 From: oglassdev <23040613+oglassdev@users.noreply.github.com> Date: Mon, 21 Sep 2026 02:16:49 -0400 Subject: [PATCH 1/2] feat: add a GitHub action to install the publishing CLI --- .github/workflows/ci.yml | 1 + .github/workflows/release.yml | 19 +++++++++- README.md | 18 ++++++++- action.yml | 14 +++++++ scripts/setup-cli.sh | 58 +++++++++++++++++++++++++++++ scripts/test-setup-cli.py | 70 +++++++++++++++++++++++++++++++++++ 6 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 action.yml create mode 100644 scripts/setup-cli.sh create mode 100644 scripts/test-setup-cli.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6197f83..102794c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,7 @@ jobs: - uses: actions/checkout@v4 - uses: jdx/mise-action@v3 - run: pnpm install --frozen-lockfile + - run: python3 scripts/test-setup-cli.py - run: just ready - run: just contracts && git diff --exit-code - run: pnpm exec playwright install --with-deps chromium diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 74ecaa7..868294b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,7 @@ name: CLI release on: push: - tags: ["v*"] + tags: ["v*.*.*"] permissions: contents: write jobs: @@ -28,3 +28,20 @@ jobs: - run: gh release create "$GITHUB_REF_NAME" release/* --generate-notes --verify-tag env: GH_TOKEN: ${{ github.token }} + setup: + needs: binaries + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + permissions: + contents: read + steps: + - uses: actions/checkout@v4 + - uses: ./ + with: + version: ${{ github.ref_name }} + - shell: bash + env: + EXPECTED_VERSION: ${{ github.ref_name }} + run: test "$(maven-r2 --version)" = "$EXPECTED_VERSION" diff --git a/README.md b/README.md index 62b2290..d90aa59 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,23 @@ Uploads are staged remotely before the proxy responds. For large artifacts, incr ### CI -Set `MAVEN_R2_SERVER` and `MAVEN_R2_TOKEN`, then run the same `publish` command without a profile. Use a service-account token restricted to the repository, artifact path prefix, and publishing operations the project needs. +On GitHub Actions, install a specific CLI release with the setup action: + +```yaml +- uses: chunkzero/maven-r2@v1 + with: + version: v0.1.0 + +- name: Publish + env: + MAVEN_R2_SERVER: https://repo.example.com + MAVEN_R2_TOKEN: ${{ secrets.MAVEN_R2_TOKEN }} + run: maven-r2 publish --repository default/releases -- ./gradlew publish +``` + +Set up your project's build tools before publishing. The action supports Linux, macOS, and Windows runners on x64 and ARM64, downloads the binary from this repository's public releases, and verifies its SHA-256 checksum. Self-hosted runners need Bash, curl, and either sha256sum or shasum. Windows also needs Git Bash with cygpath. The required `version` input selects the CLI release independently of the action's `@v1` ref. Pin the action to a commit SHA if you need an immutable reference. + +Outside GitHub Actions, set `MAVEN_R2_SERVER` and `MAVEN_R2_TOKEN`, then run the same `publish` command without a profile. Use a service-account token restricted to the repository, artifact path prefix, and publishing operations the project needs. If the build also downloads private dependencies, give it a separate read token. The CLI removes `MAVEN_R2_TOKEN` from the build's environment. diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..87192c2 --- /dev/null +++ b/action.yml @@ -0,0 +1,14 @@ +name: Setup Maven R2 +description: Install a pinned Maven R2 CLI release +inputs: + version: + description: CLI release tag, such as v0.1.0 + required: true +runs: + using: composite + steps: + - name: Install Maven R2 + shell: bash + env: + MAVEN_R2_VERSION: ${{ inputs.version }} + run: bash "$GITHUB_ACTION_PATH/scripts/setup-cli.sh" diff --git a/scripts/setup-cli.sh b/scripts/setup-cli.sh new file mode 100644 index 0000000..07d0c47 --- /dev/null +++ b/scripts/setup-cli.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +set -euo pipefail + +version="${MAVEN_R2_VERSION:-}" +if [[ ! "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then + echo 'version must be an explicit release tag such as v0.1.0' >&2 + exit 1 +fi +case "${RUNNER_OS:-}" in + Linux) platform=linux ;; + macOS) platform=darwin ;; + Windows) platform=windows ;; + *) echo "Unsupported runner OS: ${RUNNER_OS:-unset}" >&2; exit 1 ;; +esac +case "${RUNNER_ARCH:-}" in + X64) arch=amd64 ;; + ARM64) arch=arm64 ;; + *) echo "Unsupported runner architecture: ${RUNNER_ARCH:-unset}" >&2; exit 1 ;; +esac +: "${RUNNER_TEMP:?RUNNER_TEMP is required}" +: "${GITHUB_PATH:?GITHUB_PATH is required}" + +suffix="" +if [[ "$platform" == windows ]]; then suffix=.exe; fi +asset="maven-r2-${platform}-${arch}${suffix}" +release_url="https://github.com/chunkzero/maven-r2/releases/download/$version" +install_dir="$(mktemp -d "$RUNNER_TEMP/maven-r2.XXXXXX")" +trap 'rm -rf "$install_dir"' EXIT + +curl --fail --silent --show-error --location --retry 3 \ + "$release_url/$asset" --output "$install_dir/$asset" +curl --fail --silent --show-error --location --retry 3 \ + "$release_url/SHA256SUMS" --output "$install_dir/SHA256SUMS" +expected="$(awk -v asset="$asset" '$2 == asset { print $1 }' "$install_dir/SHA256SUMS")" +if [[ ! "$expected" =~ ^[0-9a-f]{64}$ ]]; then + echo "Missing or ambiguous SHA-256 checksum for $asset" >&2 + exit 1 +fi +if command -v sha256sum >/dev/null 2>&1; then + actual="$(sha256sum "$install_dir/$asset")" +else + actual="$(shasum -a 256 "$install_dir/$asset")" +fi +if [[ "${actual%% *}" != "$expected" ]]; then + echo "SHA-256 checksum mismatch for $asset" >&2 + exit 1 +fi +mv "$install_dir/$asset" "$install_dir/maven-r2$suffix" +chmod +x "$install_dir/maven-r2$suffix" +rm "$install_dir/SHA256SUMS" +# GitHub's Windows runner expects a native path in its environment file. +if [[ "$platform" == windows ]]; then + cygpath -w "$install_dir" >> "$GITHUB_PATH" +else + printf '%s\n' "$install_dir" >> "$GITHUB_PATH" +fi +trap - EXIT +printf 'Installed Maven R2 %s (%s/%s)\n' "$version" "$platform" "$arch" diff --git a/scripts/test-setup-cli.py b/scripts/test-setup-cli.py new file mode 100644 index 0000000..4ecb85b --- /dev/null +++ b/scripts/test-setup-cli.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +"""Exercise the installer with local release fixtures and no network access.""" +import hashlib +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + +SCRIPT = Path(__file__).resolve().with_name("setup-cli.sh") + + +class SetupCLI(unittest.TestCase): + def install(self, platform="Linux", arch="X64", version="v0.1.0", checksum="valid", missing=False): + with tempfile.TemporaryDirectory(prefix="maven r2 test ") as root: + root = Path(root) + tools = root / "tools" + tools.mkdir() + # Stand in for GitHub downloads, preserving real checksum verification. + (tools / "curl").write_text('''#!/usr/bin/env bash +set -eu +url="${@: -3:1}" +output="${@: -1}" +if [[ "$url" == */SHA256SUMS ]]; then + cp "$FIXTURE/SHA256SUMS" "$output" +else + cp "$FIXTURE/binary" "$output" +fi +''') + (tools / "cygpath").write_text('#!/usr/bin/env bash\nprintf "%s\\n" "$2"\n') + for tool in tools.iterdir(): + tool.chmod(0o755) + binary = b"fixture CLI bytes\n" + (root / "binary").write_bytes(binary) + os_name = {"Linux": "linux", "macOS": "darwin", "Windows": "windows"}.get(platform, "unknown") + cpu = {"X64": "amd64", "ARM64": "arm64"}.get(arch, "unknown") + suffix = ".exe" if platform == "Windows" else "" + asset = f"maven-r2-{os_name}-{cpu}{suffix}" + digest = hashlib.sha256(binary).hexdigest() if checksum == "valid" else "0" * 64 + (root / "SHA256SUMS").write_text("" if missing else f"{digest} {asset}\n") + path_file = root / "path" + env = {**os.environ, "PATH": f"{tools}{os.pathsep}{os.environ['PATH']}", + "FIXTURE": str(root), "RUNNER_TEMP": str(root), "GITHUB_PATH": str(path_file), + "MAVEN_R2_VERSION": version, "RUNNER_OS": platform, "RUNNER_ARCH": arch} + result = subprocess.run(["bash", str(SCRIPT)], env=env, capture_output=True, text=True) + if result.returncode == 0: + installed = Path(path_file.read_text().strip()) / f"maven-r2{suffix}" + self.assertEqual(installed.read_bytes(), binary) + self.assertTrue(os.access(installed, os.X_OK)) + else: + self.assertFalse(path_file.exists()) + self.assertEqual(list(root.glob("maven-r2.*")), []) + return result + + def test_supported_targets(self): + for platform in ("Linux", "macOS", "Windows"): + for arch in ("X64", "ARM64"): + with self.subTest(platform=platform, arch=arch): + result = self.install(platform=platform, arch=arch) + self.assertEqual(result.returncode, 0, result.stderr) + + def test_rejects_bad_inputs_and_downloads(self): + for options in ({"version": ""}, {"version": "../../main"}, {"version": "$(echo bad)"}, + {"platform": "FreeBSD"}, {"arch": "ARM"}, {"checksum": "bad"}, {"missing": True}): + with self.subTest(options=options): + self.assertNotEqual(self.install(**options).returncode, 0) + + +if __name__ == "__main__": + unittest.main() From 05257e98cca82aa782035db24960bcfd26566885 Mon Sep 17 00:00:00 2001 From: oglassdev <23040613+oglassdev@users.noreply.github.com> Date: Mon, 21 Sep 2026 02:18:54 -0400 Subject: [PATCH 2/2] fix(action): normalize Windows paths before checksum verification --- scripts/setup-cli.sh | 8 +++++--- scripts/test-setup-cli.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/setup-cli.sh b/scripts/setup-cli.sh index 07d0c47..c475089 100644 --- a/scripts/setup-cli.sh +++ b/scripts/setup-cli.sh @@ -24,7 +24,9 @@ suffix="" if [[ "$platform" == windows ]]; then suffix=.exe; fi asset="maven-r2-${platform}-${arch}${suffix}" release_url="https://github.com/chunkzero/maven-r2/releases/download/$version" -install_dir="$(mktemp -d "$RUNNER_TEMP/maven-r2.XXXXXX")" +temp_root="$RUNNER_TEMP" +if [[ "$platform" == windows ]]; then temp_root="$(cygpath -u "$temp_root")"; fi +install_dir="$(mktemp -d "$temp_root/maven-r2.XXXXXX")" trap 'rm -rf "$install_dir"' EXIT curl --fail --silent --show-error --location --retry 3 \ @@ -37,9 +39,9 @@ if [[ ! "$expected" =~ ^[0-9a-f]{64}$ ]]; then exit 1 fi if command -v sha256sum >/dev/null 2>&1; then - actual="$(sha256sum "$install_dir/$asset")" + actual="$(sha256sum < "$install_dir/$asset")" else - actual="$(shasum -a 256 "$install_dir/$asset")" + actual="$(shasum -a 256 < "$install_dir/$asset")" fi if [[ "${actual%% *}" != "$expected" ]]; then echo "SHA-256 checksum mismatch for $asset" >&2 diff --git a/scripts/test-setup-cli.py b/scripts/test-setup-cli.py index 4ecb85b..2386972 100644 --- a/scripts/test-setup-cli.py +++ b/scripts/test-setup-cli.py @@ -27,7 +27,13 @@ def install(self, platform="Linux", arch="X64", version="v0.1.0", checksum="vali cp "$FIXTURE/binary" "$output" fi ''') - (tools / "cygpath").write_text('#!/usr/bin/env bash\nprintf "%s\\n" "$2"\n') + (tools / "cygpath").write_text('''#!/usr/bin/env bash +if [[ "$1" == -u ]]; then + printf '%s\\n' "$FIXTURE" +else + printf '%s\\n' "$2" +fi +''') for tool in tools.iterdir(): tool.chmod(0o755) binary = b"fixture CLI bytes\n" @@ -40,7 +46,7 @@ def install(self, platform="Linux", arch="X64", version="v0.1.0", checksum="vali (root / "SHA256SUMS").write_text("" if missing else f"{digest} {asset}\n") path_file = root / "path" env = {**os.environ, "PATH": f"{tools}{os.pathsep}{os.environ['PATH']}", - "FIXTURE": str(root), "RUNNER_TEMP": str(root), "GITHUB_PATH": str(path_file), + "FIXTURE": str(root), "RUNNER_TEMP": r"C:\runner\temp" if platform == "Windows" else str(root), "GITHUB_PATH": str(path_file), "MAVEN_R2_VERSION": version, "RUNNER_OS": platform, "RUNNER_ARCH": arch} result = subprocess.run(["bash", str(SCRIPT)], env=env, capture_output=True, text=True) if result.returncode == 0: