From 28b657d81dd96b24f6d6d7d8431c06c1909df1e4 Mon Sep 17 00:00:00 2001 From: Seto Elkahfi Date: Mon, 9 Nov 2026 16:02:37 +0100 Subject: [PATCH] Add GitHub Releases, npm and PyPI release channels Three workflows fire from the same vX.Y.Z tag as the existing ones and are independent and idempotent: - release-github.yml attaches si- binaries with .sha256 sidecars. - release-npm.yml publishes @getsigit/si and six @getsigit/si-- packages with trusted publishing and provenance. - release-pypi.yml publishes sigit-si-cli wheels and an sdist, after a smoke test that installs each wheel and runs si --version. The npm launcher package.json carries its own copy of the version, so verify-version in release-npm.yml fails when it differs from the tag. CI now typechecks the launcher and builds a wheel on pull requests. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/ci.yml | 42 +++ .github/workflows/release-github.yml | 169 +++++++++++ .github/workflows/release-npm.yml | 280 ++++++++++++++++++ .github/workflows/release-pypi.yml | 247 +++++++++++++++ .gitignore | 6 + .nvmrc | 1 + README.md | 21 +- packaging/npm/scripts/render-main-package.cjs | 57 ++++ .../npm/scripts/render-platform-package.cjs | 37 +++ packaging/npm/si/.gitignore | 2 + packaging/npm/si/README.md | 54 ++++ packaging/npm/si/package-lock.json | 77 +++++ packaging/npm/si/package.json | 44 +++ packaging/npm/si/src/index.ts | 44 +++ packaging/npm/si/tsconfig.json | 12 + packaging/nuget/si/README.md | 3 + packaging/pypi/si/README.md | 52 ++++ packaging/pypi/si/pyproject.toml | 36 +++ 18 files changed, 1179 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release-github.yml create mode 100644 .github/workflows/release-npm.yml create mode 100644 .github/workflows/release-pypi.yml create mode 100644 .nvmrc create mode 100644 packaging/npm/scripts/render-main-package.cjs create mode 100644 packaging/npm/scripts/render-platform-package.cjs create mode 100644 packaging/npm/si/.gitignore create mode 100644 packaging/npm/si/README.md create mode 100644 packaging/npm/si/package-lock.json create mode 100644 packaging/npm/si/package.json create mode 100644 packaging/npm/si/src/index.ts create mode 100644 packaging/npm/si/tsconfig.json create mode 100644 packaging/pypi/si/README.md create mode 100644 packaging/pypi/si/pyproject.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8389897..888c2fd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,3 +36,45 @@ jobs: - name: Test run: cargo test --workspace + + # Packaging breakage should show up on the pull request, not on the tag. + npm-launcher: + name: npm launcher typecheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + + - name: Build the launcher + working-directory: packaging/npm/si + run: | + npm ci + npm run build + + pypi-wheel: + name: PyPI wheel build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Read Rust toolchain + shell: bash + run: | + rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)" + echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV" + + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ env.RUST_TOOLCHAIN }} + + - uses: Swatinem/rust-cache@v2 + + - name: Build wheel + uses: PyO3/maturin-action@v1 + with: + manylinux: "off" + working-directory: packaging/pypi/si + args: --release --locked --out dist diff --git a/.github/workflows/release-github.yml b/.github/workflows/release-github.yml new file mode 100644 index 0000000..dd75f58 --- /dev/null +++ b/.github/workflows/release-github.yml @@ -0,0 +1,169 @@ +name: Release GitHub + +# Attaches the prebuilt `si` binaries, each with a .sha256 sidecar, to the GitHub release for the +# tag, so Homebrew, Scoop or winget can be added later without rebuilding. Re-running overwrites +# the assets on the same release, so a re-pushed or re-dispatched tag is harmless. + +on: + push: + tags: + - "v*.*.*" + workflow_dispatch: + inputs: + tag: + description: "Release tag (e.g. v1.3.0)" + required: true + +concurrency: + group: ${{ github.workflow }}-${{ github.event.inputs.tag || github.ref_name }} + cancel-in-progress: false + +permissions: + contents: read + +env: + CARGO_TERM_COLOR: always + +jobs: + verify-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + - name: Tag matches the workspace version + shell: bash + env: + TAG: ${{ github.event.inputs.tag || github.ref_name }} + run: | + workspace=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1) + if [ "$TAG" != "v$workspace" ]; then + echo "::error::tag $TAG does not match the workspace version $workspace" + exit 1 + fi + + build: + name: Build binary (${{ matrix.build.NAME }}) + needs: verify-version + runs-on: ${{ matrix.build.OS }} + strategy: + fail-fast: false + matrix: + build: + - { + NAME: linux-x64, + OS: ubuntu-22.04, + TARGET: x86_64-unknown-linux-gnu, + } + - { + NAME: linux-arm64, + OS: ubuntu-22.04-arm, + TARGET: aarch64-unknown-linux-gnu, + } + - { + NAME: windows-x64, + OS: windows-2022, + TARGET: x86_64-pc-windows-msvc, + } + - { + NAME: windows-arm64, + OS: windows-2022, + TARGET: aarch64-pc-windows-msvc, + } + - { NAME: darwin-x64, OS: macos-26, TARGET: x86_64-apple-darwin } + - { NAME: darwin-arm64, OS: macos-26, TARGET: aarch64-apple-darwin } + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + + - name: Read Rust toolchain + shell: bash + run: | + rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)" + if [ -z "$rust_toolchain" ]; then + echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2 + exit 1 + fi + echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV" + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 + with: + toolchain: ${{ env.RUST_TOOLCHAIN }} + + - name: Install Rust target + shell: bash + run: | + rustup target add ${{ matrix.build.TARGET }} --toolchain ${{ env.RUST_TOOLCHAIN }} + rustup target list --installed + + - name: Setup Rust cache + uses: Swatinem/rust-cache@v2 + with: + key: github-${{ matrix.build.TARGET }} + + # Linux builds on the oldest runner image for its glibc floor (2.35). The repo uses rustls, + # so there is no OpenSSL to link or vendor. + - name: Build binary + shell: bash + run: cargo build --locked --release -p sigit-si-cli --bin si --target ${{ matrix.build.TARGET }} + + # The exe must not import the VC++ runtime DLLs (see .cargo/config.toml), or it fails to + # load on a machine without the redistributable. + - name: Check static CRT + if: contains(matrix.build.TARGET, 'windows') + shell: pwsh + run: ./packaging/windows/check-static-crt.ps1 -Path target/${{ matrix.build.TARGET }}/release/si.exe + + # Windows runners use bash from Git for Windows, which has sha256sum; macOS only has shasum. + - name: Package binary and checksum + shell: bash + env: + BUILD_NAME: ${{ matrix.build.NAME }} + TARGET: ${{ matrix.build.TARGET }} + run: | + suffix="" + if [[ "${BUILD_NAME}" == windows-* ]]; then + suffix=".exe" + fi + + mkdir -p release + asset="si-${BUILD_NAME}${suffix}" + cp "target/${TARGET}/release/si${suffix}" "release/${asset}" + + cd release + if command -v sha256sum >/dev/null 2>&1; then + sha256sum "${asset}" | awk '{print $1}' > "${asset}.sha256" + else + shasum -a 256 "${asset}" | awk '{print $1}' > "${asset}.sha256" + fi + echo "${asset}: $(cat "${asset}.sha256")" + + - name: Upload binary artifact + uses: actions/upload-artifact@v4 + with: + name: github-binary-${{ matrix.build.NAME }} + path: release/* + + release: + name: Create GitHub release + needs: build + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Download binary artifacts + uses: actions/download-artifact@v4 + with: + pattern: github-binary-* + path: release + merge-multiple: true + + - name: Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ github.event.inputs.tag || github.ref_name }} + files: release/* + generate_release_notes: true diff --git a/.github/workflows/release-npm.yml b/.github/workflows/release-npm.yml new file mode 100644 index 0000000..54a55f1 --- /dev/null +++ b/.github/workflows/release-npm.yml @@ -0,0 +1,280 @@ +name: Release npm + +# Publishes @getsigit/si, a launcher that resolves the native `si` binary from one of six +# platform packages (@getsigit/si--), on the same tag that release-crates.yml +# publishes from. +# +# Auth is npm Trusted Publishing (OIDC), so no token is stored. Each of the seven packages needs +# a trusted publisher for this repository and workflow (release-npm.yml). `npm trust` only works +# on a package that already exists, so the first version of each is published by hand. + +on: + push: + tags: + - "v*.*.*" + workflow_dispatch: + inputs: + tag: + description: "Release tag (e.g. v1.3.0)" + required: true + +concurrency: + group: ${{ github.workflow }}-${{ github.event.inputs.tag || github.ref_name }} + cancel-in-progress: false + +permissions: + contents: read + +env: + CARGO_TERM_COLOR: always + +jobs: + # The binary reports CARGO_PKG_VERSION, and the launcher package.json carries its own copy of + # the version, so both must agree with the tag. + verify-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + - name: Tag matches the workspace and npm package versions + shell: bash + env: + TAG: ${{ github.event.inputs.tag || github.ref_name }} + run: | + workspace=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1) + if [ "$TAG" != "v$workspace" ]; then + echo "::error::tag $TAG does not match the workspace version $workspace" + exit 1 + fi + + npm_version=$(node -p "require('./packaging/npm/si/package.json').version") + if [ "$TAG" != "v$npm_version" ]; then + echo "::error::tag $TAG does not match packaging/npm/si/package.json version $npm_version. Bump it (and its lockfile) with the workspace version." + exit 1 + fi + + publish-npm-binaries: + name: Publish @getsigit/si-${{ matrix.build.NAME }} + needs: verify-version + runs-on: ${{ matrix.build.OS }} + permissions: + contents: read + id-token: write + strategy: + fail-fast: false + matrix: + build: + - { + NAME: linux-x64, + OS: ubuntu-22.04, + TARGET: x86_64-unknown-linux-gnu, + NODE_OS: linux, + NODE_ARCH: x64, + } + - { + NAME: linux-arm64, + OS: ubuntu-22.04-arm, + TARGET: aarch64-unknown-linux-gnu, + NODE_OS: linux, + NODE_ARCH: arm64, + } + - { + NAME: windows-x64, + OS: windows-2022, + TARGET: x86_64-pc-windows-msvc, + NODE_OS: win32, + NODE_ARCH: x64, + } + - { + NAME: windows-arm64, + OS: windows-2022, + TARGET: aarch64-pc-windows-msvc, + NODE_OS: win32, + NODE_ARCH: arm64, + } + - { + NAME: darwin-x64, + OS: macos-26, + TARGET: x86_64-apple-darwin, + NODE_OS: darwin, + NODE_ARCH: x64, + } + - { + NAME: darwin-arm64, + OS: macos-26, + TARGET: aarch64-apple-darwin, + NODE_OS: darwin, + NODE_ARCH: arm64, + } + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + + - name: Set the release version + shell: bash + run: | + release_version="${{ github.event.inputs.tag || github.ref_name }}" + echo "RELEASE_VERSION=${release_version#v}" >> "$GITHUB_ENV" + + - name: Read Rust toolchain + shell: bash + run: | + rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)" + if [ -z "$rust_toolchain" ]; then + echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2 + exit 1 + fi + echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV" + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 + with: + toolchain: ${{ env.RUST_TOOLCHAIN }} + + - name: Install Rust target + shell: bash + run: | + rustup target add ${{ matrix.build.TARGET }} --toolchain ${{ env.RUST_TOOLCHAIN }} + rustup target list --installed + + - name: Setup Rust cache + uses: Swatinem/rust-cache@v2 + with: + key: npm-${{ matrix.build.TARGET }} + + # Linux builds on the oldest runner image for its glibc floor (2.35). The repo uses rustls, + # so there is no OpenSSL to link or vendor. + - name: Build binary + shell: bash + run: cargo build --locked --release -p sigit-si-cli --bin si --target ${{ matrix.build.TARGET }} + + # The exe must not import the VC++ runtime DLLs (see .cargo/config.toml), or it fails to + # load on a machine without the redistributable. + - name: Check static CRT + if: contains(matrix.build.TARGET, 'windows') + shell: pwsh + run: ./packaging/windows/check-static-crt.ps1 -Path target/${{ matrix.build.TARGET }}/release/si.exe + + - name: Install Node + uses: actions/setup-node@v6 + with: + node-version-file: .nvmrc + registry-url: "https://registry.npmjs.org" + + - name: Render the platform package + shell: bash + env: + BUILD_NAME: ${{ matrix.build.NAME }} + TARGET: ${{ matrix.build.TARGET }} + NODE_OS: ${{ matrix.build.NODE_OS }} + NODE_ARCH: ${{ matrix.build.NODE_ARCH }} + run: | + package_directory="si-${BUILD_NAME}" + executable_name="si" + if [[ "${BUILD_NAME}" == windows-* ]]; then + executable_name="si.exe" + fi + + mkdir -p "packaging/npm/${package_directory}/bin" + node packaging/npm/scripts/render-platform-package.cjs \ + "${package_directory}" "${RELEASE_VERSION}" "${NODE_OS}" "${NODE_ARCH}" + cp "target/${TARGET}/release/${executable_name}" "packaging/npm/${package_directory}/bin/" + + - name: Check whether the package version already exists on npm + id: npm-check + shell: bash + env: + BUILD_NAME: ${{ matrix.build.NAME }} + run: | + # A 404 means this version is not on npm yet. Anything other than 200 or 404 is an + # outage or a block, which must not read as "not published yet". + status=$(curl -sS -o /dev/null -w '%{http_code}' \ + --retry 3 --retry-delay 2 --retry-all-errors \ + "https://registry.npmjs.org/@getsigit%2Fsi-${BUILD_NAME}/${RELEASE_VERSION}") + + case "$status" in + 200) + echo "@getsigit/si-${BUILD_NAME}@${RELEASE_VERSION} already exists on npm, skipping publish" + echo "exists=true" >> "$GITHUB_OUTPUT" + ;; + 404) + echo "exists=false" >> "$GITHUB_OUTPUT" + ;; + *) + echo "Unexpected ${status} from npm while checking @getsigit/si-${BUILD_NAME}@${RELEASE_VERSION}" >&2 + exit 1 + ;; + esac + + - name: Publish to npm + if: steps.npm-check.outputs.exists != 'true' + shell: bash + env: + BUILD_NAME: ${{ matrix.build.NAME }} + run: | + cd "packaging/npm/si-${BUILD_NAME}" + npm publish --access public --provenance + + publish-npm-base: + name: Publish @getsigit/si + needs: publish-npm-binaries + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + + - name: Set the release version + shell: bash + run: | + release_version="${{ github.event.inputs.tag || github.ref_name }}" + echo "RELEASE_VERSION=${release_version#v}" >> "$GITHUB_ENV" + + - name: Install Node + uses: actions/setup-node@v6 + with: + node-version-file: .nvmrc + registry-url: "https://registry.npmjs.org" + + - name: Render and build the launcher + shell: bash + working-directory: packaging/npm/si + run: | + node ../scripts/render-main-package.cjs ./package.json "${RELEASE_VERSION}" + npm ci + npm run build + + - name: Check whether the package version already exists on npm + id: npm-check + shell: bash + run: | + status=$(curl -sS -o /dev/null -w '%{http_code}' \ + --retry 3 --retry-delay 2 --retry-all-errors \ + "https://registry.npmjs.org/@getsigit%2Fsi/${RELEASE_VERSION}") + + case "$status" in + 200) + echo "@getsigit/si@${RELEASE_VERSION} already exists on npm, skipping publish" + echo "exists=true" >> "$GITHUB_OUTPUT" + ;; + 404) + echo "exists=false" >> "$GITHUB_OUTPUT" + ;; + *) + echo "Unexpected ${status} from npm while checking @getsigit/si@${RELEASE_VERSION}" >&2 + exit 1 + ;; + esac + + - name: Publish to npm + if: steps.npm-check.outputs.exists != 'true' + shell: bash + working-directory: packaging/npm/si + run: npm publish --access public --provenance diff --git a/.github/workflows/release-pypi.yml b/.github/workflows/release-pypi.yml new file mode 100644 index 0000000..8e33d8f --- /dev/null +++ b/.github/workflows/release-pypi.yml @@ -0,0 +1,247 @@ +name: Release PyPI + +# Publishes sigit-si-cli, the native `si` binary packaged as maturin wheels, on the same tag that +# release-crates.yml publishes from. +# +# Windows arm64 wheels are intentionally not built here. GitHub's hosted Windows runners provide +# x64 Python, and maturin refuses to build an arm64 wheel when the interpreter reports win-amd64. +# +# Auth is PyPI Trusted Publishing (OIDC), so no API token is stored. pypi.org needs a publisher +# for this repository and workflow (release-pypi.yml), with no environment. For the first release +# that is a pending publisher, which creates the project on first upload. + +on: + push: + tags: + - "v*.*.*" + workflow_dispatch: + inputs: + tag: + description: "Release tag (e.g. v1.3.0)" + required: true + +concurrency: + group: ${{ github.workflow }}-${{ github.event.inputs.tag || github.ref_name }} + cancel-in-progress: false + +permissions: + contents: read + +env: + CARGO_TERM_COLOR: always + PYPI_PACKAGE: sigit-si-cli + +jobs: + verify-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + - name: Tag matches the workspace version + shell: bash + env: + TAG: ${{ github.event.inputs.tag || github.ref_name }} + run: | + workspace=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1) + if [ "$TAG" != "v$workspace" ]; then + echo "::error::tag $TAG does not match the workspace version $workspace" + exit 1 + fi + + build-wheels: + name: Build wheel (${{ matrix.build.NAME }}) + needs: verify-version + runs-on: ${{ matrix.build.OS }} + strategy: + fail-fast: false + matrix: + build: + - { + NAME: linux-x64, + OS: ubuntu-22.04, + TARGET: x86_64-unknown-linux-gnu, + MANYLINUX: "2_28", + } + - { + NAME: linux-arm64, + OS: ubuntu-22.04-arm, + TARGET: aarch64-unknown-linux-gnu, + MANYLINUX: "2_28", + } + - { + NAME: windows-x64, + OS: windows-2022, + TARGET: x86_64-pc-windows-msvc, + } + - { NAME: darwin-x64, OS: macos-26, TARGET: x86_64-apple-darwin } + - { NAME: darwin-arm64, OS: macos-26, TARGET: aarch64-apple-darwin } + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + + - name: Read Rust toolchain + shell: bash + run: | + rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)" + if [ -z "$rust_toolchain" ]; then + echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2 + exit 1 + fi + echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV" + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 + with: + toolchain: ${{ env.RUST_TOOLCHAIN }} + targets: ${{ matrix.build.TARGET }} + + # The repo uses rustls and a vendored libgit2, so the manylinux container needs no extra + # system packages. + - name: Build wheel + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.build.TARGET }} + manylinux: ${{ matrix.build.MANYLINUX || 'off' }} + working-directory: packaging/pypi/si + args: --release --locked --compatibility pypi --out dist + + - name: Upload wheel artifact + uses: actions/upload-artifact@v4 + with: + name: pypi-wheels-${{ matrix.build.NAME }} + path: packaging/pypi/si/dist/* + + build-sdist: + name: Build source distribution + needs: verify-version + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + + - name: Build sdist + uses: PyO3/maturin-action@v1 + with: + command: sdist + working-directory: packaging/pypi/si + args: --out dist + + - name: Upload sdist artifact + uses: actions/upload-artifact@v4 + with: + name: pypi-sdist + path: packaging/pypi/si/dist/* + + # Installing from the built wheels proves the binary loads, not just that it was packed: a + # missing runtime DLL or a glibc mismatch shows up here instead of on PyPI. + smoke-test: + name: Smoke test (${{ matrix.os }}) + needs: + - build-wheels + - build-sdist + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + # The oldest image, so the Linux wheel runs against the glibc floor. + - ubuntu-22.04 + - windows-2022 + - macos-26 + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.tag || github.ref }} + + - name: Set the release version + shell: bash + run: | + release_version="${{ github.event.inputs.tag || github.ref_name }}" + echo "RELEASE_VERSION=${release_version#v}" >> "$GITHUB_ENV" + + - name: Download distribution artifacts + uses: actions/download-artifact@v4 + with: + pattern: pypi-* + path: dist + merge-multiple: true + + # --only-binary keeps pip from falling back to the sdist, which would compile instead of + # testing the wheel. + - name: Install from the built wheels + shell: bash + run: | + python -m venv .venv + if [ -d .venv/Scripts ]; then bin_dir=.venv/Scripts; else bin_dir=.venv/bin; fi + "${bin_dir}/python" -m pip install --no-index --only-binary :all: --find-links dist "${PYPI_PACKAGE}==${RELEASE_VERSION}" + echo "SI_BIN_DIR=${bin_dir}" >> "$GITHUB_ENV" + + - name: Run the installed binary + shell: bash + run: | + output="$("${SI_BIN_DIR}/si" --version)" + echo "${output}" + case "${output}" in + *"${RELEASE_VERSION}"*) ;; + *) + echo "::error::si --version did not report ${RELEASE_VERSION}" >&2 + exit 1 + ;; + esac + + publish-pypi: + name: Publish to PyPI + needs: smoke-test + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - name: Set the release version + shell: bash + run: | + release_version="${{ github.event.inputs.tag || github.ref_name }}" + echo "RELEASE_VERSION=${release_version#v}" >> "$GITHUB_ENV" + + - name: Download distribution artifacts + uses: actions/download-artifact@v4 + with: + pattern: pypi-* + path: dist + merge-multiple: true + + - name: Check whether release already exists on PyPI + id: pypi-check + shell: bash + run: | + # A 404 means the project or the version is not on PyPI, so publish. Anything other than + # 200 or 404 is an outage or a block, which must not read as "not published yet". + status=$(curl -sS -o /dev/null -w '%{http_code}' \ + --retry 3 --retry-delay 2 --retry-all-errors \ + "https://pypi.org/pypi/${PYPI_PACKAGE}/${RELEASE_VERSION}/json") + + case "$status" in + 200) + echo "${PYPI_PACKAGE} ${RELEASE_VERSION} already exists on PyPI, skipping publish" + echo "exists=true" >> "$GITHUB_OUTPUT" + ;; + 404) + echo "exists=false" >> "$GITHUB_OUTPUT" + ;; + *) + echo "Unexpected ${status} from PyPI while checking whether ${PYPI_PACKAGE} ${RELEASE_VERSION} is published" >&2 + exit 1 + ;; + esac + + - name: Publish distribution + if: steps.pypi-check.outputs.exists != 'true' + uses: pypa/gh-action-pypi-publish@release/v1 + with: + skip-existing: true diff --git a/.gitignore b/.gitignore index 0facf51..6777f6f 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,9 @@ packaging/nuget/**/obj/ packaging/nuget/**/native/ packaging/nuget/dist/ packaging/nuget/NuGet.Config + +# npm and PyPI packaging +/packaging/npm/si-*/ +/packaging/npm/si/lib/ +/packaging/npm/si/node_modules/ +/packaging/pypi/*/dist/ diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..a45fd52 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +24 diff --git a/README.md b/README.md index d042e5a..a67327a 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,18 @@ drive Cloud Sessions, all from the terminal. cargo install --path crates/cli ``` -This installs a binary named `si`. On a machine with the .NET SDK there is also -a prebuilt tool: +This installs a binary named `si`. Prebuilt binaries are also available: ```sh -dotnet tool install --global SiGit.Cli +npm install -g @getsigit/si # npm +pipx install sigit-si-cli # PyPI (or: uvx --from sigit-si-cli si) +dotnet tool install --global SiGit.Cli # .NET ``` +Or download a binary for your platform from +[GitHub Releases](https://github.com/getsigit/si/releases); each asset has a +`.sha256` file next to it. + ## Usage ```sh @@ -142,11 +147,17 @@ marker can never be listed, and fixing it costs a new version. The internal setup and release runbook live with the server (private `sigit-si` repo). To cut a release, bump `[workspace.package].version` and the `sigit-si-api` -dependency in the root `Cargo.toml`, merge `development` into `main`, and push a +dependency in the root `Cargo.toml`, and the `version` in +`packaging/npm/si/package.json` and its lockfile (`release-npm.yml` fails when +it differs from the tag; PyPI and NuGet read the version from the crate), merge `development` into `main`, and push a `vX.Y.Z` tag. `release-crates.yml` checks the crate versions against the tag, publishes whichever of `sigit-si-api` and `sigit-si-cli` isn't on crates.io yet (through Trusted Publishing, so no token is stored), then dispatches -`release-mcp-registry.yml`. +`release-mcp-registry.yml`. The same tag also starts `release-github.yml` +(release assets with checksums), `release-npm.yml`, `release-pypi.yml` and +`release-nuget.yml`. They run independently, publish through Trusted Publishing +where the registry supports it, and skip a version that is already published, +so any of them can be re-run on its own. ## Development diff --git a/packaging/npm/scripts/render-main-package.cjs b/packaging/npm/scripts/render-main-package.cjs new file mode 100644 index 0000000..5aa2c18 --- /dev/null +++ b/packaging/npm/scripts/render-main-package.cjs @@ -0,0 +1,57 @@ +#!/usr/bin/env node + +const fs = require("fs"); +const path = require("path"); + +const [outputPath, version] = process.argv.slice(2); + +if (!outputPath || !version) { + throw new Error("Usage: render-main-package.cjs "); +} + +// The platform binary packages the launcher resolves at runtime. Kept in lockstep with the +// release-npm.yml build matrix. +const platformSuffixes = [ + "darwin-arm64", + "darwin-x64", + "linux-arm64", + "linux-x64", + "windows-arm64", + "windows-x64", +]; + +const optionalDependencies = {}; +for (const suffix of platformSuffixes) { + optionalDependencies[`@getsigit/si-${suffix}`] = version; +} + +const packageJson = { + name: "@getsigit/si", + version, + // Ownership proof for the MCP Registry: must match `name` in the repo's server.json. + mcpName: "si.sigit/cli", + keywords: ["sigit", "si", "cli", "git", "code-review", "mcp"], + bin: { + si: "lib/index.js", + }, + files: ["lib", "README.md"], + description: "si, the sigit.si command line interface.", + license: "Apache-2.0", + homepage: "https://sigit.si", + repository: { + type: "git", + url: "git+https://github.com/getsigit/si.git", + }, + scripts: { + typecheck: "tsc --noEmit", + build: "tsc", + dev: "npm run build && node lib/index.js", + }, + devDependencies: { + "@types/node": "^18.15.11", + typescript: "^5.0.0", + }, + optionalDependencies, +}; + +fs.writeFileSync(path.resolve(outputPath), `${JSON.stringify(packageJson, null, 2)}\n`); diff --git a/packaging/npm/scripts/render-platform-package.cjs b/packaging/npm/scripts/render-platform-package.cjs new file mode 100644 index 0000000..1eabfd7 --- /dev/null +++ b/packaging/npm/scripts/render-platform-package.cjs @@ -0,0 +1,37 @@ +#!/usr/bin/env node + +const fs = require("fs"); +const path = require("path"); + +const [packageName, version, operatingSystem, architecture] = process.argv.slice(2); + +if (!packageName || !version || !operatingSystem || !architecture) { + throw new Error("Usage: render-platform-package.cjs "); +} + +const packageDirectory = path.resolve(__dirname, "..", packageName); + +fs.mkdirSync(packageDirectory, { recursive: true }); + +const packageJson = { + name: `@getsigit/${packageName}`, + version, + description: "Platform binary for the si CLI.", + license: "Apache-2.0", + repository: { + type: "git", + url: "git+https://github.com/getsigit/si.git", + }, + keywords: [packageName, "si", "sigit", "cli", "binary"], + os: [operatingSystem], + cpu: [architecture], + files: ["bin"], +}; + +const readme = `# ${packageName} + +Not meant to be used directly. Please see [@getsigit/si](https://www.npmjs.com/package/@getsigit/si). +`; + +fs.writeFileSync(path.join(packageDirectory, "package.json"), `${JSON.stringify(packageJson, null, 2)}\n`); +fs.writeFileSync(path.join(packageDirectory, "README.md"), readme); diff --git a/packaging/npm/si/.gitignore b/packaging/npm/si/.gitignore new file mode 100644 index 0000000..3b4e8dc --- /dev/null +++ b/packaging/npm/si/.gitignore @@ -0,0 +1,2 @@ +lib/ +node_modules/ diff --git a/packaging/npm/si/README.md b/packaging/npm/si/README.md new file mode 100644 index 0000000..9438814 --- /dev/null +++ b/packaging/npm/si/README.md @@ -0,0 +1,54 @@ + + +# si for npm + +`si` is the command line interface for [sigit.si](https://sigit.si): sign in, manage repositories, +review pull requests, triage issues, search code, and drive Cloud Sessions from the terminal. + +This package installs the native `si` binary for your platform. It has no JavaScript API. + +## Install + +```sh +npm install -g @getsigit/si +``` + +Or run it without installing: + +```sh +npx @getsigit/si --help +``` + +## Run + +```sh +si auth login +si repo list +``` + +## Platform support + +The binary comes from an optional dependency that npm selects for your machine: + +- macOS `arm64`, `x64` +- Linux `arm64`, `x64` (glibc) +- Windows `arm64`, `x64` + +Installing with `--omit=optional` leaves the binary out, and `si` then fails with a message saying so. + +## Other installation methods + +- Cargo: `cargo install sigit-si-cli` +- PyPI: `pipx install sigit-si-cli` +- .NET: `dotnet tool install --global SiGit.Cli` +- Prebuilt binaries: [GitHub Releases](https://github.com/getsigit/si/releases) + +## Source + +- Repository: +- Website: +- Issues: + +## License + +[Apache 2.0](https://github.com/getsigit/si/blob/main/LICENSE) diff --git a/packaging/npm/si/package-lock.json b/packaging/npm/si/package-lock.json new file mode 100644 index 0000000..b564508 --- /dev/null +++ b/packaging/npm/si/package-lock.json @@ -0,0 +1,77 @@ +{ + "name": "@getsigit/si", + "version": "1.3.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@getsigit/si", + "version": "1.3.1", + "license": "Apache-2.0", + "bin": { + "si": "lib/index.js" + }, + "devDependencies": { + "@types/node": "^18.15.11", + "typescript": "^5.0.0" + }, + "optionalDependencies": { + "@getsigit/si-darwin-arm64": "1.3.1", + "@getsigit/si-darwin-x64": "1.3.1", + "@getsigit/si-linux-arm64": "1.3.1", + "@getsigit/si-linux-x64": "1.3.1", + "@getsigit/si-windows-arm64": "1.3.1", + "@getsigit/si-windows-x64": "1.3.1" + } + }, + "node_modules/@getsigit/si-darwin-arm64": { + "optional": true + }, + "node_modules/@getsigit/si-darwin-x64": { + "optional": true + }, + "node_modules/@getsigit/si-linux-arm64": { + "optional": true + }, + "node_modules/@getsigit/si-linux-x64": { + "optional": true + }, + "node_modules/@getsigit/si-windows-arm64": { + "optional": true + }, + "node_modules/@getsigit/si-windows-x64": { + "optional": true + }, + "node_modules/@types/node": { + "version": "18.19.130", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.130.tgz", + "integrity": "sha512-GRaXQx6jGfL8sKfaIDD6OupbIHBr9jv7Jnaml9tB7l4v068PAOXqfcujMMo5PhbIs6ggR1XODELqahT2R8v0fg==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true, + "license": "MIT" + } + } +} diff --git a/packaging/npm/si/package.json b/packaging/npm/si/package.json new file mode 100644 index 0000000..4975441 --- /dev/null +++ b/packaging/npm/si/package.json @@ -0,0 +1,44 @@ +{ + "name": "@getsigit/si", + "version": "1.3.1", + "mcpName": "si.sigit/cli", + "keywords": [ + "sigit", + "si", + "cli", + "git", + "code-review", + "mcp" + ], + "bin": { + "si": "lib/index.js" + }, + "files": [ + "lib", + "README.md" + ], + "description": "si, the sigit.si command line interface.", + "license": "Apache-2.0", + "homepage": "https://sigit.si", + "repository": { + "type": "git", + "url": "git+https://github.com/getsigit/si.git" + }, + "scripts": { + "typecheck": "tsc --noEmit", + "build": "tsc", + "dev": "npm run build && node lib/index.js" + }, + "devDependencies": { + "@types/node": "^18.15.11", + "typescript": "^5.0.0" + }, + "optionalDependencies": { + "@getsigit/si-darwin-arm64": "1.3.1", + "@getsigit/si-darwin-x64": "1.3.1", + "@getsigit/si-linux-arm64": "1.3.1", + "@getsigit/si-linux-x64": "1.3.1", + "@getsigit/si-windows-arm64": "1.3.1", + "@getsigit/si-windows-x64": "1.3.1" + } +} diff --git a/packaging/npm/si/src/index.ts b/packaging/npm/si/src/index.ts new file mode 100644 index 0000000..706f905 --- /dev/null +++ b/packaging/npm/si/src/index.ts @@ -0,0 +1,44 @@ +#!/usr/bin/env node + +import { spawnSync } from "child_process"; + +/** + * Resolves the native binary from the platform package npm installed next to this one. + * The package is named `@getsigit/si-${os}-${arch}`, with `win32` mapped to `windows`. + * @see https://nodejs.org/api/os.html#osarch + * @see https://nodejs.org/api/os.html#osplatform + */ +function getExePath(): string { + const arch = process.arch; + let os = process.platform as string; + let extension = ""; + if (["win32", "cygwin"].includes(process.platform)) { + os = "windows"; + extension = ".exe"; + } + + try { + return require.resolve(`@getsigit/si-${os}-${arch}/bin/si${extension}`); + } catch (e) { + throw new Error( + `Couldn't find the si binary for ${os}-${arch} inside node_modules. ` + + "Reinstall without --omit=optional, or install with `cargo install sigit-si-cli`.", + ); + } +} + +function run(): void { + const args = process.argv.slice(2); + const result = spawnSync(getExePath(), args, { stdio: "inherit" }); + + if (result.error) { + console.error(`Failed to run si: ${result.error.message}`); + process.exit(1); + } + + // `status` is null when the child was killed by a signal; report that as a failure rather + // than as success. + process.exit(result.status ?? 1); +} + +run(); diff --git a/packaging/npm/si/tsconfig.json b/packaging/npm/si/tsconfig.json new file mode 100644 index 0000000..8e6c790 --- /dev/null +++ b/packaging/npm/si/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "es2016", + "module": "commonjs", + "esModuleInterop": true, + "baseUrl": "./", + "outDir": "lib", + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true + } +} diff --git a/packaging/nuget/si/README.md b/packaging/nuget/si/README.md index 7942e32..eec9d27 100644 --- a/packaging/nuget/si/README.md +++ b/packaging/nuget/si/README.md @@ -36,6 +36,9 @@ download. `cargo install sigit-si-cli` builds only for your machine. ## Other installation methods - Cargo: `cargo install sigit-si-cli` +- npm: `npm install -g @getsigit/si` +- PyPI: `pipx install sigit-si-cli` +- Prebuilt binaries: [GitHub Releases](https://github.com/getsigit/si/releases) ## Source diff --git a/packaging/pypi/si/README.md b/packaging/pypi/si/README.md new file mode 100644 index 0000000..356e7f6 --- /dev/null +++ b/packaging/pypi/si/README.md @@ -0,0 +1,52 @@ +# si for Python + +`si` is the command line interface for [sigit.si](https://sigit.si): sign in, manage repositories, +review pull requests, triage issues, search code, and drive Cloud Sessions from the terminal. + +This package is the native `si` binary packaged as a Python wheel. There is no Python API. + +## Install + +```sh +pipx install sigit-si-cli +``` + +Or run it without installing: + +```sh +uvx --from sigit-si-cli si --help +``` + +## Run + +```sh +si auth login +si repo list +``` + +## Platform support + +Prebuilt wheels cover: + +- macOS `arm64`, `x86_64` +- Linux `arm64`, `x86_64` (glibc) +- Windows `x86_64` + +On other platforms pip builds from the source distribution, which needs a Rust toolchain. + +## Other installation methods + +- Cargo: `cargo install sigit-si-cli` +- npm: `npm install -g @getsigit/si` +- .NET: `dotnet tool install --global SiGit.Cli` +- Prebuilt binaries: [GitHub Releases](https://github.com/getsigit/si/releases) + +## Source + +- Repository: +- Website: +- Issues: + +## License + +[Apache 2.0](https://github.com/getsigit/si/blob/main/LICENSE) diff --git a/packaging/pypi/si/pyproject.toml b/packaging/pypi/si/pyproject.toml new file mode 100644 index 0000000..9b8d607 --- /dev/null +++ b/packaging/pypi/si/pyproject.toml @@ -0,0 +1,36 @@ +[build-system] +requires = ["maturin>=1.7,<2.0"] +build-backend = "maturin" + +[project] +name = "sigit-si-cli" +description = "si, the sigit.si command line interface." +readme = "README.md" +requires-python = ">=3.8" +dynamic = ["version"] +license = { text = "Apache-2.0" } +authors = [{ name = "Seto Elkahfi", email = "seto@sigit.si" }] +keywords = ["cli", "git", "sigit", "code-review"] +classifiers = [ + "Development Status :: 4 - Beta", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Operating System :: MacOS", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3", + "Programming Language :: Rust", + "Topic :: Software Development :: Version Control :: Git", + "Topic :: Utilities", +] + +[project.urls] +Homepage = "https://sigit.si" +Repository = "https://github.com/getsigit/si" +Issues = "https://github.com/getsigit/si/issues" + +[tool.maturin] +manifest-path = "../../../crates/cli/Cargo.toml" +bindings = "bin" +strip = true