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
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Checks
on:
pull_request:
push:
branches: [main]
workflow_dispatch:
workflow_call:
permissions:
contents: read
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check:
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- run: rustup show active-toolchain
- run: python3 -m unittest discover -s scripts -p 'test_*.py'
- run: cargo fmt --check
- run: cargo clippy --locked --all-targets -- -D warnings
- run: cargo test --locked
- run: cargo install cargo-deny --locked --version 0.20.2 && cargo deny check
120 changes: 120 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Release
on:
push:
tags: ['v*']
workflow_dispatch:
inputs:
publish:
description: Publish the checked CLI version
type: boolean
default: false
permissions:
contents: read
concurrency:
group: release
cancel-in-progress: false
jobs:
check:
uses: ./.github/workflows/ci.yml
version:
runs-on: ubuntu-24.04
timeout-minutes: 5
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- id: version
run: python3 scripts/release-version.py
build:
needs: [check, version]
strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-24.04
target: x86_64-unknown-linux-musl
- runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-musl
- runner: macos-15-intel
target: x86_64-apple-darwin
- runner: macos-15
target: aarch64-apple-darwin
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install --no-install-recommends --yes musl-tools
- env:
TARGET: ${{ matrix.target }}
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER: musl-gcc
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: musl-gcc
CC_x86_64_unknown_linux_musl: musl-gcc
CC_aarch64_unknown_linux_musl: musl-gcc
run: |
rustup target add "$TARGET"
cargo build --release --locked --target "$TARGET"
- env:
TARGET: ${{ matrix.target }}
VERSION: ${{ needs.version.outputs.version }}
run: |
test "$(target/"$TARGET"/release/proofline --version)" = "proofline $VERSION"
python3 scripts/archive.py "$TARGET"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: cli-${{ matrix.target }}
path: artifacts/*.tar.gz
if-no-files-found: error
publish:
if: github.event_name == 'push' || inputs.publish
needs: [version, build]
runs-on: ubuntu-24.04
timeout-minutes: 15
environment: release
permissions:
contents: write
id-token: write
attestations: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: cli-*
merge-multiple: true
path: artifacts
- env:
VERSION: ${{ needs.version.outputs.version }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
test "$(find artifacts -name '*.tar.gz' | wc -l)" -eq 4
(cd artifacts && LC_ALL=C sha256sum proofline-*.tar.gz > SHA256SUMS)
printf '%s\n' "$VERSION" > artifacts/latest
# Creating the draft reserves the GitHub version atomically.
gh release create "v$VERSION" --repo "$GITHUB_REPOSITORY" --target "$GITHUB_SHA" --draft --title "Proofline $VERSION" --generate-notes
- uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
with:
subject-path: artifacts/*.tar.gz
- env:
VERSION: ${{ needs.version.outputs.version }}
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
CLI_RELEASE_R2_CREDENTIALS: ${{ secrets.CLI_RELEASE_R2_CREDENTIALS }}
run: scripts/publish-r2.sh "$VERSION" artifacts
- env:
VERSION: ${{ needs.version.outputs.version }}
GH_TOKEN: ${{ github.token }}
run: |
gh release upload "v$VERSION" artifacts/* --repo "$GITHUB_REPOSITORY"
gh release edit "v$VERSION" --repo "$GITHUB_REPOSITORY" --draft=false --latest
for archive in artifacts/*.tar.gz; do
name=$(basename "$archive")
curl --proto '=https' --tlsv1.2 --fail --silent --show-error --location "https://proofline.sh/cli/download/$VERSION/$name" -o "/tmp/$name"
cmp "$archive" "/tmp/$name"
done
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,18 @@ is installed by rustup. Run `cargo fmt --check`, `cargo clippy --locked --all-ta
Server compatibility is checked in the Proofline control plane.

Licensed under Apache-2.0.

## Publishing

GitHub Actions checks pull requests and main. Run `Release` on main with
`publish=false` to build all four Linux/macOS archives without publishing.
A `vX.Y.Z` tag equal to Cargo's version, or a main dispatch with `publish=true`,
publishes after the `release` environment approves the job. The commit must be on main.

The build jobs have no write credential. The publisher creates a GitHub draft
to reserve the version, records artifact attestations, and uploads the binaries
and SHA256SUMS to the existing R2 download bucket and GitHub Releases.
The bucket-scoped credential is the `CLI_RELEASE_R2_CREDENTIALS` environment secret;
`CLOUDFLARE_ACCOUNT_ID` is an environment variable. R2 versions are reserved
with a conditional write. A failed publication retains its reservation; raise
the package version before another release. Install and update URLs stay on proofline.sh.
19 changes: 19 additions & 0 deletions scripts/archive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Package one checked CLI binary with deterministic archive metadata."""
import gzip
import io
from pathlib import Path
import sys
import tarfile

target = sys.argv[1]
source = Path("target") / target / "release/proofline"
data = source.read_bytes()
Path("artifacts").mkdir(exist_ok=True)
with Path(f"artifacts/proofline-{target}.tar.gz").open("wb") as output:
with gzip.GzipFile(filename="", fileobj=output, mode="wb", mtime=0) as compressed:
with tarfile.open(fileobj=compressed, mode="w") as archive:
entry = tarfile.TarInfo("proofline")
entry.size = len(data)
entry.mode = 0o755
entry.mtime = 0
archive.addfile(entry, io.BytesIO(data))
83 changes: 83 additions & 0 deletions scripts/publish-r2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env bash
# Upload the reserved CLI version through R2's bucket-scoped S3 API.
# Credentials arrive only in the publish step and travel to curl on stdin.
set -euo pipefail

version=${1:-}
dist=${2:-}
refuse() { printf 'cli publish: %s\n' "$*" >&2; exit 1; }
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || refuse 'expected an x.y.z version'
[ -d "$dist" ] || refuse 'the release directory is missing'
: "${CLOUDFLARE_ACCOUNT_ID:?the Cloudflare account is required}"
: "${CLI_RELEASE_R2_CREDENTIALS:?the bucket-scoped S3 credentials are required}"
[[ "$CLOUDFLARE_ACCOUNT_ID" =~ ^[0-9a-f]{32}$ ]] || refuse 'invalid Cloudflare account ID'
access_key=$(printf '%s' "$CLI_RELEASE_R2_CREDENTIALS" | jq -er '.access_key_id')
secret_key=$(printf '%s' "$CLI_RELEASE_R2_CREDENTIALS" | jq -er '.secret_access_key')
[[ "$access_key" =~ ^[0-9a-f]{32}$ ]] || refuse 'invalid R2 access key ID'
[[ "$secret_key" =~ ^[0-9a-f]{64}$ ]] || refuse 'invalid R2 secret access key'
unset CLI_RELEASE_R2_CREDENTIALS

temporary=$(mktemp -d)
trap 'rm -rf "$temporary"' EXIT
targets='aarch64-apple-darwin aarch64-unknown-linux-musl x86_64-apple-darwin x86_64-unknown-linux-musl'
# Verify every archive before the first upload. The manifest names exactly
# the four files the installer can download, with their actual digests.
for target in $targets; do
archive="proofline-$target.tar.gz"
[ -f "$dist/$archive" ] || refuse "missing $archive"
digest=$(sha256sum "$dist/$archive" | cut -d ' ' -f 1)
printf '%s %s\n' "$digest" "$archive" >> "$temporary/SHA256SUMS"
done
cmp -s "$temporary/SHA256SUMS" "$dist/SHA256SUMS" || refuse 'SHA256SUMS does not match the four release archives'

put() {
local key=$1 source=$2 content_type=$3 cache_control=$4 condition=${5:-} digest
digest=$(sha256sum "$source" | cut -d ' ' -f 1)
# Object Read & Write tokens support the S3 API only. curl signs the exact
# payload and metadata; credentials stay out of command arguments and logs.
printf 'user = "%s:%s"\n' "$access_key" "$secret_key" |
curl --config - --aws-sigv4 'aws:amz:auto:s3' \
--proto '=https' --tlsv1.2 --fail --silent --show-error \
--connect-timeout 15 --max-time 120 --retry 2 \
--request PUT --upload-file "$source" \
--header "Content-Type: $content_type" \
--header "Cache-Control: $cache_control" \
--header "x-amz-content-sha256: $digest" \
--header "If-None-Match: $condition" \
"https://$CLOUDFLARE_ACCOUNT_ID.r2.cloudflarestorage.com/proofline-cli-releases/$key"
}

# Old releases predate R2 reservations. Refuse those too, and never replace
# latest with an older version. An unavailable origin is not an empty registry.
status=$(curl --proto '=https' --tlsv1.2 --silent --show-error --location \
--connect-timeout 15 --max-time 30 --output "$temporary/probe" --write-out '%{http_code}' \
"https://proofline.sh/cli/download/$version/SHA256SUMS")
[ "$status" = 404 ] || refuse "version $version is already published or its status is unavailable ($status)"
status=$(curl --proto '=https' --tlsv1.2 --silent --show-error --location \
--connect-timeout 15 --max-time 30 --output "$temporary/latest" --write-out '%{http_code}' \
'https://proofline.sh/cli/latest')
case "$status" in
200)
latest=$(cat "$temporary/latest")
[[ "$latest" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || refuse 'latest is not a version'
[ "$latest" != "$version" ] && [ "$(printf '%s\n%s\n' "$latest" "$version" | sort -V | tail -1)" = "$version" ] \
|| refuse "$version is not newer than $latest"
;;
404) ;;
*) refuse "could not read latest ($status)" ;;
esac

# Reserve the version before any release object is written. A failed upload
# retains the claim, so another run cannot overwrite a partial publication.
printf '{"version":"%s","commit":"%s"}\n' "$version" "${GITHUB_SHA:?missing release commit}" > "$temporary/reservation.json"
put "$version/RELEASE.json" "$temporary/reservation.json" application/json 'public, max-age=31536000, immutable' '*'
immutable='public, max-age=31536000, immutable'
for target in $targets; do
archive="proofline-$target.tar.gz"
put "$version/$archive" "$dist/$archive" application/gzip "$immutable"
done
put "$version/SHA256SUMS" "$dist/SHA256SUMS" 'text/plain; charset=utf-8' "$immutable"
# Installers see the version only after all five release objects exist.
printf '%s\n' "$version" > "$temporary/latest"
put latest "$temporary/latest" 'text/plain; charset=utf-8' 'public, max-age=60'
printf 'cli publish: uploaded CLI %s\n' "$version"
18 changes: 18 additions & 0 deletions scripts/release-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Admit a release only at its package version and a commit on main."""
import os
from pathlib import Path
import re
import subprocess
import tomllib

version = tomllib.loads(Path("Cargo.toml").read_text())["package"]["version"]
if not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", version):
raise SystemExit("package version must be x.y.z")
ref = os.environ["GITHUB_REF"]
if ref not in ("refs/heads/main", f"refs/tags/v{version}"):
raise SystemExit("release requires main or a tag equal to the package version")
subprocess.run(["git", "fetch", "--quiet", "origin", "main"], check=True)
subprocess.run(["git", "merge-base", "--is-ancestor", "HEAD", "origin/main"], check=True)
with Path(os.environ["GITHUB_OUTPUT"]).open("a") as output:
output.write(f"version={version}\n")
print(f"Release version: {version}")
Loading
Loading