diff --git a/.github/scripts/check-dist.sh b/.github/scripts/check-dist.sh new file mode 100755 index 000000000..a59809513 --- /dev/null +++ b/.github/scripts/check-dist.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Checks the files about to go to PyPI: each one carries the expected +# version, and twine accepts the metadata. Used by python.yml in dry runs +# and real releases alike. +# +# check-dist.sh +set -euo pipefail +NAME=$1 VERSION=$2 DIR=$3 +ls -la "$DIR" +[ -n "$(ls -A "$DIR")" ] || { echo "::error::No files in $DIR"; exit 1; } +for f in "$DIR"/*; do + case "$(basename "$f")" in + "$NAME-$VERSION"-*.whl | "$NAME-$VERSION".tar.gz) ;; + *) echo "::error::$(basename "$f") is not $NAME $VERSION"; exit 1 ;; + esac +done +pipx run twine check --strict "$DIR"/* diff --git a/.github/scripts/release_plan.py b/.github/scripts/release_plan.py new file mode 100755 index 000000000..096f00cb4 --- /dev/null +++ b/.github/scripts/release_plan.py @@ -0,0 +1,190 @@ +#!/usr/bin/env python3 +"""Work out what a release publishes, for .github/workflows/release.yml. + +Reads every artifact's version from the repository and asks its registry +whether that version is published. A real release publishes only what is +missing. A dry run exercises every selected artifact, published or not, +so it can run at any time. + +Also fails on mistakes that only the registries would catch otherwise: +wildcard dependency requirements, which crates.io rejects on upload, and +artifacts that must share a version but don't. + +Runs locally too, it only needs cargo and network access: + + python3 .github/scripts/release_plan.py --dry-run + +On GitHub it writes its decisions to $GITHUB_OUTPUT and a table to +$GITHUB_STEP_SUMMARY. +""" + +import argparse +import json +import os +import subprocess +import sys +import tomllib +import urllib.error +import urllib.request +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +SWIFT_REPO = "https://github.com/Blockstream/gl-sdk-swift" +USER_AGENT = "greenlight-release-plan (https://github.com/Blockstream/greenlight)" +GROUPS = ("crates", "python", "npm", "swift", "maven") + + +def published(url: str) -> bool: + """True on 200, False on 404, an error for anything else.""" + req = urllib.request.Request(url, headers={"User-Agent": USER_AGENT}) + try: + with urllib.request.urlopen(req, timeout=30): + return True + except urllib.error.HTTPError as e: + if e.code == 404: + return False + raise SystemExit(f"error: {url} answered {e.code}, cannot tell whether it is published") + + +def swift_tag_exists(version: str) -> bool: + out = subprocess.run( + ["git", "ls-remote", "--tags", SWIFT_REPO, f"refs/tags/{version}"], + check=True, capture_output=True, text=True, + ).stdout + return bool(out.strip()) + + +def pyproject_version(path: str) -> str: + with open(ROOT / path, "rb") as f: + return tomllib.load(f)["project"]["version"] + + +def gradle_property(path: str, key: str) -> str: + for line in (ROOT / path).read_text().splitlines(): + k, _, v = line.partition("=") + if k.strip() == key: + return v.strip() + raise SystemExit(f"error: no {key} in {path}") + + +def publish_order(packages: dict) -> list: + """Workspace crates ordered so each comes after its workspace dependencies.""" + deps = { + name: { + d["name"] for d in pkg["dependencies"] + if d["name"] in packages and d["kind"] != "dev" + } + for name, pkg in packages.items() + } + order, done = [], set() + while len(order) < len(packages): + ready = sorted(n for n in packages if n not in done and deps[n] <= done) + if not ready: + raise SystemExit(f"error: dependency cycle among {sorted(set(packages) - done)}") + order += ready + done |= set(ready) + return order + + +def main() -> None: + ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + ap.add_argument("--dry-run", action="store_true") + ap.add_argument("--select", default=",".join(GROUPS), + help=f"comma-separated subset of {','.join(GROUPS)}") + args = ap.parse_args() + selected = {g for g in args.select.split(",") if g} + if selected - set(GROUPS): + raise SystemExit(f"error: unknown group(s) {sorted(selected - set(GROUPS))}") + + meta = json.loads(subprocess.run( + ["cargo", "metadata", "--no-deps", "--format-version", "1"], + cwd=ROOT, check=True, capture_output=True, text=True, + ).stdout) + workspace = {p["name"]: p for p in meta["packages"]} + crates = {n: p for n, p in workspace.items() if p["publish"] != []} + + errors = [] + rows = [] # (group, artifact, version, registry, published, action) + + def decide(group, artifact, version, registry, is_published): + if group not in selected: + action = "not selected" + elif is_published: + action = "dry run (already published)" if args.dry_run else "skip, already published" + else: + action = "dry run" if args.dry_run else "publish" + rows.append((group, artifact, version, registry, is_published, action)) + return group in selected and (args.dry_run or not is_published) + + # crates.io rejects wildcard requirements only on upload. + for name, pkg in crates.items(): + for d in pkg["dependencies"]: + if d["req"] == "*" and d["kind"] != "dev": + errors.append(f'{name}: dependency `{d["name"]} = "*"`, crates.io rejects wildcard requirements') + + crate_list = [] + for name in publish_order(crates): + v = crates[name]["version"] + if decide("crates", name, v, "crates.io", + published(f"https://crates.io/api/v1/crates/{name}/{v}")): + crate_list.append(name) + + sdk = workspace["gl-sdk"]["version"] + gl_client_py = pyproject_version("libs/gl-client-py/pyproject.toml") + gl_sdk_py = pyproject_version("libs/gl-sdk/pyproject.toml") + package_json = json.loads((ROOT / "libs/gl-sdk-napi/package.json").read_text()) + maven = gradle_property("libs/gl-sdk-android/gradle.properties", "libraryVersion") + + # The bindings of one SDK release share the gl-sdk version, and each + # binding's crate carries the version of the package built from it. + for what, version, want in [ + ("libs/gl-sdk/pyproject.toml", gl_sdk_py, sdk), + ("libraryVersion in libs/gl-sdk-android/gradle.properties", maven, sdk), + ("libs/gl-client-py/pyproject.toml", gl_client_py, workspace["gl-client-py"]["version"]), + ("libs/gl-sdk-napi/package.json", package_json["version"], workspace["gl-sdk-node"]["version"]), + ]: + if version != want: + errors.append(f"{what} says {version}, expected {want}") + + out = { + "crates": " ".join(crate_list), + "gl_client_py": decide("python", "gl-client (PyPI)", gl_client_py, "PyPI", + published(f"https://pypi.org/pypi/gl-client/{gl_client_py}/json")), + "gl_sdk_py": decide("python", "gl-sdk (PyPI)", gl_sdk_py, "PyPI", + published(f"https://pypi.org/pypi/gl-sdk/{gl_sdk_py}/json")), + } + npm_name, npm_version = package_json["name"], package_json["version"] + npm_doc = f"https://registry.npmjs.org/{npm_name.replace('/', '%2F')}/{npm_version}" + out["npm"] = decide("npm", npm_name, npm_version, "npm", published(npm_doc)) + out["swift"] = decide("swift", "GreenlightSDK", sdk, "gl-sdk-swift tag", swift_tag_exists(sdk)) + out["maven"] = decide("maven", "com.blockstream:glsdk", maven, "Maven Central", published( + f"https://repo1.maven.org/maven2/com/blockstream/glsdk/{maven}/glsdk-{maven}.pom")) + out["sdk_version"] = sdk + + mode = "Dry run" if args.dry_run else "Release" + summary = [f"## {mode} plan", "", "| Group | Artifact | Version | Registry | Published | Action |", + "| --- | --- | --- | --- | --- | --- |"] + summary += [f"| {g} | `{a}` | {v} | {r} | {'yes' if p else 'no'} | {act} |" + for g, a, v, r, p, act in rows] + if errors: + summary += ["", "### Errors", ""] + [f"- {e}" for e in errors] + text = "\n".join(summary) + "\n" + print(text) + if path := os.environ.get("GITHUB_STEP_SUMMARY"): + with open(path, "a") as f: + f.write(text) + if path := os.environ.get("GITHUB_OUTPUT"): + with open(path, "a") as f: + for k, v in out.items(): + f.write(f"{k}={str(v).lower() if isinstance(v, bool) else v}\n") + else: + print(json.dumps(out, indent=2)) + + for e in errors: + print(f"::error::{e}" if os.environ.get("GITHUB_ACTIONS") else f"error: {e}", file=sys.stderr) + if errors: + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/kotlin.yml b/.github/workflows/kotlin.yml index 238ea50e8..1dea792f6 100644 --- a/.github/workflows/kotlin.yml +++ b/.github/workflows/kotlin.yml @@ -1,10 +1,29 @@ +# Builds and tests the Kotlin Multiplatform library (Android, JVM, iOS). +# +# Called by release.yml, it also builds the Maven Central bundle of +# com.blockstream:glsdk: the publications in the Maven repository layout, +# unsigned. contrib/maven-central/check-bundle.sh checks it and signs it +# with a throwaway key, the way Central requires. A real release attaches +# the unsigned bundle to the gl-sdk-vX.Y.Z release, where Blockstream's +# release infrastructure picks it up within the hour, signs it with +# Blockstream's key and uploads it. No Maven credentials are on GitHub. +# The release then waits until the version is on repo1.maven.org. + on: push: branches: - - master - tags: - - 'gl-sdk-*' + - main pull_request: {} + workflow_dispatch: + # Publishing runs only when release.yml calls this workflow. + workflow_call: + inputs: + release: + type: boolean + default: false + dry_run: + type: boolean + default: true name: Kotlin library @@ -12,6 +31,8 @@ jobs: build: runs-on: macos-26 + outputs: + version: ${{ steps.bundle.outputs.version }} steps: - name: "Show default version of NDK" run: echo $ANDROID_NDK_ROOT @@ -63,14 +84,91 @@ jobs: run: | ./gradlew :lib:jvmTest --console=plain - - name: "Puiblish to Maven" + - name: "Publish to Maven Local" working-directory: libs/gl-sdk-android run: | ./gradlew :lib:publishToMavenLocal + - name: "Build the Maven Central bundle" + id: bundle + if: inputs.release + working-directory: libs/gl-sdk-android + run: | + VERSION=$(sed -n 's/^libraryVersion=//p' gradle.properties) + ./gradlew :lib:publishAllPublicationsToBundleRepository --console=plain + mkdir -p "$GITHUB_WORKSPACE/dist" + ZIP="$GITHUB_WORKSPACE/dist/glsdk-maven-$VERSION.zip" + (cd lib/build/maven-bundle && zip -q -r "$ZIP" com) + shasum -a 256 "$ZIP" | cut -d' ' -f1 > "$ZIP.sha256" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + + # What Central checks, with a throwaway key. + - name: "Check the bundle" + if: inputs.release + run: | + VERSION=${{ steps.bundle.outputs.version }} + GNUPGHOME=$(mktemp -d) + export GNUPGHOME + gpg --batch --passphrase '' --quick-gen-key "glsdk release dry run " ed25519 sign never + KEY=$(gpg --list-keys --with-colons | awk -F: '/^fpr/ {print $10; exit}') + contrib/maven-central/check-bundle.sh "dist/glsdk-maven-$VERSION.zip" "$VERSION" "$KEY" "$RUNNER_TEMP/signed.zip" + + - uses: actions/upload-artifact@v4 + if: inputs.release + with: + name: maven-bundle + path: dist/ + if-no-files-found: error + - name: Temporarily save artifact uses: actions/upload-artifact@v4 with: name: glsdk-artifact path: libs/gl-sdk-android/lib/build/outputs/ retention-days: 14 + + attach: + name: Attach the Maven bundle to the gl-sdk release + if: inputs.release && !inputs.dry_run + needs: build + runs-on: ubuntu-latest + permissions: + contents: write + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + TAG: gl-sdk-v${{ needs.build.outputs.version }} + steps: + - uses: actions/download-artifact@v4 + with: + name: maven-bundle + path: dist + + # publish-crates.yml creates the release when it publishes the gl-sdk + # crate. A Maven-only release creates it here. + - name: Upload the bundle + run: | + if ! gh release view "$TAG" >/dev/null 2>&1; then + gh release create "$TAG" --target "$GITHUB_SHA" --title "gl-sdk ${TAG#gl-sdk-v}" \ + --notes "See the [gl-sdk changelog](https://github.com/$GH_REPO/blob/$TAG/libs/gl-sdk/CHANGELOG.md)." \ + || gh release view "$TAG" >/dev/null # created concurrently + fi + gh release upload "$TAG" --clobber dist/glsdk-maven-*.zip dist/glsdk-maven-*.zip.sha256 + gh release view "$TAG" --json assets --jq '.assets[].name' + + # The bundle is picked up within the hour, then Central validates, + # publishes and syncs to repo1.maven.org. + published: + name: Wait for Maven Central + needs: [build, attach] + runs-on: ubuntu-latest + timeout-minutes: 180 + env: + VERSION: ${{ needs.build.outputs.version }} + steps: + - name: Wait for the release on repo1.maven.org + run: | + echo "::notice::Waiting for com.blockstream:glsdk:$VERSION on Maven Central, usually within 90 minutes" + URL="https://repo1.maven.org/maven2/com/blockstream/glsdk/$VERSION/glsdk-$VERSION.pom" + until curl -fsI "$URL" >/dev/null; do sleep 120; done + echo "com.blockstream:glsdk:$VERSION is on Maven Central" diff --git a/.github/workflows/publish-crates.yml b/.github/workflows/publish-crates.yml new file mode 100644 index 000000000..e09fc0d8b --- /dev/null +++ b/.github/workflows/publish-crates.yml @@ -0,0 +1,153 @@ +# Publishes workspace crates to crates.io. Called by release.yml, which +# passes the crates in dependency order. +# +# crates.io never deletes a version, it can only be yanked, so every crate +# passes these checks first, in a dry run too: +# +# 1. a Keep a Changelog CHANGELOG.md with an entry for the version +# 2. cargo-semver-checks against the latest published version, unless +# the bump allows breaking changes (X.0.0, or 0.X.0 before 1.0) +# 3. its tests +# 4. `cargo publish --dry-run` for all of them together +# +# Step 4 packages each crate and builds it against the others' packages. +# Cargo overlays the unpublished ones as a local registry, so a dry run +# passes before any of them is on crates.io. A real run uploads in that +# order, skips versions crates.io already has, and creates a +# `-vX.Y.Z` GitHub release for each crate. + +name: Crates + +on: + workflow_call: + inputs: + crates: + description: 'Space-separated crates, in dependency order' + required: true + type: string + dry_run: + required: true + type: boolean + +permissions: + contents: write + +jobs: + publish: + runs-on: ubuntu-latest + env: + CRATES: ${{ inputs.crates }} + steps: + - uses: actions/checkout@v4 + with: + # cargo-semver-checks compares against the published versions. + fetch-depth: 0 + + - uses: dtolnay/rust-toolchain@stable + + - name: Install Protoc + uses: arduino/setup-protoc@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Install python-kacl + run: pip install python-kacl + + - uses: cargo-bins/cargo-binstall@main + - run: cargo binstall --no-confirm cargo-semver-checks + + - name: Check the changelogs + run: | + META=$(cargo metadata --no-deps --format-version 1) + for CRATE in $CRATES; do + PKG=$(jq -c --arg c "$CRATE" '.packages[] | select(.name == $c)' <<<"$META") + VERSION=$(jq -r .version <<<"$PKG") + DIR=$(dirname "$(jq -r .manifest_path <<<"$PKG")") + if [ ! -f "$DIR/CHANGELOG.md" ]; then + echo "::error::$CRATE has no CHANGELOG.md in $DIR" + exit 1 + fi + # kacl-cli reads CHANGELOG.md from the working directory. + if ! (cd "$DIR" && kacl-cli verify --json) > kacl.json 2>&1; then + echo "::error::$DIR/CHANGELOG.md does not follow Keep a Changelog" + jq -r '.errors[] | "Line \(.line_number): \(.error_message)\n \(.line)"' kacl.json || cat kacl.json + exit 1 + fi + if ! grep -qE "^##? \[?v?${VERSION//./\\.}\]?" "$DIR/CHANGELOG.md"; then + echo "::error::$DIR/CHANGELOG.md has no entry for $CRATE $VERSION" + exit 1 + fi + echo "$CRATE $VERSION: changelog ok" + done + + - name: Check semver compatibility + run: | + META=$(cargo metadata --no-deps --format-version 1) + for CRATE in $CRATES; do + VERSION=$(jq -r --arg c "$CRATE" '.packages[] | select(.name == $c) | .version' <<<"$META") + IFS=. read -r MAJOR MINOR PATCH <<<"$VERSION" + if ! cargo info "$CRATE" --registry crates-io >/dev/null 2>&1; then + echo "$CRATE: not on crates.io yet, nothing to compare against" + elif [ "$MAJOR" != 0 ] && [ "$MINOR.$PATCH" = 0.0 ]; then + echo "$CRATE $VERSION: major bump, breaking changes allowed" + elif [ "$MAJOR" = 0 ] && [ "$PATCH" = 0 ]; then + echo "$CRATE $VERSION: 0.x minor bump, breaking changes allowed" + elif ! cargo semver-checks check-release -p "$CRATE"; then + echo "::error::$CRATE $VERSION breaks the API of its last release, bump the version accordingly" + exit 1 + fi + done + + - name: Run the tests + run: | + ARGS=() + for CRATE in $CRATES; do ARGS+=(-p "$CRATE"); done + cargo test "${ARGS[@]}" + + - name: Publish + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} + DRY_RUN: ${{ inputs.dry_run }} + run: | + ARGS=() + META=$(cargo metadata --no-deps --format-version 1) + for CRATE in $CRATES; do + VERSION=$(jq -r --arg c "$CRATE" '.packages[] | select(.name == $c) | .version' <<<"$META") + if [ "$DRY_RUN" != true ] && cargo info "$CRATE@$VERSION" --registry crates-io >/dev/null 2>&1; then + echo "::notice::$CRATE $VERSION is already on crates.io, skipping it" + continue + fi + ARGS+=(-p "$CRATE") + done + if [ ${#ARGS[@]} = 0 ]; then + echo "Nothing to publish" + elif [ "$DRY_RUN" = true ]; then + cargo publish --dry-run "${ARGS[@]}" + else + cargo publish "${ARGS[@]}" + fi + + - name: Create the GitHub releases + if: ${{ !inputs.dry_run }} + env: + GH_TOKEN: ${{ github.token }} + run: | + META=$(cargo metadata --no-deps --format-version 1) + for CRATE in $CRATES; do + VERSION=$(jq -r --arg c "$CRATE" '.packages[] | select(.name == $c) | .version' <<<"$META") + TAG="$CRATE-v$VERSION" + DIR=$(dirname "$(jq -r --arg c "$CRATE" '.packages[] | select(.name == $c) | .manifest_path' <<<"$META")") + if gh release view "$TAG" >/dev/null 2>&1; then + echo "$TAG: release exists" + continue + fi + # swift.yml may create gl-sdk-vX.Y.Z concurrently, losing the + # race is fine. + gh release create "$TAG" --target "$GITHUB_SHA" --title "$CRATE v$VERSION" \ + --notes "Published $CRATE $VERSION to [crates.io](https://crates.io/crates/$CRATE/$VERSION). See the [changelog](https://github.com/$GITHUB_REPOSITORY/blob/$TAG/${DIR#"$GITHUB_WORKSPACE"/}/CHANGELOG.md)." \ + || gh release view "$TAG" >/dev/null + done diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index c1a9ce535..66b4b693b 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -9,10 +9,30 @@ on: - synchronize - opened workflow_dispatch: + # Publishing runs only when release.yml calls this workflow. + workflow_call: + inputs: + release: + type: boolean + default: false + dry_run: + type: boolean + default: true + gl_client: + description: 'Publish the gl-client package' + type: boolean + default: false + gl_sdk: + description: 'Publish the gl-sdk package' + type: boolean + default: false +# A called workflow sees the caller's github.workflow, so the group names +# this workflow itself, or it would share the group with the other +# workflows release.yml calls. concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true + group: python-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: source: @@ -190,3 +210,218 @@ jobs: with: name: wheels-win-${{ matrix.target }} path: libs\gl-client-py\dist + + # The gl-sdk Python package wraps the gl-sdk shared library with UniFFI + # bindings loaded through ctypes, so one wheel per platform serves every + # Python version. hatchling tags the wheel `py3-none-any`, which is + # retagged with the platform the bundled library was built for. + gl-sdk-wheels: + name: gl-sdk wheel - ${{ matrix.plat }} + runs-on: ${{ matrix.host }} + strategy: + fail-fast: false + matrix: + include: + # Linux libraries link glibc 2.17 through cargo-zigbuild, like the + # desktop libraries in the jvm jar, so the manylinux_2_17 tag holds. + - host: ubuntu-24.04 + target: x86_64-unknown-linux-gnu + zig: true + lib: libglsdk.so + plat: manylinux_2_17_x86_64.manylinux2014_x86_64 + smoke: true + - host: ubuntu-24.04-arm + target: aarch64-unknown-linux-gnu + zig: true + lib: libglsdk.so + plat: manylinux_2_17_aarch64.manylinux2014_aarch64 + smoke: true + - host: macos-15 + target: aarch64-apple-darwin + lib: libglsdk.dylib + plat: macosx_11_0_arm64 + smoke: true + # Cross built on the arm64 runner, not smoke tested. + - host: macos-15 + target: x86_64-apple-darwin + lib: libglsdk.dylib + plat: macosx_11_0_x86_64 + smoke: false + - host: windows-latest + target: x86_64-pc-windows-msvc + lib: glsdk.dll + plat: win_amd64 + smoke: true + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v7 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + + - name: Install Protoc + uses: arduino/setup-protoc@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Install cargo-zigbuild + if: matrix.zig + run: | + pip install ziglang + cargo install --locked cargo-zigbuild@0.24.0 + + - name: Build the gl-sdk library (Linux) + if: runner.os == 'Linux' + run: cargo zigbuild --release --target ${{ matrix.target }}.2.17 -p gl-sdk + + # Apple's strip instead of cargo's rust-objcopy, see jvm-darwin-* in + # build/.tasks.yml for the dyld issue this avoids. + - name: Build the gl-sdk library (macOS) + if: runner.os == 'macOS' + env: + MACOSX_DEPLOYMENT_TARGET: '11.0' + CARGO_PROFILE_RELEASE_STRIP: 'false' + run: | + cargo build --release --target ${{ matrix.target }} -p gl-sdk + /usr/bin/strip -x target/${{ matrix.target }}/release/${{ matrix.lib }} + + # Static C runtime, so the library loads without the Visual C++ + # Redistributable. + - name: Build the gl-sdk library (Windows) + if: runner.os == 'Windows' + env: + RUSTFLAGS: -C target-feature=+crt-static + run: cargo build --release --target ${{ matrix.target }} -p gl-sdk + + # Regenerated from the library going into the wheel, so the bindings + # and the library always agree on the API checksums. + - name: Generate the Python bindings + run: | + LIB=target/${{ matrix.target }}/release/${{ matrix.lib }} + cp "$LIB" libs/gl-sdk/glsdk/${{ matrix.lib }} + cargo run --bin uniffi-bindgen -- generate \ + --library "$LIB" --language python --out-dir libs/gl-sdk/glsdk + if ! git diff --quiet -- libs/gl-sdk/glsdk/glsdk.py; then + echo "::warning::The committed libs/gl-sdk/glsdk/glsdk.py is stale, run task sdk:bindings-python" + fi + + - name: Build and retag the wheel + run: | + uv build --package gl-sdk --wheel --out-dir dist-sdk + uvx --from wheel wheel tags --remove --platform-tag '${{ matrix.plat }}' dist-sdk/*.whl + ls -la dist-sdk + + - name: Smoke test the wheel + if: matrix.smoke + run: | + WHEEL=$(ls dist-sdk/*.whl) + # The import checks the bindings against the library's API + # checksums, parse_input calls into the library. + uv run --no-project --isolated --python 3.12 --with "$WHEEL" python -c \ + "import glsdk; print(glsdk.__version__); print(glsdk.parse_input('02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619'))" + + - name: Upload wheel + uses: actions/upload-artifact@v4 + with: + name: gl-sdk-wheel-${{ matrix.target }} + path: dist-sdk/*.whl + if-no-files-found: error + + # Publishing uses PyPI trusted publishing: PyPI accepts the GitHub OIDC + # token of this workflow in the `pypi` environment, no API token needed. + # The token names the workflow that started the run, release.yml, so + # that is the workflow each PyPI trusted publisher has to name. + # + # A dry run checks the same files and stops before the upload, without + # the `pypi` environment, so it needs no approval. + check-gl-client: + name: Check gl-client for PyPI + if: inputs.release && inputs.gl_client + needs: [source, linux, macos, windows] + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + pattern: wheels-* + path: dist + merge-multiple: true + - name: Check the version and metadata + run: .github/scripts/check-dist.sh gl_client "$(sed -n 's/^version = "\(.*\)"/\1/p' libs/gl-client-py/pyproject.toml)" dist + + publish-gl-client: + name: Publish gl-client to PyPI + if: inputs.release && inputs.gl_client && !inputs.dry_run + needs: [check-gl-client] + runs-on: ubuntu-24.04 + environment: + name: pypi + url: https://pypi.org/project/gl-client/ + permissions: + contents: write + id-token: write + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + pattern: wheels-* + path: dist + merge-multiple: true + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + # A re-run after a partial upload. + skip-existing: true + - name: Create the GitHub release + env: + GH_TOKEN: ${{ github.token }} + run: | + VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' libs/gl-client-py/pyproject.toml) + TAG="gl-client-py-v$VERSION" + gh release view "$TAG" >/dev/null 2>&1 || gh release create "$TAG" --target "$GITHUB_SHA" \ + --title "gl-client (Python) v$VERSION" \ + --notes "Published gl-client $VERSION to [PyPI](https://pypi.org/project/gl-client/$VERSION/). See the [changelog](https://github.com/$GITHUB_REPOSITORY/blob/$TAG/libs/gl-client-py/CHANGELOG.md)." + + check-gl-sdk: + name: Check gl-sdk for PyPI + if: inputs.release && inputs.gl_sdk + needs: [gl-sdk-wheels] + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + pattern: gl-sdk-wheel-* + path: dist + merge-multiple: true + - name: Check the version and metadata + run: .github/scripts/check-dist.sh gl_sdk "$(sed -n 's/^version = "\(.*\)"/\1/p' libs/gl-sdk/pyproject.toml)" dist + + # The gl-sdk-vX.Y.Z GitHub release comes from the crate, in + # publish-crates.yml. + publish-gl-sdk: + name: Publish gl-sdk to PyPI + if: inputs.release && inputs.gl_sdk && !inputs.dry_run + needs: [check-gl-sdk] + runs-on: ubuntu-24.04 + environment: + name: pypi + url: https://pypi.org/project/gl-sdk/ + permissions: + contents: read + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + pattern: gl-sdk-wheel-* + path: dist + merge-multiple: true + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + skip-existing: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 16dc90cb9..38b40af1e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,553 +1,155 @@ -# ============================================================================== -# CRATE PUBLISHING WORKFLOW -# ============================================================================== -# Purpose: Automatically publish Rust crates from a monorepo to crates.io +# The one place to release the SDK: Actions > Release > Run workflow. # -# Trigger: Push a git tag matching the pattern `-v` -# Example: `mycrate-v1.2.3` +# Each artifact's version comes from the repository. The plan job asks the +# registries which of them are published, and a release publishes the +# rest. A dry run (the default) builds, tests and packages every selected +# artifact, published or not, and stops before each upload, so it can run +# at any time, from any branch. Real releases run from main only. # -# Safety Philosophy: This workflow implements multiple validation gates to catch -# issues before publishing. Once a crate version is published to crates.io, it -# cannot be unpublished (only yanked), so we want to ensure everything is correct. +# crates gl-client, gl-util, gl-plugin, gl-signerproxy, gl-cli, gl-sdk, +# gl-sdk-cli to crates.io publish-crates.yml +# python gl-client and gl-sdk to PyPI python.yml +# npm @greenlightcln/glsdk to npm typescript.yml +# swift GreenlightSDK, through Blockstream/gl-sdk-swift swift.yml +# maven com.blockstream:glsdk to Maven Central kotlin.yml # -# Workflow Steps: -# 1. Version Match - Ensures Cargo.toml version matches the tag -# 2. Changelog Format - Validates changelog follows Keep a Changelog format -# 3. Changelog Entry - Ensures this version is documented in changelog -# 4. Semver Check - Prevents accidental breaking changes in minor/patch bumps -# 5. Tests - Runs the crate's test suite -# 6. Publish - Publishes to crates.io and creates GitHub release -# -# These checks should have already passed in CI (on PRs/main branch), but we -# run them again here as a final safety gate before the irreversible publish. -# ============================================================================== +# The crates go first, then the bindings in parallel, so a binding never +# ships a gl-sdk version whose crates failed to publish. Every step skips +# what its registry already has, so re-running a partly failed release +# publishes what is missing. -name: Publish Crate +name: Release on: - push: - tags: - # Matches tags like: mycrate-v1.2.3, my-crate-v0.1.0, etc. - # The 'v' prefix helps distinguish version tags from other tags - - '*-v[0-9]+.[0-9]+.[0-9]+' - - # Manual trigger for dry-run testing - # This allows testing all validation checks without actually publishing workflow_dispatch: inputs: - crate: - description: 'Crate name to test (e.g., gl-client)' - required: true - type: string - version: - description: 'Version to test (e.g., 1.2.3)' - required: true - type: string + dry_run: + description: 'Dry run: build and check everything, publish nothing' + type: boolean + default: true + crates: + description: 'Rust crates (crates.io)' + type: boolean + default: true + python: + description: 'gl-client and gl-sdk (PyPI)' + type: boolean + default: true + npm: + description: '@greenlightcln/glsdk (npm)' + type: boolean + default: true + swift: + description: 'GreenlightSDK (gl-sdk-swift)' + type: boolean + default: true + maven: + description: 'com.blockstream:glsdk (Maven Central)' + type: boolean + default: true + +concurrency: + group: release + cancel-in-progress: false permissions: - contents: write + contents: read + +run-name: ${{ inputs.dry_run && 'Release dry run' || 'Release' }} from ${{ github.ref_name }} jobs: - publish: + plan: runs-on: ubuntu-latest + outputs: + crates: ${{ steps.plan.outputs.crates }} + gl_client_py: ${{ steps.plan.outputs.gl_client_py }} + gl_sdk_py: ${{ steps.plan.outputs.gl_sdk_py }} + npm: ${{ steps.plan.outputs.npm }} + swift: ${{ steps.plan.outputs.swift }} + maven: ${{ steps.plan.outputs.maven }} steps: - # ========================================================================== - # SETUP: Checkout and Parse Tag - # ========================================================================== - - - uses: actions/checkout@v4 - with: - # fetch-depth: 0 gets the full git history, which is required for - # cargo-semver-checks to compare against previous published versions - fetch-depth: 0 - - - name: Parse tag - id: parse + - name: Real releases run from main + if: ${{ !inputs.dry_run && github.ref != 'refs/heads/main' }} run: | - # Check if this is a manual dispatch (dry-run) or tag-triggered run - if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then - # Manual dispatch - use inputs - CRATE="${{ inputs.crate }}" - VERSION="${{ inputs.version }}" - echo "๐Ÿงช DRY-RUN MODE: Testing $CRATE version $VERSION" - echo "dry_run=true" >> $GITHUB_OUTPUT - else - # Tag-triggered - parse from tag - # Extract the full tag name from the GitHub ref - # GITHUB_REF format: refs/tags/mycrate-v1.2.3 - TAG=${GITHUB_REF#refs/tags/} - echo "Full tag: $TAG" - - # Parse the tag to extract crate name and version - # Example: mycrate-v1.2.3 โ†’ CRATE=mycrate, VERSION=1.2.3 - # This regex removes everything from '-v' onwards to get the crate name - CRATE=$(echo $TAG | sed -E 's/-v[0-9]+\.[0-9]+\.[0-9]+$//') - - # This regex extracts just the version numbers after '-v' - VERSION=$(echo $TAG | sed -E 's/.*-v([0-9]+\.[0-9]+\.[0-9]+)$/\1/') - - echo "๐Ÿ“ฆ Publishing $CRATE version $VERSION" - echo "dry_run=false" >> $GITHUB_OUTPUT - fi - - # Make these available to subsequent steps via GITHUB_OUTPUT - echo "crate=$CRATE" >> $GITHUB_OUTPUT - echo "version=$VERSION" >> $GITHUB_OUTPUT - - # Parse semantic version components for later use in semver checks - # We need to know if this is a major/minor/patch bump to determine - # whether breaking changes are allowed - MAJOR=$(echo $VERSION | cut -d. -f1) - MINOR=$(echo $VERSION | cut -d. -f2) - PATCH=$(echo $VERSION | cut -d. -f3) - - echo "major=$MAJOR" >> $GITHUB_OUTPUT - echo "minor=$MINOR" >> $GITHUB_OUTPUT - echo "patch=$PATCH" >> $GITHUB_OUTPUT - - - uses: dtolnay/rust-toolchain@stable + echo "::error::Releasing from $GITHUB_REF, release from main or start a dry run" + exit 1 - - name: Install Protoc - uses: arduino/setup-protoc@v3 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - - # ========================================================================== - # CHECK 1: Version Match - # ========================================================================== - # Rationale: The tag version must match the version in Cargo.toml. - # This prevents accidentally publishing the wrong version or forgetting to - # bump the version in Cargo.toml before tagging. - # - # Why this matters: If we published with a mismatched version, the published - # crate would have a different version than expected, breaking consumer - # dependencies and causing confusion. - # ========================================================================== - - - name: Verify version matches - run: | - echo "๐Ÿ” CHECK 1/5: Verifying Cargo.toml version..." - - # Use cargo metadata to extract the version from Cargo.toml - # This is more reliable than parsing TOML manually - # The jq command filters packages by name and extracts the version field - CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 | \ - jq -r '.packages[] | select(.name == "${{ steps.parse.outputs.crate }}") | .version') - - # Check if we found the crate in the workspace - if [ -z "$CARGO_VERSION" ]; then - echo "โŒ ERROR: Crate '${{ steps.parse.outputs.crate }}' not found in workspace" - echo "" - echo "This usually means:" - echo " 1. The crate name in the tag doesn't match any crate in the workspace" - echo " 2. The crate is not included in the workspace members" - exit 1 - fi - - # Compare versions - if [ "$CARGO_VERSION" != "${{ steps.parse.outputs.version }}" ]; then - echo "โŒ ERROR: Version mismatch!" - echo " Tag version: ${{ steps.parse.outputs.version }}" - echo " Cargo.toml version: $CARGO_VERSION" - echo "" - echo "Please update Cargo.toml to version ${{ steps.parse.outputs.version }}" - echo "and create a new tag, or delete this tag and create a new one matching" - echo "the Cargo.toml version." - exit 1 - fi - - echo "โœ… Version verified: $CARGO_VERSION" - - # ========================================================================== - # CHECK 2: Changelog Format Validation - # ========================================================================== - # Rationale: Validates that the changelog follows the Keep a Changelog format. - # This ensures consistency and makes changelogs machine-readable. - # - # Why this matters: A properly formatted changelog is easier to parse - # programmatically, looks professional, and helps users quickly find - # information about specific versions. It also catches common formatting - # errors like missing dates, wrong heading levels, etc. - # - # Tool choice: python-kacl provides excellent error messages with line - # numbers and specific issues, making it easy to fix problems. - # ========================================================================== - - - name: Setup Python for changelog validation - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - - name: Install python-kacl - run: pip install python-kacl - - - name: Validate changelog format - run: | - echo "๐Ÿ” CHECK 2/5: Validating changelog format..." - - CRATE="${{ steps.parse.outputs.crate }}" - - # Find the crate's directory in the workspace - # We use cargo metadata rather than assuming a directory structure - CRATE_DIR=$(cargo metadata --no-deps --format-version 1 | \ - jq -r ".packages[] | select(.name == \"$CRATE\") | .manifest_path" | \ - xargs dirname) - - # Look for changelog files in order of preference - # We check multiple variants because conventions vary - CHANGELOG="" - for name in CHANGELOG.md changelog.md CHANGELOG; do - if [ -f "$CRATE_DIR/$name" ]; then - CHANGELOG="$CRATE_DIR/$name" - break - fi - done - - if [ -z "$CHANGELOG" ]; then - echo "โŒ ERROR: No changelog found in $CRATE_DIR" - echo "" - echo "Expected one of: CHANGELOG.md, changelog.md, CHANGELOG" - echo "Please create a changelog following the Keep a Changelog format:" - echo "https://keepachangelog.com/" - exit 1 - fi - - echo "Validating $CHANGELOG..." + - uses: actions/checkout@v4 - # Run kacl-cli verify with JSON output for structured error reporting - # The JSON output makes it easier to parse and display errors - # Note: kacl-cli reads CHANGELOG.md from cwd, does not accept file arguments - if (cd "$CRATE_DIR" && kacl-cli verify --json) > /tmp/kacl-output.json 2>&1; then - echo "โœ… Changelog format is valid" - else - echo "โŒ ERROR: Changelog format validation failed" - echo "" - echo "The following issues were found:" - echo "" - - # Parse and display errors in a human-readable format - cat /tmp/kacl-output.json | jq -r '.errors[] | "Line \(.line_number): \(.error_message)\n โ†’ \(.line)\n"' - - echo "" - echo "Please fix these issues and try again." - echo "See https://keepachangelog.com/ for format guidelines." - exit 1 - fi - - # ========================================================================== - # CHECK 3: Changelog Entry Exists - # ========================================================================== - # Rationale: Ensures that this specific version has been documented in the - # changelog before we publish it. - # - # Why this matters: Publishing without changelog documentation means users - # won't know what changed in this version. This is especially important for - # breaking changes or new features. It also enforces good release hygiene - # by ensuring documentation happens before release, not after. - # - # Note: This check is separate from format validation because a changelog - # can be properly formatted but missing the entry for the version being - # published (e.g., if someone forgot to move changes from Unreleased). - # ========================================================================== - - - name: Verify changelog entry exists + - id: plan run: | - echo "๐Ÿ” CHECK 3/5: Checking for changelog entry..." - - CRATE="${{ steps.parse.outputs.crate }}" - VERSION="${{ steps.parse.outputs.version }}" - - # Find the changelog (same logic as CHECK 2) - CRATE_DIR=$(cargo metadata --no-deps --format-version 1 | \ - jq -r ".packages[] | select(.name == \"$CRATE\") | .manifest_path" | \ - xargs dirname) - - CHANGELOG="" - for name in CHANGELOG.md changelog.md CHANGELOG; do - if [ -f "$CRATE_DIR/$name" ]; then - CHANGELOG="$CRATE_DIR/$name" - break - fi + SELECT="" + for G in crates python npm swift maven; do + case "$G" in + crates) ON=${{ inputs.crates }} ;; + python) ON=${{ inputs.python }} ;; + npm) ON=${{ inputs.npm }} ;; + swift) ON=${{ inputs.swift }} ;; + maven) ON=${{ inputs.maven }} ;; + esac + [ "$ON" = true ] && SELECT="$SELECT,$G" done - - # Search for version entry using regex that matches common formats: - # - ## [1.2.3] (preferred Keep a Changelog format) - # - ## 1.2.3 (without brackets) - # - ## [v1.2.3] (with v prefix) - # - # [1.2.3] (single # for projects not using nested headers) - # - # The regex breakdown: - # ^##? - Start of line, one or two # symbols - # \[? - Optional opening bracket - # v? - Optional 'v' prefix - # $VERSION - The actual version number - # \]? - Optional closing bracket - if grep -qE "^##? \[?v?$VERSION\]?" "$CHANGELOG"; then - echo "โœ… Changelog entry found for version $VERSION" - echo "" - echo "Entry preview:" - # Show the version header and the next 10 lines to give context - grep -A 10 -E "^##? \[?v?$VERSION\]?" "$CHANGELOG" | head -15 - else - echo "โŒ ERROR: No changelog entry found for version $VERSION" - echo "" - echo "Please add a changelog entry with one of these formats:" - echo " ## [$VERSION] - $(date +%Y-%m-%d)" - echo " ## $VERSION" - echo " ## [v$VERSION]" - echo "" - echo "Example:" - echo " ## [$VERSION] - $(date +%Y-%m-%d)" - echo " ### Added" - echo " - New feature X" - echo " ### Fixed" - echo " - Bug Y" - echo "" - echo "Current changelog preview:" - head -30 "$CHANGELOG" - exit 1 - fi - - # ========================================================================== - # CHECK 4: Semver Compatibility - # ========================================================================== - # Rationale: Prevents accidental breaking changes in patch and minor version - # bumps by comparing the API surface against the last published version. - # - # Why this matters: Semantic versioning is a contract with users. A patch - # bump (1.2.3 โ†’ 1.2.4) promises only bug fixes, no breaking changes. A minor - # bump (1.2.3 โ†’ 1.3.0) promises new features but no breaking changes. Only - # major bumps (1.2.3 โ†’ 2.0.0) can break compatibility. Breaking this contract - # causes downstream breakage and frustration. - # - # Semver rules applied: - # - For 1.0.0+: Breaking changes require major bump (X.0.0) - # - For 0.x.y: Breaking changes require minor bump (0.X.0) - # (0.x is considered unstable, so minor bump = breaking OK) - # - Patch bumps: Never allow breaking changes - # - # Tool: cargo-semver-checks analyzes the compiled crate's public API and - # detects breaking changes like removed functions, changed signatures, etc. - # ========================================================================== - - - name: Install cargo-semver-checks - uses: cargo-bins/cargo-binstall@main - - run: cargo binstall --no-confirm cargo-semver-checks - - - name: Check semver compatibility - run: | - echo "๐Ÿ” CHECK 4/5: Running semver checks..." - - CRATE="${{ steps.parse.outputs.crate }}" - - # Check if this crate has been published before - # If not, we can't run semver checks (nothing to compare against) - if ! cargo info "$CRATE" --registry crates-io &>/dev/null; then - echo "โ„น๏ธ Crate not yet published to crates.io - skipping semver check" - echo " (First release has nothing to compare against)" - exit 0 - fi - - # Determine if breaking changes are allowed based on the version bump - MAJOR="${{ steps.parse.outputs.major }}" - MINOR="${{ steps.parse.outputs.minor }}" - PATCH="${{ steps.parse.outputs.patch }}" - - SKIP_CHECK=false - - # Check if this is a major version bump (X.0.0) - if [ "$MAJOR" != "0" ]; then - # For stable versions (1.0.0+), only X.0.0 allows breaking changes - if [ "$MINOR" == "0" ] && [ "$PATCH" == "0" ]; then - echo "โ„น๏ธ Major version bump detected ($MAJOR.0.0)" - echo " Breaking changes are allowed per semver rules" - SKIP_CHECK=true - fi - else - # For pre-1.0 versions (0.x.y), 0.X.0 allows breaking changes - # Rationale: 0.x versions are considered unstable/development - if [ "$PATCH" == "0" ]; then - echo "โ„น๏ธ Minor version bump in 0.x series (0.$MINOR.0)" - echo " Breaking changes are allowed in 0.x per semver rules" - SKIP_CHECK=true - fi - fi - - if [ "$SKIP_CHECK" = true ]; then - echo "โญ๏ธ Skipping semver check (breaking changes expected for this bump)" - exit 0 - fi - - # Run semver checks - # If this fails, it means there are breaking changes but the version - # bump doesn't allow them (e.g., patch bump with breaking changes) - echo "Running cargo-semver-checks..." - echo "(Breaking changes are NOT allowed for this version bump)" - - if cargo semver-checks check-release -p "$CRATE"; then - echo "โœ… No semver violations detected" - else - echo "" - echo "โŒ ERROR: Semver violations detected!" - echo "" - echo "Breaking changes were found, but this version bump doesn't allow them." - echo "" - echo "Your options:" - echo " 1. Fix the breaking changes to maintain API compatibility" - if [ "$MAJOR" != "0" ]; then - echo " 2. Bump to next major version (e.g., $MAJOR.0.0 โ†’ $(($MAJOR + 1)).0.0)" - else - echo " 2. Bump to next minor version (e.g., 0.$MINOR.x โ†’ 0.$(($MINOR + 1)).0)" - fi - echo "" - echo "See cargo-semver-checks output above for details on what broke." - exit 1 - fi - - # ========================================================================== - # CHECK 5: Run Tests - # ========================================================================== - # Rationale: Final verification that the crate's tests pass before publish. - # - # Why this matters: Even though tests should have passed in CI on the PR, - # we run them again here as a final gate. This catches edge cases like: - # - Someone force-pushed changes after CI passed - # - Flaky tests that passed in CI but might fail now - # - Issues with the tag itself or checkout process - # - # Note: We use `-p ` to only test this specific crate, not the - # entire workspace. This is faster and only tests what we're publishing. - # ========================================================================== - - - name: Run tests - run: | - echo "๐Ÿ” CHECK 5/5: Running tests..." - - # -p flag: Run tests only for this specific crate - # This is important in a monorepo to avoid testing unrelated crates - cargo test -p ${{ steps.parse.outputs.crate }} - - echo "โœ… All tests passed" - - # ========================================================================== - # PUBLISH: Publish to crates.io and Create GitHub Release - # ========================================================================== - # Rationale: All checks passed, now we can safely publish. - # - # Why two steps (crates.io + GitHub release): - # 1. crates.io publish - Makes the crate available to Rust users - # 2. GitHub release - Creates a release on GitHub with changelog notes, - # providing a nice UI for browsing releases and downloading source - # - # Note: Publishing to crates.io is IRREVERSIBLE. You cannot unpublish, - # only yank (which hides from new installs but doesn't delete). That's - # why we have all the checks above! - # ========================================================================== - - - name: Publish to crates.io - if: steps.parse.outputs.dry_run == 'false' - run: | - CRATE="${{ steps.parse.outputs.crate }}" - VERSION="${{ steps.parse.outputs.version }}" - echo "๐Ÿš€ Publishing $CRATE v$VERSION to crates.io..." - - # Check if this version is already published (idempotent retries) - if cargo info "${CRATE}@${VERSION}" --registry crates-io &>/dev/null; then - echo "โœ… $CRATE v$VERSION is already published on crates.io โ€” skipping" - else - cargo publish -p "$CRATE" - echo "โœ… Successfully published to crates.io!" - fi - echo "๐Ÿ”— https://crates.io/crates/$CRATE" - env: - # The token is stored in GitHub Secrets for security - # To create one: https://crates.io/settings/tokens - # Add it to repo: Settings โ†’ Secrets and variables โ†’ Actions - CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} - - - name: Create GitHub Release - if: steps.parse.outputs.dry_run == 'false' - uses: softprops/action-gh-release@v1 - with: - # Use the tag that triggered this workflow - tag_name: ${{ github.ref }} - - # Format: "mycrate v1.2.3" - name: ${{ steps.parse.outputs.crate }} v${{ steps.parse.outputs.version }} - - # Release notes body - # In the future, you could extract the changelog section here - # to automatically populate the release notes - body: | - Published ${{ steps.parse.outputs.crate }} v${{ steps.parse.outputs.version }} to crates.io - - ๐Ÿ”— [View on crates.io](https://crates.io/crates/${{ steps.parse.outputs.crate }}) - - See [CHANGELOG](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/CHANGELOG.md) for details. - env: - # GITHUB_TOKEN is automatically provided by GitHub Actions - # No need to create this secret manually - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Dry-run complete - if: steps.parse.outputs.dry_run == 'true' - run: | - echo "โœ… DRY-RUN COMPLETE!" - echo "" - echo "All validation checks passed for ${{ steps.parse.outputs.crate }} v${{ steps.parse.outputs.version }}" - echo "" - echo "The following checks were successful:" - echo " โœ… Version matches Cargo.toml" - echo " โœ… Changelog format is valid" - echo " โœ… Changelog entry exists" - echo " โœ… Semver compatibility check passed" - echo " โœ… All tests passed" - echo "" - echo "To publish for real, push a tag:" - echo " git tag ${{ steps.parse.outputs.crate }}-v${{ steps.parse.outputs.version }}" - echo " git push origin ${{ steps.parse.outputs.crate }}-v${{ steps.parse.outputs.version }}" - -# ============================================================================== -# MAINTENANCE NOTES -# ============================================================================== -# -# Common modifications you might want to make: -# -# 1. Change tag format: -# - Modify the regex in the `on.push.tags` section -# - Update the parsing logic in the "Parse tag" step -# -# 2. Skip semver checks entirely (not recommended): -# - Remove or comment out CHECK 4 -# -# 3. Add additional checks: -# - cargo clippy for linting -# - cargo fmt --check for formatting -# - Documentation build check: cargo doc --no-deps -# -# 4. Auto-extract changelog for GitHub release: -# - Use kacl-cli or similar tool to extract the version section -# - Replace the static body in "Create GitHub Release" -# -# 5. Publish multiple crates at once: -# - This workflow publishes one crate at a time by design -# - For dependency order, consider using cargo-release instead -# -# 6. Customize python-kacl validation rules: -# - Create a .kacl.yml file in your crate directories -# - Pass it to kacl-cli: kacl-cli verify --config .kacl.yml -# -# Troubleshooting: -# -# - If semver-checks fails unexpectedly: -# Run locally: cargo semver-checks check-release -p -# -# - If changelog validation fails: -# Run locally: kacl-cli verify --json CHANGELOG.md | jq -# -# - If version mismatch: -# Ensure you updated Cargo.toml before tagging -# -# - If crate not found: -# Check workspace members in root Cargo.toml -# ============================================================================== + python3 .github/scripts/release_plan.py --select "${SELECT#,}" \ + ${{ inputs.dry_run && '--dry-run' || '' }} + + crates: + needs: plan + if: needs.plan.outputs.crates != '' + uses: ./.github/workflows/publish-crates.yml + with: + crates: ${{ needs.plan.outputs.crates }} + dry_run: ${{ inputs.dry_run }} + secrets: inherit + permissions: + contents: write + + # The bindings wait for the crates, but also run when there were none to + # publish. + python: + needs: [plan, crates] + if: >- + !failure() && !cancelled() && + (needs.plan.outputs.gl_client_py == 'true' || needs.plan.outputs.gl_sdk_py == 'true') + uses: ./.github/workflows/python.yml + with: + release: true + dry_run: ${{ inputs.dry_run }} + gl_client: ${{ needs.plan.outputs.gl_client_py == 'true' }} + gl_sdk: ${{ needs.plan.outputs.gl_sdk_py == 'true' }} + secrets: inherit + permissions: + contents: write + id-token: write + + npm: + needs: [plan, crates] + if: ${{ !failure() && !cancelled() && needs.plan.outputs.npm == 'true' }} + uses: ./.github/workflows/typescript.yml + with: + release: true + dry_run: ${{ inputs.dry_run }} + secrets: inherit + permissions: + contents: read + + swift: + needs: [plan, crates] + if: ${{ !failure() && !cancelled() && needs.plan.outputs.swift == 'true' }} + uses: ./.github/workflows/swift.yml + with: + release: true + dry_run: ${{ inputs.dry_run }} + secrets: inherit + permissions: + contents: write + + maven: + needs: [plan, crates] + if: ${{ !failure() && !cancelled() && needs.plan.outputs.maven == 'true' }} + uses: ./.github/workflows/kotlin.yml + with: + release: true + dry_run: ${{ inputs.dry_run }} + secrets: inherit + permissions: + contents: write diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml new file mode 100644 index 000000000..df7767c2f --- /dev/null +++ b/.github/workflows/swift.yml @@ -0,0 +1,214 @@ +name: Swift + +# Builds the gl-sdk XCFramework and Swift bindings, and checks them with +# Blockstream/gl-sdk-swift's own publish scripts from its main branch: +# scripts/prepare.sh renders Package.swift for the build and commits and +# tags it locally, scripts/check-package.sh compiles that package against +# the fresh XCFramework. Nothing leaves the runner, so every build is a +# dry run of the Swift release. +# +# When release.yml calls it for a real release, it also attaches the zip, +# its checksum and glsdk.swift to the gl-sdk-vX.Y.Z release here, where +# gl-sdk-swift's hourly publish.yml picks them up. It then waits for the +# X.Y.Z tag in gl-sdk-swift and verifies it the way SwiftPM installs it, +# so the outcome shows on this repository's Actions page. Neither +# repository writes to the other, so no cross-repository token is needed. + +on: + push: + branches: + - main + paths: + - '.github/workflows/swift.yml' + - 'build/**' + - 'libs/gl-client/**' + - 'libs/gl-sdk/**' + - 'libs/proto/**' + - 'Cargo.lock' + pull_request: + paths: + - '.github/workflows/swift.yml' + - 'build/**' + - 'libs/gl-client/**' + - 'libs/gl-sdk/**' + - 'libs/proto/**' + - 'Cargo.lock' + workflow_dispatch: + # Publishing runs only when release.yml calls this workflow. + workflow_call: + inputs: + release: + type: boolean + default: false + dry_run: + type: boolean + default: true + +# A called workflow sees the caller's github.workflow, so the group names +# this workflow itself, or it would share the group with the other +# workflows release.yml calls. +concurrency: + group: swift-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +permissions: + contents: read + +env: + SWIFT_REPO: Blockstream/gl-sdk-swift + +jobs: + build: + name: Build XCFramework + runs-on: macos-15 + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@stable + with: + targets: aarch64-apple-ios,aarch64-apple-ios-sim,x86_64-apple-ios + + - name: Determine the version + id: version + run: | + VERSION=$(cargo metadata --no-deps --format-version 1 | \ + jq -r '.packages[] | select(.name == "gl-sdk") | .version') + echo "VERSION=$VERSION" >> "$GITHUB_ENV" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "Building gl-sdk $VERSION" + + - uses: Swatinem/rust-cache@v2 + + - name: Install Protoc + uses: arduino/setup-protoc@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Install Task + uses: arduino/setup-task@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Install XcodeGen and yq + run: brew install xcodegen yq + + - name: Set the framework version + run: | + yq e '.targets.glsdkFFI.settings.MARKETING_VERSION = env(VERSION)' -i build/project.yml + yq e '.targets.glsdkFFI.settings.CURRENT_PROJECT_VERSION = "1"' -i build/project.yml + + - name: Build + run: task build:swift + + - name: Package + run: | + mkdir -p dist + (cd target && zip -9 -r -q ../dist/glsdkFFI.xcframework.zip glsdkFFI.xcframework) + cp target/swift/glsdk.swift dist/glsdk.swift + # SwiftPM verifies the zip against this checksum, the SHA-256. + swift package compute-checksum dist/glsdkFFI.xcframework.zip > dist/glsdkFFI.xcframework.zip.checksum + ls -la dist + + - uses: actions/checkout@v4 + with: + repository: ${{ env.SWIFT_REPO }} + ref: main + path: gl-sdk-swift + fetch-depth: 0 + + # What gl-sdk-swift's publish.yml does with these assets, short of + # pushing: render and commit Package.swift, tag the version, and + # compile the package against the zip. + - name: Prepare the Swift package + working-directory: gl-sdk-swift + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + # A version that is published already cannot be tagged again, + # prepare it as a pre-release of itself instead. + V="$VERSION" + if git rev-parse -q --verify "refs/tags/$V" >/dev/null; then + V="$VERSION-check.$GITHUB_RUN_NUMBER" + echo "::notice::$VERSION is published in gl-sdk-swift already, preparing it as $V" + fi + scripts/prepare.sh "$V" "$GITHUB_WORKSPACE/dist" \ + "https://github.com/$GITHUB_REPOSITORY/releases/download/gl-sdk-v$VERSION/glsdkFFI.xcframework.zip" + cat Package.swift + + - name: Compile the Swift package + run: gl-sdk-swift/scripts/check-package.sh dist/glsdkFFI.xcframework.zip + + - uses: actions/upload-artifact@v4 + with: + name: swift + path: dist/ + if-no-files-found: error + + attach: + name: Attach to the gl-sdk release + if: inputs.release && !inputs.dry_run + needs: build + runs-on: ubuntu-latest + permissions: + contents: write + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + TAG: gl-sdk-v${{ needs.build.outputs.version }} + steps: + - uses: actions/download-artifact@v4 + with: + name: swift + path: dist + + # publish-crates.yml creates the release when it publishes the gl-sdk + # crate. A Swift-only release creates it here. + - name: Upload the release assets + run: | + if ! gh release view "$TAG" >/dev/null 2>&1; then + gh release create "$TAG" --target "$GITHUB_SHA" --title "gl-sdk ${TAG#gl-sdk-v}" \ + --notes "See the [gl-sdk changelog](https://github.com/$GH_REPO/blob/$TAG/libs/gl-sdk/CHANGELOG.md)." \ + || gh release view "$TAG" >/dev/null # created concurrently + fi + gh release upload "$TAG" --clobber \ + dist/glsdkFFI.xcframework.zip \ + dist/glsdkFFI.xcframework.zip.checksum \ + dist/glsdk.swift + gh release view "$TAG" --json assets --jq '.assets[].name' + + # gl-sdk-swift publishes within the hour, at 17 past, and GitHub can + # delay scheduled runs. Running its publish.yml by hand is quicker. + published: + name: Wait for gl-sdk-swift + needs: [build, attach] + runs-on: ubuntu-latest + timeout-minutes: 120 + env: + VERSION: ${{ needs.build.outputs.version }} + steps: + - uses: actions/checkout@v4 + with: + repository: ${{ env.SWIFT_REPO }} + ref: main + path: gl-sdk-swift + + - name: Wait for the tag + run: | + echo "::notice::Waiting for $VERSION in https://github.com/$SWIFT_REPO, run its publish.yml to skip the wait" + until git ls-remote --exit-code --tags "https://github.com/$SWIFT_REPO" "refs/tags/$VERSION" >/dev/null; do + sleep 120 + done + + - name: Verify the package + run: | + gl-sdk-swift/scripts/verify.sh "$VERSION" + # The package must download the zip attached by this run. + URL=$(curl -fsSL "https://raw.githubusercontent.com/$SWIFT_REPO/refs/tags/$VERSION/Package.swift" \ + | sed -nE 's/.*url: "([^"]+)".*/\1/p') + WANT="https://github.com/$GITHUB_REPOSITORY/releases/download/gl-sdk-v$VERSION/glsdkFFI.xcframework.zip" + if [ "$URL" != "$WANT" ]; then + echo "::error::Package.swift at $VERSION downloads $URL, not $WANT" + exit 1 + fi diff --git a/.github/workflows/typescript.yml b/.github/workflows/typescript.yml index 160f87523..18b6e9cb3 100644 --- a/.github/workflows/typescript.yml +++ b/.github/workflows/typescript.yml @@ -7,45 +7,49 @@ on: - main pull_request: {} workflow_dispatch: + # Publishing runs only when release.yml calls this workflow. + workflow_call: inputs: - shouldPublish: - description: 'Publish to NPM' + release: + type: boolean + default: false + dry_run: type: boolean default: true name: Typescript Library jobs: + # Whether the version in package.json is on npm yet. Comparing against + # the registry rather than against the parent commit stays correct for + # rebase-merges, where the version bump is not the tip commit, and lets + # a re-run publish a version that an earlier run failed to publish. check-version: runs-on: ubuntu-latest outputs: - version-changed: ${{ steps.check.outputs.changed }} + unpublished: ${{ steps.check.outputs.unpublished }} defaults: run: working-directory: libs/gl-sdk-napi steps: - uses: actions/checkout@v4 - with: - fetch-depth: 2 - + - id: check run: | - CURRENT_VERSION=$(cat package.json | jq -r '.version') - git checkout HEAD^ - PREVIOUS_VERSION=$(cat package.json | jq -r '.version') - git checkout - - if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then - echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION" - echo "changed=true" >> $GITHUB_OUTPUT + NAME=$(jq -r '.name' package.json) + VERSION=$(jq -r '.version' package.json) + # The package document lists every published version. A failed + # request fails the job rather than passing for "unpublished". + DOC=$(curl -fsS "https://registry.npmjs.org/${NAME/\//%2F}") + if ! jq -e --arg v "$VERSION" '.versions | has($v)' <<<"$DOC" >/dev/null; then + echo "${NAME}@${VERSION} is not on npm yet" + echo "unpublished=true" >> $GITHUB_OUTPUT else - echo "::warning::Will not trigger publishing because version is unchanged" - echo "changed=false" >> $GITHUB_OUTPUT - exit 0 + echo "${NAME}@${VERSION} is already on npm" + echo "unpublished=false" >> $GITHUB_OUTPUT fi build: - needs: check-version - if: needs.check-version.outputs.version-changed == 'true' strategy: fail-fast: false matrix: @@ -62,7 +66,7 @@ jobs: target: x86_64-apple-darwin strip: strip -x *.node - - host: macos-14 + - host: macos-15 target: aarch64-apple-darwin strip: strip -x *.node @@ -238,11 +242,13 @@ jobs: shell: bash command: cd libs/gl-sdk-napi && npm test -- tests/basic.spec.ts + # A dry run packs and checks the package like a release and stops before + # the upload. It also runs for a version npm already has. publish: name: Publish to NPM runs-on: ubuntu-latest - needs: test - if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch' && inputs.shouldPublish == true) + needs: [check-version, test] + if: inputs.release && (inputs.dry_run || needs.check-version.outputs.unpublished == 'true') defaults: run: @@ -263,6 +269,7 @@ jobs: - name: Download all artifacts uses: actions/download-artifact@v4 with: + pattern: bindings-* path: artifacts - name: Move artifacts to package directory @@ -275,12 +282,7 @@ jobs: done ls -la *.* - - name: List package contents - run: npm pack --dry-run - - name: Publish to NPM - run: | - echo "Token length: ${#NODE_AUTH_TOKEN}" - npm publish --access public + run: npm publish --access public ${{ inputs.dry_run && '--dry-run' || '' }} env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index be20e2bb2..000000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,20 +0,0 @@ -variables: - GIT_DEPTH: 1 - CI_IMAGE: blockstream/gli-ci - -stages: - - build - - deploy - -default: - image: ${CI_IMAGE}:${CI_IMAGE_VER} # set in CI env vars - -include: - - gitlab/**.yml - -## disables MR-triggered pipelines and allows only branch-triggered pipelines -workflow: - rules: - - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - when: never - - when: always diff --git a/contrib/maven-central/check-bundle.sh b/contrib/maven-central/check-bundle.sh new file mode 100755 index 000000000..32d0cfbb8 --- /dev/null +++ b/contrib/maven-central/check-bundle.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +# Checks a com.blockstream:glsdk release bundle and signs it the way Maven +# Central requires. +# +# check-bundle.sh +# +# The bundle is what `./gradlew :lib:publishAllPublicationsToBundleRepository` +# writes to libs/gl-sdk-android/lib/build/maven-bundle, zipped: the +# publications in the Maven repository layout, unsigned. This checks the +# layout and the POMs, writes the md5 and sha1 checksums Central requires, +# signs every file with the given key from the gpg keyring, checks the +# signatures and zips the result to , ready for the Central +# Portal's upload API. MAVEN_SIGNING_KEY_PASSWORD is the key's passphrase, +# if it has one. +# +# The Release workflow runs it with a throwaway key on every release, dry +# run or not, so a bundle that Central would reject never leaves GitHub. +# Runs on macOS (bash 3.2) and Linux. +set -euo pipefail + +[ $# = 4 ] || { echo "usage: $0 " >&2; exit 2; } +ZIP=$(cd "$(dirname "$1")" && pwd)/$(basename "$1") +VERSION=$2 KEY_ID=$3 +OUT=$(cd "$(dirname "$4")" && pwd)/$(basename "$4") + +digest() { openssl dgst "-$1" "$2" | sed 's/.*= //'; } + +WORK=$(mktemp -d) +trap 'rm -rf "$WORK"' EXIT +mkdir "$WORK/in" "$WORK/out" +unzip -q "$ZIP" -d "$WORK/in" +cd "$WORK/in" + +# Only the version directories go to Central. Gradle also writes +# maven-metadata.xml one level up, which Central does not take. +DIRS=$(find . -type d -path "./com/blockstream/glsdk*/$VERSION" | sort) +[ -n "$DIRS" ] || { echo "error: no com/blockstream/glsdk*/$VERSION in $ZIP" >&2; exit 1; } +for d in $DIRS; do + mkdir -p "$WORK/out/$d" + find "$d" -maxdepth 1 -type f ! -name '*.md5' ! -name '*.sha1' ! -name '*.sha256' ! -name '*.sha512' ! -name '*.asc' \ + -exec cp {} "$WORK/out/$d/" \; +done +cd "$WORK/out" + +for d in $DIRS; do + NAME=$(basename "$(dirname "$d")") + POM="$d/$NAME-$VERSION.pom" + [ -f "$POM" ] || { echo "error: $NAME has no $NAME-$VERSION.pom" >&2; exit 1; } + # What Central requires of every POM. + for tag in name description url licenses developers scm; do + grep -q "<$tag>" "$POM" || { echo "error: $POM has no <$tag>" >&2; exit 1; } + done + for c in sources javadoc; do + [ -f "$d/$NAME-$VERSION-$c.jar" ] || echo "warning: $NAME has no $c jar, Central may reject it" >&2 + done +done + +FILES=$(find . -type f | sort) +for f in $FILES; do + digest md5 "$f" > "$f.md5" + digest sha1 "$f" > "$f.sha1" + printf '%s' "${MAVEN_SIGNING_KEY_PASSWORD:-}" | gpg --batch --yes --quiet --pinentry-mode loopback --passphrase-fd 0 \ + --local-user "$KEY_ID" --armor --detach-sign --output "$f.asc" "$f" + gpg --batch --quiet --verify "$f.asc" "$f" 2>/dev/null || { echo "error: the signature of $f does not verify" >&2; exit 1; } +done +echo "Signed $(echo "$FILES" | wc -l | tr -d ' ') files with $KEY_ID:" +echo "$FILES" | sed 's/^/ /' + +rm -f "$OUT" +zip -q -r "$OUT" com +echo "com.blockstream:glsdk:$VERSION is ready for Maven Central: $OUT" diff --git a/docs/src/reference/releases.md b/docs/src/reference/releases.md index 5d1acc463..08ecad6d4 100644 --- a/docs/src/reference/releases.md +++ b/docs/src/reference/releases.md @@ -1,67 +1,105 @@ # Releasing the Greenlight SDK This page documents how a version of the Greenlight SDK is cut and -published, and which automation is (and is not) wired up. The SDK is a -Cargo workspace that is published to several registries at once, so a -release touches multiple pipelines with slightly different triggers and -failure modes. +published. The SDK is a Cargo workspace with bindings for several +languages, published to five registries. One workflow releases all of +them: **Actions > Release > Run workflow** in `Blockstream/greenlight`. ## What gets published, and by what -| Artifact | Workflow | Trigger | Registry | -| --- | --- | --- | --- | -| `gl-client`, `gl-sdk`, `gl-sdk-cli` (Rust) | `.github/workflows/release.yml` | push of a `*-v*` tag | crates.io | -| `@greenlightcln/glsdk` (npm) | `.github/workflows/typescript.yml` | push to `main`, gated on a version change | npm | -| `gl-client-py`, `gl-sdk` (Python wheels) | `.github/workflows/python.yml` | push to `main` / PR | **built only โ€” not published** | -| `clnvm` (Python) | `task clnvm:publish` (manual `twine`) | manual | PyPI | +| Group | Artifact | Version from | Registry | Workflow | +| --- | --- | --- | --- | --- | +| crates | `gl-client`, `gl-util`, `gl-plugin`, `gl-signerproxy`, `gl-cli`, `gl-sdk`, `gl-sdk-cli` | each `Cargo.toml` | crates.io | `publish-crates.yml` | +| python | `gl-client` (`libs/gl-client-py`) | its `pyproject.toml` | PyPI | `python.yml` | +| python | `gl-sdk` (`libs/gl-sdk`) | its `pyproject.toml` | PyPI | `python.yml` | +| npm | `@greenlightcln/glsdk` | `libs/gl-sdk-napi/package.json` | npm | `typescript.yml` | +| swift | `GreenlightSDK` | the `gl-sdk` crate | tag `X.Y.Z` in `Blockstream/gl-sdk-swift` | `swift.yml` | +| maven | `com.blockstream:glsdk` | `libraryVersion` in `libs/gl-sdk-android/gradle.properties` | Maven Central | `kotlin.yml` | +| | `clnvm` (Python) | | PyPI | manual `task clnvm:publish` | -!!! warning - The Python SDK wheels are built and tested in CI but there is - currently **no publish step** for them. Publishing them, if it is - ever wanted, still has to be wired up (see - [Gaps and gotchas](#gaps-and-gotchas)). +`release.yml` calls the other workflows. On their own, on pushes and +pull requests, they only build and test. Pushing a release tag no +longer publishes anything. -## Tag conventions +## Cutting a release -The crates.io workflow fires on any tag matching: +1. **Bump versions and changelogs.** Set the new version of everything + going out, and move the `Unreleased` section of each `CHANGELOG.md` + under a dated version heading. The plan job enforces that the + bindings of one SDK release agree: + - `libs/gl-sdk/pyproject.toml` and `libraryVersion` match the + `gl-sdk` crate; the Swift package always takes the crate's version; + - `libs/gl-client-py/pyproject.toml` matches the `gl-client-py` + crate, and `package.json` matches the `gl-sdk-node` crate. +2. **Merge to `main`.** +3. **Run a dry run**: Actions > Release > Run workflow, with *Dry run* + ticked (the default). It runs from any branch, so a release can also + be tried before merging. +4. **Run the release** from `main` with *Dry run* unticked. Untick the + groups that should not go out. -```text -*-v[0-9]+.[0-9]+.[0-9]+ -``` +The plan job asks each registry whether the version from the +repository is published and writes a table of what the run will do to +the run's summary page. A real release publishes only what is missing, +so re-running a partly failed release finishes it. A dry run exercises +every selected artifact, published or not, so it can run at any time, +for example to check that the release pipeline still works. -so a release tag looks like `gl-client-v0.7.0`. Everything before the -last `-v` is taken as the crate name and the rest as the version. The -workflow then enforces a **"Version Match"** check: the tag version must -equal the `version` in that crate's `Cargo.toml`. +The crates go first, the bindings after them in parallel, so a binding +never ships a `gl-sdk` version whose crates failed to publish. -## Cutting a release +## What a dry run checks -1. **Bump versions and changelogs.** For each crate going out, set - `version` in its `Cargo.toml` (and `package.json` for the npm - binding), and move the `Unreleased` section of its `CHANGELOG.md` - under a dated version heading. -2. **Merge to `main`.** -3. **Publish the Rust crates** by pushing one semver tag per crate, on - the commit whose `Cargo.toml` matches: - - ```bash - git tag -a gl-client-v0.7.0 - git tag -a gl-sdk-v0.5.0 - git tag -a gl-sdk-cli-v0.4.0 - git push origin --tags - ``` - -4. **Publish in dependency order.** The higher-level crates depend on - the lower-level ones, so publish (or re-run) `gl-client` first, then - `gl-sdk`, then `gl-sdk-cli`. If they race, the dependent crate fails - with `failed to select a version for the requirement gl-client = ...` - simply because its dependency is not on crates.io yet. The publish - step is idempotent โ€” anything already on crates.io is skipped โ€” so a - re-run after the dependency lands is enough; the tags do not need to - be re-pushed. - -5. **The npm binding** is published automatically by `typescript.yml` on - the merge push (see the gotcha below). +Every publication step has a dry-run mode that stops right before the +upload: + +| Group | Dry run | Real release adds | +| --- | --- | --- | +| crates | changelog format and entry, `cargo semver-checks` against the last release, tests, and `cargo publish --dry-run` of all crates together. Cargo builds each against the others' packages through a local registry overlay, so this passes before any of them is on crates.io. | the upload in dependency order, and a `-vX.Y.Z` GitHub release per crate | +| python | the wheels and sdist are built and smoke tested, and carry the expected version; `twine check --strict` | the upload, and a `gl-client-py-vX.Y.Z` GitHub release | +| npm | the native modules are built for every platform and tested; `npm publish --dry-run` | the upload | +| swift | the XCFramework is built; gl-sdk-swift's `scripts/prepare.sh` renders, commits and tags the package locally, and `scripts/check-package.sh` compiles it for the iOS simulator against the fresh zip | the assets on the `gl-sdk-vX.Y.Z` release, then a wait for gl-sdk-swift to tag `X.Y.Z` and a check of it the way SwiftPM installs it | +| maven | the library is built and tested, and the Maven Central bundle is built and run through `contrib/maven-central/check-bundle.sh` with a throwaway key: POM fields, checksums, every file signed and verified | the unsigned bundle on the `gl-sdk-vX.Y.Z` release, then a wait until it is on repo1.maven.org | + +The plan also catches what only a registry would reject otherwise, such +as a wildcard (`"*"`) dependency requirement, which crates.io refuses +on upload. To see the plan without running anything: + +```bash +python3 .github/scripts/release_plan.py --dry-run +``` + +## The Swift package + +SwiftPM resolves packages by repository, so the package lives in +`Blockstream/gl-sdk-swift` while greenlight builds it. Neither +repository writes to the other, so no cross-repository token is needed: + +1. `swift.yml` attaches `glsdkFFI.xcframework.zip`, its checksum and + `glsdk.swift` to the `gl-sdk-vX.Y.Z` release here. +2. `publish.yml` in gl-sdk-swift polls hourly for such releases, commits + a `Package.swift` whose binary target points at the zip here, and + tags and releases `X.Y.Z` there. +3. `swift.yml` waits for that tag, for up to two hours, and verifies it. + To skip the wait, run `publish.yml` in gl-sdk-swift by hand. + +`swift.yml` runs gl-sdk-swift's scripts from its `main` branch in every +build, so changes to the templates there are tested here. GitHub +disables a scheduled workflow after 60 days without activity in its +repository; if a release waits forever, re-enable `publish.yml` on +gl-sdk-swift's Actions tab. + +## The Maven package + +GitHub holds no Maven Central credentials or signing key. `kotlin.yml` +builds the publications, unsigned, in the Maven repository layout +(`./gradlew :lib:publishAllPublicationsToBundleRepository`), checks them +with `contrib/maven-central/check-bundle.sh` and a throwaway key, and +attaches them to the `gl-sdk-vX.Y.Z` release as `glsdk-maven-X.Y.Z.zip` +with its `.sha256`. Blockstream's release infrastructure picks the +bundle up within the hour, signs it with Blockstream's key and uploads +it. `kotlin.yml` waits, for up to three hours, until the version is on +repo1.maven.org. ## Cargo manifest requirements @@ -80,45 +118,34 @@ license = "MIT" repository = "https://github.com/Blockstream/greenlight" ``` -(As of the `v26.06gl1` release, `gl-sdk-cli` was missing these and -needed a small follow-up before it would publish.) - -## Secrets +Every workspace crate is released unless it sets `publish = false`, as +`gl-examples`, `uniffi-bindgen`, `gl-client-py` and `gl-sdk-node` do. -Publishing reads these GitHub Actions secrets (in -`Blockstream/greenlight`): +## Secrets and registry setup -| Secret | Consumed by | Notes | +| Secret or setting | Used by | Notes | | --- | --- | --- | -| `CRATES_IO_TOKEN` | `release.yml` | crates.io publishing | +| `CRATES_IO_TOKEN` | `publish-crates.yml` | crates.io publishing | | `NPM_TOKEN` | `typescript.yml` | npm publishing | +| PyPI trusted publisher | `python.yml` | per PyPI project: owner `Blockstream`, repository `greenlight`, workflow **`release.yml`**, environment `pypi`. The OIDC token names the workflow that started the run, not the called `python.yml`. For a project not on PyPI yet, add a *pending* publisher. | | `TWINE_PASSWORD` | manual `task clnvm:publish` only | PyPI; not used by CI | -| `CARGO_REGISTRY_TOKEN` | *none* | orphaned โ€” `release.yml` maps the env var from `CRATES_IO_TOKEN` instead | -| `RELEASE_PLZ_TOKEN` | *none* | orphaned โ€” `release-plz.toml` exists but no workflow runs release-plz | +| `CARGO_REGISTRY_TOKEN` | *none* | orphaned, `publish-crates.yml` maps the env var from `CRATES_IO_TOKEN` instead | +| `RELEASE_PLZ_TOKEN` | *none* | orphaned, `release-plz.toml` exists but no workflow runs release-plz | Long-lived tokens must be **rotated roughly every 90 days**, or immediately on any auth failure such as a `403 authentication failed` from `cargo publish`. To rotate a crates.io token: sign in to crates.io as an owner of *all* published crates, create a token with `publish-new` + `publish-update` (leave the IP prefix blank, since the -runners use dynamic IPs), then update `CRATES_IO_TOKEN` and re-publish -in dependency order. +runners use dynamic IPs), then update `CRATES_IO_TOKEN` and re-run the +release. ## Gaps and gotchas -- **npm publish skips after a rebase-merge.** `typescript.yml` decides - whether to publish by diffing `package.json` against its immediate - parent (`HEAD^`). A normal PR merge puts the version bump on the tip, - so it fires; a **rebase-merge buries the bump below the tip**, the diff - sees "unchanged", and `check-version` skips build, test **and** publish. - A `workflow_dispatch` does not help, because `publish` transitively - depends on the skipped `test` job. The robust fix is to compare against - the version already published to npm (`npm view @greenlightcln/glsdk - version`) rather than `HEAD^`. -- **Python wheels are not published.** `python.yml` builds them and - `import glclient` smoke-tests them, but nothing uploads them to PyPI. - If Python releases are wanted, add a publish job (ideally PyPI trusted - publishing, which needs no token) triggered by `gl-client-py-v*` / - `gl-sdk-v*` tags. -- **Swift is a separate repository.** `gl-sdk-swift` is published from - its own repo (`Blockstream/gl-sdk-swift`) and is out of scope here. +- **The `gl-sdk` Python wheel is retagged.** hatchling builds it as + `py3-none-any`, but it bundles the native library, so `python.yml` + retags each wheel with the platform the library was built for. The + Linux libraries are built with `cargo zigbuild` against glibc 2.17, + which is what the `manylinux_2_17` tag promises. The bindings in the + wheel are regenerated from the bundled library, and the job warns if + the committed `libs/gl-sdk/glsdk/glsdk.py` differs from them. diff --git a/examples/rust/Cargo.toml b/examples/rust/Cargo.toml index 88a9128f4..22bcbcf1f 100644 --- a/examples/rust/Cargo.toml +++ b/examples/rust/Cargo.toml @@ -2,6 +2,7 @@ name = "gl-examples" version = "0.1.0" edition = "2021" +publish = false # an example, not a library [dependencies] gl-client = { path = "../../libs/gl-client" } diff --git a/gitlab/README.md b/gitlab/README.md deleted file mode 100644 index ac30d512c..000000000 --- a/gitlab/README.md +++ /dev/null @@ -1,19 +0,0 @@ -## Gitlab Pipelines -There are 5 Greenlight packaged binaries/libraries that are published - 1 Python packages and 4 Rust crates. - -The builds are triggered by certain tag formats. Make sure to include a patch as well since the Rust compiler requires that (applicable to `gl-client-py` as well). - -Packages and tag formats ---- -If a tagged release doesn't work, it can be retried by adding an `_N` suffix after the date part. For example: `..YYYYMMDD_1-x.x.x` or `..YYYYMMDD_25-x.x.x`. - -**Note:** The last part of the tag (after the `-`) is used to change the version to be pushed. If different from what's in the respective `pyproject.toml`/`Cargo.toml`, the TOML files will be overwritten via `sed` by the Gitlab job. - -### PyPI -* gl-client-py - `glclientpy_YYYYMMDD-x.x.x` - -### crates.io -* gl-client - `glclient_YYYYMMDD-x.x.x` -* gl-plugin - `glplugin_YYYYMMDD-x.x.x` -* gl-signerproxy - `glsignerproxy_YYYYMMDD-x.x.x` -* gl-cli -`glcli_YYYYMMDD-x.x.x` diff --git a/gitlab/build-crates.yml b/gitlab/build-crates.yml deleted file mode 100644 index 5db19fa0a..000000000 --- a/gitlab/build-crates.yml +++ /dev/null @@ -1,42 +0,0 @@ -.build_rust_prep: - extends: .build_setup - when: manual - before_script: - - export NEW_VER=$(echo ${CI_COMMIT_TAG} | cut -d'-' -f2) - - sed -i "s/^version = \".*\"/version = \"$NEW_VER\"/" libs/${PKG_NAME}/Cargo.toml - - . $HOME/.cargo/env # sh doesn't have the correct PATH - script: - - cargo test -p ${PKG_NAME} -- --test-threads=1 || sleep 3600 - - cargo build --release -p ${PKG_NAME} - - cargo publish -p ${PKG_NAME} --allow-dirty # allow-dirty needed because we change the version in Cargo.toml - artifacts: - paths: - - "target/release/${PKG_NAME}" - -build_gl_client: - extends: .build_rust_prep - rules: - - if: $CI_COMMIT_TAG =~ /glclient_\d{8}(_[1-9][0-9]?)?\-.*/ - variables: - PKG_NAME: gl-client - -build_gl_plugin: - extends: .build_rust_prep - rules: - - if: $CI_COMMIT_TAG =~ /glplugin_\d{8}(_[1-9][0-9]?)?\-.*/ - variables: - PKG_NAME: gl-plugin - -build_gl_signerproxy: - extends: .build_rust_prep - rules: - - if: $CI_COMMIT_TAG =~ /glsignerproxy_\d{8}(_[1-9][0-9]?)?\-.*/ - variables: - PKG_NAME: gl-signerproxy - -build_gl_cli: - extends: .build_rust_prep - rules: - - if: $CI_COMMIT_TAG =~ /glcli_\d{8}(_[1-9][0-9]?)?\-.*/ - variables: - PKG_NAME: gl-cli diff --git a/gitlab/build-pypi.yml b/gitlab/build-pypi.yml deleted file mode 100644 index 2866bf202..000000000 --- a/gitlab/build-pypi.yml +++ /dev/null @@ -1,19 +0,0 @@ -build_gl_client_py: - extends: .build_setup - when: manual - rules: - - if: $CI_COMMIT_TAG =~ /glclientpy_\d{8}(_[1-9][0-9]?)?\-.*/ - before_script: - - export NEW_VER=$(echo ${CI_COMMIT_TAG} | cut -d'-' -f2) - - sed -i "s/^version = \".*\"/version = \"$NEW_VER\"/" libs/gl-client-py/pyproject.toml - - sed -i "s/^version = \".*\"/version = \"$NEW_VER\"/" libs/gl-client-py/Cargo.toml - - . $HOME/.cargo/env # sh doesn't have the correct PATH - script: - - uv run maturin build -m libs/gl-client-py/Cargo.toml --release || sleep 3600 - - uv run maturin sdist -m libs/gl-client-py/Cargo.toml - - uv run maturin upload --username __token__ --password ${PYPI_TOKEN} target/wheels/* - - ls -lh target/wheels - artifacts: - expire_in: 2 weeks - paths: - - "target/wheels/*" diff --git a/gitlab/deploy-maven.yml b/gitlab/deploy-maven.yml deleted file mode 100644 index f97141fa1..000000000 --- a/gitlab/deploy-maven.yml +++ /dev/null @@ -1,82 +0,0 @@ -build_kotlin: - stage: build - tags: - - m4 - rules: - - if: "$CI_COMMIT_TAG" - - if: '$CI_COMMIT_BRANCH == "main"' - before_script: - # The desktop libraries bundled in the jvm jar - - rustup target add aarch64-apple-darwin x86_64-apple-darwin aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu aarch64-pc-windows-msvc x86_64-pc-windows-msvc - # cargo-xwin archives the Windows libraries with the llvm-ar of llvm-tools - - rustup component add llvm-tools - # cargo-zigbuild cross builds the Linux libraries with zig - - command -v zig >/dev/null || brew install zig - script: - - task build:kotlin - artifacts: - paths: - - libs/gl-sdk-android/lib/src/androidMain/jniLibs - - libs/gl-sdk-android/lib/src/androidMain/kotlin - - libs/gl-sdk-android/lib/src/jvmMain - - libs/gl-sdk-android/lib/src/lib - - libs/gl-sdk-android/lib/src/commonMain - - libs/gl-sdk-android/lib/src/nativeMain - - libs/gl-sdk-android/lib/src/nativeInterop - expire_in: 1 day - -# maven credentials and gpg settings -# in runner's ~/.gradle/gradle.properties -publish_to_maven: - stage: deploy - tags: - - m4 - rules: - - if: "$CI_COMMIT_TAG" - when: manual - needs: - - job: build_kotlin - artifacts: true - script: - - cd libs/gl-sdk-android - - ./gradlew publish --no-daemon - artifacts: - paths: - - libs/gl-sdk-android/lib/build/libs - - libs/gl-sdk-android/lib/build/outputs - - libs/gl-sdk-android/lib/build/publications - when: always - expire_in: 7 days - allow_failure: true - -publish_snapshot_to_maven: - stage: deploy - tags: - - m4 - needs: - - job: build_kotlin - artifacts: true - rules: - - if: '$CI_COMMIT_BRANCH' - when: on_success - script: - - cd libs/gl-sdk-android - - RAW_VERSION=$(grep '^libraryVersion=' gradle.properties | cut -d'=' -f2) - - BASE_VERSION=${RAW_VERSION%-SNAPSHOT} - - VERSION_CORE=$(echo "$BASE_VERSION" | sed -E 's/[^0-9.].*$//') - - IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION_CORE" - - MAJOR=${MAJOR:-0} - - MINOR=${MINOR:-0} - - PATCH=${PATCH:-0} - - NEXT_PATCH=$((PATCH + 1)) - - NEXT_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}" - - SNAPSHOT_VERSION="${NEXT_VERSION}-SNAPSHOT" - - SNAPSHOT_VERSION_COMMIT="${NEXT_VERSION}-${CI_COMMIT_SHORT_SHA}-SNAPSHOT" - - | - if [ "$CI_COMMIT_BRANCH" = "master" ]; then - echo "Publishing snapshot versions ${SNAPSHOT_VERSION}" - ./gradlew -PlibraryVersion=${SNAPSHOT_VERSION} publish --no-daemon - fi - echo "Publishing snapshot version ${SNAPSHOT_VERSION_COMMIT}" - ./gradlew -PlibraryVersion=${SNAPSHOT_VERSION_COMMIT} publish --no-daemon - allow_failure: true diff --git a/gitlab/functions.yml b/gitlab/functions.yml deleted file mode 100644 index c02b1f49b..000000000 --- a/gitlab/functions.yml +++ /dev/null @@ -1,45 +0,0 @@ -.build_setup: - stage: build - tags: - - cloud - rules: - - if: $CI_COMMIT_BRANCH - retry: - max: 2 - when: - - runner_system_failure - - unknown_failure - - stuck_or_timeout_failure - -build_ci_image: - extends: .build_setup - variables: - DOCKER_DRIVER: overlay2 - DOCKER_HOST: tcp://localhost:2375 - DOCKER_TLS_CERTDIR: "" - DOCKER_BUILDKIT: 1 - image: - name: docker:24-dind - services: - - docker:24-dind - rules: - - if: $CI_COMMIT_BRANCH - changes: - paths: - - docker/ci.Dockerfile - compare_to: main - script: - - docker pull ${CI_IMAGE}:latest || true - - export IMAGE_TAG=${CI_COMMIT_SHORT_SHA}-$(date +%Y%m%d) - - cd docker - - > - docker build - -f ci.Dockerfile - --network=host - --build-arg BUILDKIT_INLINE_CACHE=1 - --cache-from ${CI_IMAGE}:latest - -t ${CI_IMAGE}:${IMAGE_TAG} - -t ${CI_IMAGE}:latest - . - - docker push ${CI_IMAGE}:${IMAGE_TAG} - - docker push ${CI_IMAGE}:latest diff --git a/libs/gl-client-py/CHANGELOG.md b/libs/gl-client-py/CHANGELOG.md index 792190a09..ae52898f2 100644 --- a/libs/gl-client-py/CHANGELOG.md +++ b/libs/gl-client-py/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased +### Added + +- Wheels are published to PyPI from GitHub Actions again, for Linux (x86_64, i686), macOS (x86_64, arm64) and Windows (x64, x86). 0.3.4 had shipped only a Linux x86_64 wheel. + ## [0.4.1] - 2026-11-18 ### Changed diff --git a/libs/gl-client-py/Cargo.toml b/libs/gl-client-py/Cargo.toml index 9812a8af1..29c7f070d 100644 --- a/libs/gl-client-py/Cargo.toml +++ b/libs/gl-client-py/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "gl-client-py" version = "0.4.1" +publish = false # released to PyPI as `gl-client`, see python.yml edition = "2018" authors = ["Christian Decker", "The Greenlight Team"] description = "Python bindings for the Greenlight client library." diff --git a/libs/gl-sdk-android/lib/build.gradle.kts b/libs/gl-sdk-android/lib/build.gradle.kts index bb33d9ddb..69c8b95b7 100644 --- a/libs/gl-sdk-android/lib/build.gradle.kts +++ b/libs/gl-sdk-android/lib/build.gradle.kts @@ -138,12 +138,30 @@ extensions.configure { useGpgCmd() } -// Do not require signing when publishing to Maven Local +// The release bundle: the publications in the Maven repository layout, +// with checksums but unsigned, under build/maven-bundle. The Release +// workflow builds it with `./gradlew :lib:publishAllPublicationsToBundleRepository` +// and checks it with contrib/maven-central/check-bundle.sh. It is signed +// and uploaded to Maven Central where the signing key is. +publishing { + repositories { + maven { + name = "Bundle" + url = uri(layout.buildDirectory.dir("maven-bundle")) + } + } +} + +// Do not require signing when publishing to Maven Local or the bundle // Allows `./gradlew publishToMavenLocal` (or `publishToLocalMaven`) without GPG setup tasks.withType().configureEach { onlyIf { val taskNames = gradle.startParameter.taskNames - // Skip signing if the build is targeting the local Maven repository - taskNames.none { it.contains("publishToMavenLocal", ignoreCase = true) || it.contains("publishToLocalMaven", ignoreCase = true) } + // Skip signing if the build is targeting the local Maven repository or the bundle + taskNames.none { + it.contains("publishToMavenLocal", ignoreCase = true) || + it.contains("publishToLocalMaven", ignoreCase = true) || + it.contains("BundleRepository", ignoreCase = true) + } } } diff --git a/libs/gl-sdk-napi/Cargo.toml b/libs/gl-sdk-napi/Cargo.toml index f46e400c2..95b879e3e 100644 --- a/libs/gl-sdk-napi/Cargo.toml +++ b/libs/gl-sdk-napi/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "gl-sdk-node" version = "0.3.1" +publish = false # released to npm as `@greenlightcln/glsdk`, see typescript.yml edition = "2021" license = "MIT" diff --git a/libs/gl-sdk/CHANGELOG.md b/libs/gl-sdk/CHANGELOG.md index 1dd8200a5..a88406bab 100644 --- a/libs/gl-sdk/CHANGELOG.md +++ b/libs/gl-sdk/CHANGELOG.md @@ -6,6 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased +### Added + +- Python: the `gl-sdk` package is published to PyPI, with wheels for Linux (glibc 2.17 or later) on x86_64 and aarch64, macOS 11 or later on arm64 and x86_64, and Windows on x64. + +### Changed + +- Swift: the `glsdkFFI` binary target in `gl-sdk-swift`'s `Package.swift` downloads `glsdkFFI.xcframework.zip` from the `gl-sdk-vX.Y.Z` release of `Blockstream/greenlight`, where it is now built, instead of from the `gl-sdk-swift` release. + +### Fixed + +- Python: `glsdk.__version__` reports the installed package version. It was hard-coded to 0.4.0. + ## [0.5.1] - 2026-11-18 ### Changed diff --git a/libs/gl-sdk/glsdk/__init__.py b/libs/gl-sdk/glsdk/__init__.py index 268e838e9..33442017c 100644 --- a/libs/gl-sdk/glsdk/__init__.py +++ b/libs/gl-sdk/glsdk/__init__.py @@ -6,4 +6,9 @@ from .glsdk import * # noqa: F401, F403 -__version__ = "0.4.0" +from importlib.metadata import PackageNotFoundError, version as _version + +try: + __version__ = _version("gl-sdk") +except PackageNotFoundError: # imported from a source checkout + __version__ = "unknown" diff --git a/libs/gl-sdk/glsdk/glsdk.py b/libs/gl-sdk/glsdk/glsdk.py index 86b90b14e..ebba84905 100644 --- a/libs/gl-sdk/glsdk/glsdk.py +++ b/libs/gl-sdk/glsdk/glsdk.py @@ -534,7 +534,7 @@ def _uniffi_check_api_checksums(lib): raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_glsdk_checksum_method_nodeeventstream_next() != 12635: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_glsdk_checksum_method_scheduler_lightning_available() != 7327: + if lib.uniffi_glsdk_checksum_method_scheduler_lightning_available() != 8721: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_glsdk_checksum_method_scheduler_recover() != 55514: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") @@ -8616,8 +8616,12 @@ def lightning_available(self, node_id: "bytes"): before it creates a node. It needs no credentials, and the `node_id` is passed explicitly. - The answer is advisory and may change over time. Treat an - error as "unknown" rather than as a negative answer. + The answer is monotonic: once the node has been registered + it is reported as available, and stays available regardless + of the node's status or the provider's current capacity. + Before registration the answer is advisory and may change + over time. Treat an error as "unknown" rather than as a + negative answer. """ raise NotImplementedError @@ -8685,8 +8689,12 @@ def lightning_available(self, node_id: "bytes") -> "bool": before it creates a node. It needs no credentials, and the `node_id` is passed explicitly. - The answer is advisory and may change over time. Treat an - error as "unknown" rather than as a negative answer. + The answer is monotonic: once the node has been registered + it is reported as available, and stays available regardless + of the node's status or the provider's current capacity. + Before registration the answer is advisory and may change + over time. Treat an error as "unknown" rather than as a + negative answer. """ _UniffiConverterBytes.check_lower(node_id) diff --git a/libs/gl-sdk/hooks/libglsdk_force_include.py b/libs/gl-sdk/hooks/libglsdk_force_include.py index 15314d8c6..45648796b 100644 --- a/libs/gl-sdk/hooks/libglsdk_force_include.py +++ b/libs/gl-sdk/hooks/libglsdk_force_include.py @@ -4,20 +4,29 @@ class CustomBuildHook(BuildHookInterface): def initialize(self, version, build_data): """ - Sets force-include option for glsdk/libglsdk shared lib. + Sets force-include option for glsdk/libglsdk shared lib and the + generated glsdk/glsdk.py bindings. Does the same as [tool.hatch.build.targets.wheel.force-include], however assumes system OS and based on that sets the correct extension. + + Both files are listed in .gitignore as generated artifacts, and + hatchling leaves ignored files out of the wheel unless they are + force-included. """ + build_data['force_include']["glsdk/glsdk.py"] = "glsdk/glsdk.py" + system = platform.system() + # Must match the file name `_uniffi_load_indirect` in glsdk.py + # loads, which on Windows has no `lib` prefix. match system: case "Darwin": - lib_ext = ".dylib" + lib_name = "libglsdk.dylib" case "Windows": - lib_ext = ".dll" + lib_name = "glsdk.dll" case _: - lib_ext = ".so" + lib_name = "libglsdk.so" - shared_file = f"glsdk/libglsdk{lib_ext}" + shared_file = f"glsdk/{lib_name}" build_data['force_include'][shared_file] = shared_file \ No newline at end of file diff --git a/libs/gl-signerproxy/Cargo.toml b/libs/gl-signerproxy/Cargo.toml index f491e759a..cdf244b9c 100644 --- a/libs/gl-signerproxy/Cargo.toml +++ b/libs/gl-signerproxy/Cargo.toml @@ -23,7 +23,7 @@ env_logger = { workspace = true } tokio = { version = "1", features = ["rt", "net", "io-util"] } tonic = { version = "0.11", features = ["tls", "transport"] } prost = "0.12" -log = "*" +log = "0.4" tower = "0.4" which = "4.4.2" libc = "0.2" diff --git a/libs/uniffi-bindgen/Cargo.toml b/libs/uniffi-bindgen/Cargo.toml index 0df97517d..73a8bbb7f 100644 --- a/libs/uniffi-bindgen/Cargo.toml +++ b/libs/uniffi-bindgen/Cargo.toml @@ -2,6 +2,7 @@ name = "uniffi-bindgen" version = "0.1.0" edition = "2024" +publish = false # build tool; crates.io's uniffi-bindgen is a different crate [[bin]] # This can be whatever name makes sense for your project, but the rest of this tutorial assumes uniffi-bindgen.