dts-lsp 0.1.7

Language Server for Device Tree Source files
name: Release

on:
  workflow_dispatch:
  push:
   tags:
     # Regex for a version number such as 0.2.1
     - '*'

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always

jobs:
  changelog:
    runs-on: ubuntu-latest
    steps:
      - name: Install cliff
        run: cargo install git-cliff

      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Write Changelog
        run: git cliff --latest -o log.txt

      - name: Read Changelog
        run: cat log.txt

      - name: Release
        uses: softprops/action-gh-release@v2
        with:
          body_path: log.txt

  build-and-upload:
    name: Build and upload
    needs: changelog
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        include:
          - build: liunx
            os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            dependencies: sudo apt install musl-tools
            binary_name: dts-lsp

          - build: macos
            os: macos-latest
            target: x86_64-apple-darwin
            dependencies:
            binary_name: dts-lsp

          - build: macos
            os: macos-latest
            target: aarch64-apple-darwin
            dependencies:
            binary_name: dts-lsp

          - build: windows
            os: windows-latest
            target: x86_64-pc-windows-msvc
            dependencies:
            binary_name: dts-lsp.exe

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Get release version
        shell: bash
        run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

      - name: Install dependencies
        run: ${{ matrix.dependencies }}

      - name: Add rustup target
        run: rustup target add ${{ matrix.target }}

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

      - name: Build archive
        shell: bash
        run: |
          release_name="dts-lsp-${{ env.VERSION }}-${{ matrix.target }}"
          tar -czf "$release_name.tar.gz" -C target/${{ matrix.target }}/release "${{ matrix.binary_name }}"

          echo "ASSET=$release_name.tar.gz" >> $GITHUB_ENV

      - name: Release
        uses: softprops/action-gh-release@v2
        with:
          files: |
            ${{ env.ASSET }}

  publish-crate:
    name: Publish crate
    needs: build-and-upload
    runs-on: ubuntu-latest
    env:
      CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
    steps:
    - uses: actions/checkout@v3
    - name: Build
      run: cargo publish --token ${CRATES_IO_TOKEN}