| name: Release crates | |
| # Publishes nsh's crates to crates.io: the main workspace's crates that do | |
| # not inherit `publish = false` (Cargo.toml), the libraries and the | |
| # development hosts and release runners (`nsh` builds an app with Rust | |
| # crates of its own from them, at its own version), then the GPUI | |
| # workspace's (`crates/gpui`: `nsh-platform-gpui` and its development host), | |
| # which depend on them. | |
| # | |
| # - Pushing a tag `vX.Y.Z` (the workspace version in Cargo.toml) publishes | |
| # that version, alongside `release.yml`'s distribution. | |
| # - Running it by hand releases the given tag; a dry run packages and | |
| # verifies every crate without uploading. | |
| # | |
| # Crates whose version is already on crates.io are skipped, so a run that | |
| # failed half way (crates.io limits how many new crates an account publishes | |
| # in a row) can be run again. A new version also updates the `version` of | |
| # the `nsh-*` entries in both workspaces' `[workspace.dependencies]`. | |
| # | |
| # Needs the `CARGO_REGISTRY_TOKEN` secret (a crates.io token with the | |
| # publish-update scope, and publish-new for crates not published yet). | |
| on: | |
| push: | |
| tags: ["v*"] | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Tag to publish (e.g. v0.1.0)" | |
| required: true | |
| type: string | |
| dry-run: | |
| description: "Package and verify only, upload nothing" | |
| required: false | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: release-crate | |
| cancel-in-progress: false | |
| defaults: | |
| run: | |
| shell: bash | |
| env: | |
| CARGO_TERM_COLOR: always | |
| TAG: ${{ inputs.tag || github.ref_name }} | |
| DRY_RUN: ${{ inputs.dry-run && '--dry-run' || '' }} | |
| jobs: | |
| publish: | |
| # 24.04 has GTK 4.14 and Pango 1.52+, what `nsh-platform-linux` needs to | |
| # build when `cargo publish` verifies it. | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ env.TAG }} | |
| - name: Check the version | |
| run: | | |
| version=$(sed -n 's/^version = "\(.*\)"$/\1/p' Cargo.toml | head -1) | |
| if [[ "$TAG" != "v$version" ]]; then | |
| echo "::error::Tag $TAG does not match the workspace version $version" | |
| exit 1 | |
| fi | |
| # The `nsh-*` dependencies must ask for the version being published. | |
| if grep -E '^nsh-[a-z-]+ = \{' Cargo.toml crates/gpui/Cargo.toml | grep -v "version = \"$version\""; then | |
| echo "::error::Set version = \"$version\" on the nsh-* entries of [workspace.dependencies] above" | |
| exit 1 | |
| fi | |
| echo "VERSION=$version" >> "$GITHUB_ENV" | |
| # Temporary directories (verification builds) outside the checkout. | |
| - name: Set up the environment | |
| run: | | |
| mkdir -p "$RUNNER_TEMP/tmp" | |
| echo "TMPDIR=$RUNNER_TEMP/tmp" >> "$GITHUB_ENV" | |
| # QuickJS is C (bindgen needs libclang); `nsh-platform-linux` links | |
| # GTK 4, Pango and WebKitGTK 6.0; `nsh-platform-gpui` GPUI's X11 / | |
| # Wayland / xkbcommon / fontconfig libraries, GTK 3 and WebKitGTK 4.1 | |
| # (feature `webview`) and GStreamer (feature `video`), as in gpui.yml. | |
| - name: Install Linux dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| clang libclang-dev build-essential pkg-config \ | |
| libgtk-4-dev libwebkitgtk-6.0-dev \ | |
| libasound2-dev libfontconfig-dev libfreetype-dev libssl-dev \ | |
| libvulkan1 libwayland-dev libx11-xcb-dev libxcb1-dev \ | |
| libxkbcommon-dev libxkbcommon-x11-dev libzstd-dev \ | |
| libgtk-3-dev libwebkit2gtk-4.1-dev \ | |
| libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| # Prints the packages of a workspace that are published and whose | |
| # version is not on crates.io yet, as `-p <name>` arguments. | |
| - name: Write the helper | |
| run: | | |
| cat > "$RUNNER_TEMP/unpublished.sh" <<'EOF' | |
| for name in $(cargo metadata --no-deps --format-version 1 \ | |
| | jq -r '.packages[] | select(.publish != []) | .name'); do | |
| status=$(curl -s -o /dev/null -w '%{http_code}' \ | |
| -A "nsh release (https://github.com/longbridge/nsh)" \ | |
| "https://crates.io/api/v1/crates/$name/$VERSION") | |
| if [[ "$status" == 200 ]]; then | |
| echo "$name $VERSION is on crates.io, skipped" >&2 | |
| else | |
| printf -- '-p %s ' "$name" | |
| fi | |
| done | |
| EOF | |
| - name: Publish the main workspace | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| run: | | |
| packages=$(bash "$RUNNER_TEMP/unpublished.sh") | |
| if [[ -z "$packages" ]]; then echo "Nothing to publish"; exit 0; fi | |
| # cargo publishes them in dependency order. | |
| cargo publish $DRY_RUN $packages | |
| # Packaging it needs the main workspace's crates of this version on | |
| # crates.io, so a dry run only lists what its package would hold. | |
| - name: Publish the GPUI workspace | |
| working-directory: crates/gpui | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| run: | | |
| packages=$(bash "$RUNNER_TEMP/unpublished.sh") | |
| if [[ -z "$packages" ]]; then echo "Nothing to publish"; exit 0; fi | |
| if [[ -n "$DRY_RUN" ]]; then | |
| cargo package --list $packages | |
| else | |
| cargo publish $packages | |
| fi |