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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CLI release
on:
push:
tags: ["v*"]
tags: ["v*.*.*"]
permissions:
contents: write
jobs:
Expand All @@ -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"
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
14 changes: 14 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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"
60 changes: 60 additions & 0 deletions scripts/setup-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/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"
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 \
"$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"
76 changes: 76 additions & 0 deletions scripts/test-setup-cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/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
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"
(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": 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:
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()
Loading