smux-cli 0.1.10

Small Rust CLI for tmux session selection and creation
Documentation
name: Release

on:
  push:
    tags:
      - "v*"
  workflow_dispatch:
    inputs:
      version:
        description: "Release tag to build and publish, for example v0.1.6"
        required: true
        type: string

jobs:
  prepare:
    name: Resolve release ref
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.resolve.outputs.version }}
      ref: ${{ steps.resolve.outputs.ref }}

    steps:
      - name: Resolve release tag
        id: resolve
        shell: bash
        run: |
          if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
            VERSION="${{ inputs.version }}"
          else
            VERSION="${GITHUB_REF_NAME}"
          fi

          if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
            echo "expected a v-prefixed semantic version tag, got: $VERSION" >&2
            exit 1
          fi

          echo "version=$VERSION" >> "$GITHUB_OUTPUT"
          echo "ref=refs/tags/$VERSION" >> "$GITHUB_OUTPUT"

  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    needs: prepare
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          - os: macos-15-intel
            target: x86_64-apple-darwin
          - os: macos-15
            target: aarch64-apple-darwin

    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          ref: ${{ needs.prepare.outputs.ref }}

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Build release binary
        run: cargo build --release --locked --target ${{ matrix.target }}

      - name: Package release archive
        shell: bash
        run: |
          VERSION="${{ needs.prepare.outputs.version }}"
          VERSION="${VERSION#v}"
          mkdir -p dist
          bash ./scripts/package-release.sh \
            "${VERSION}" \
            "${{ matrix.target }}" \
            "target/${{ matrix.target }}/release/smux" \
            dist

      - name: Upload binary archive
        uses: actions/upload-artifact@v4
        with:
          name: smux-${{ matrix.target }}
          path: dist/*.tar.gz
          if-no-files-found: error

  docs:
    name: Generate docs artifacts
    runs-on: ubuntu-latest
    needs: prepare

    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          ref: ${{ needs.prepare.outputs.ref }}

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Generate completions
        run: cargo run --locked -- completions zsh --dir dist/completions

      - name: Generate man pages
        run: cargo run --locked -- man --dir dist/man

      - name: Package docs artifact
        shell: bash
        run: |
          VERSION="${{ needs.prepare.outputs.version }}"
          VERSION="${VERSION#v}"
          tar -C dist -czf "dist/smux-${VERSION}-docs.tar.gz" completions man

      - name: Upload docs artifact
        uses: actions/upload-artifact@v4
        with:
          name: smux-docs
          path: dist/smux-*-docs.tar.gz
          if-no-files-found: error

  publish:
    name: Publish GitHub release
    runs-on: ubuntu-latest
    needs:
      - prepare
      - build
      - docs
    permissions:
      contents: write

    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          ref: ${{ needs.prepare.outputs.ref }}

      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          path: dist

      - name: Collect release files
        shell: bash
        run: |
          mkdir -p release
          find dist -type f -name '*.tar.gz' -exec cp {} release/ \;
          (
            cd release
            shasum -a 256 *.tar.gz > SHA256SUMS
          )

      - name: Generate release notes from changelog
        shell: bash
        run: |
          VERSION="${{ needs.prepare.outputs.version }}"
          VERSION="${VERSION#v}"
          {
            echo "## smux ${VERSION}"
            echo
            awk -v version="$VERSION" '
              $0 ~ "^## \\[" version "\\]" { in_section = 1; next }
              $0 ~ /^## \[/ && in_section { exit }
              in_section { print }
            ' CHANGELOG.md
          } > release/RELEASE_NOTES.md

          if [[ ! -s release/RELEASE_NOTES.md ]] || [[ "$(wc -l < release/RELEASE_NOTES.md)" -le 2 ]]; then
            {
              echo "## smux ${VERSION}"
              echo
              echo "See [CHANGELOG.md](https://github.com/${GITHUB_REPOSITORY}/blob/${{ needs.prepare.outputs.ref }}/CHANGELOG.md) for release details."
            } > release/RELEASE_NOTES.md
          fi

      - name: Publish release
        uses: softprops/action-gh-release@v2
        with:
          body_path: release/RELEASE_NOTES.md
          files: |
            release/*.tar.gz
            release/SHA256SUMS