name: Release
on:
push:
tags: ["v*"]
permissions:
contents: write
id-token: write
jobs:
publish-crate:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Validate version matches tag
run: |
CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
TAG_VERSION=${GITHUB_REF_NAME#v}
if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
echo "ERROR: Cargo.toml version ($CARGO_VERSION) != tag ($TAG_VERSION)"
exit 1
fi
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- name: Publish to crates.io
run: cargo publish || echo "Already published (idempotent)"
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
build:
name: Build ${{ matrix.target }}
needs: publish-crate
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
- target: x86_64-apple-darwin
os: macos-latest
archive: tar.gz
- target: aarch64-apple-darwin
os: macos-latest
archive: tar.gz
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: zip
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Package (unix)
if: matrix.archive == 'tar.gz'
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../perl-lsp-${{ matrix.target }}.tar.gz perl-lsp
cd ../../..
- name: Package (windows)
if: matrix.archive == 'zip'
run: |
cd target/${{ matrix.target }}/release
7z a ../../../perl-lsp-${{ matrix.target }}.zip perl-lsp.exe
cd ../../..
- name: Upload release asset
uses: softprops/action-gh-release@v2
with:
files: perl-lsp-${{ matrix.target }}.${{ matrix.archive }}