ts-bridge 0.2.3

A TypeScript language-server shim that bridges Neovim's LSP client with tsserver.
Documentation
name: release

on:
  push:
    tags:
      - "v*"
  workflow_dispatch:

permissions:
  contents: read

jobs:
  test-and-build:
    name: Test and build (${{ matrix.label }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            label: Linux
            artifact: ts-bridge-linux-x86_64
            binary_path: target/release/ts-bridge
          - os: macos-latest
            label: macOS
            artifact: ts-bridge-macos-universal
            binary_path: target/release/ts-bridge
          - os: windows-latest
            label: Windows
            artifact: ts-bridge-windows-x86_64
            binary_path: target/release/ts-bridge.exe
    env:
      CARGO_TERM_COLOR: always
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

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

      - name: Cache cargo build assets
        uses: Swatinem/rust-cache@v2
        with:
          cache-on-failure: true

      - name: Run tests
        run: cargo test --locked --all-targets

      - name: Build release binary
        run: cargo build --locked --release

      - name: Upload compiled binary
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.artifact }}
          path: ${{ matrix.binary_path }}
          if-no-files-found: error

  release:
    name: Publish release assets
    runs-on: ubuntu-latest
    needs: test-and-build
    if: startsWith(github.ref, 'refs/tags/v')
    permissions:
      contents: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

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

      - name: Extract release notes from CHANGELOG.md
        shell: bash
        run: |
          set -euo pipefail
          mkdir -p notes
          raw_tag="${GITHUB_REF##*/}"
          version="${raw_tag#v}"
          awk -v version="$version" '
            function header_to_version(line) {
              sub(/^##[[:space:]]*\[/, "", line)
              sub(/\].*/, "", line)
              return line
            }
            /^##[[:space:]]*\[/ {
              if (capture) exit
              current = header_to_version($0)
              if (current == version) {
                capture = 1
                print $0
                next
              }
            }
            capture { print }
          ' CHANGELOG.md > notes/RELEASE_NOTES.md
          if [[ ! -s notes/RELEASE_NOTES.md ]]; then
            echo "Unable to find release notes for version $version in CHANGELOG.md" >&2
            exit 1
          fi

      - name: Package release archives
        shell: bash
        run: |
          set -euo pipefail
          mkdir -p release
          for dir in dist/*; do
            name="$(basename "$dir")"
            if [[ "$name" == *windows* ]]; then
              zip -j "release/${name}.zip" "$dir"/*
            else
              tar -C "$dir" -czf "release/${name}.tar.gz" .
            fi
          done

      - name: Generate SHA256 checksums
        shell: bash
        run: |
          set -euo pipefail
          cd release
          sha256sum * > SHA256SUMS

      - name: Publish GitHub release
        uses: softprops/action-gh-release@v2
        with:
          files: release/*
          body_path: notes/RELEASE_NOTES.md
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}