name: Release
permissions:
contents: write
env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
build:
name: Build ${{ matrix.target.name }} binary
runs-on: ${{ matrix.target.os }}
strategy:
matrix:
target:
[
{ name: aarch64-apple-darwin, os: macos-latest },
{ name: x86_64-unknown-linux-gnu, os: ubuntu-latest },
{ name: x86_64-pc-windows-msvc, os: windows-latest },
]
steps:
- name: Fetch latest code
uses: actions/checkout@v6
- name: Set up Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: true
components: rustfmt, clippy
- name: Add target
run: rustup target add ${{ matrix.target.name }}
- name: Build
run: cargo build --profile final-release --locked --target ${{ matrix.target.name }}
- name: Archive binaries (macOS)
if: matrix.target.os == 'macos-latest'
run: |
VERSION="${GITHUB_REF_NAME#v}"
PKG_NAME="vibe-style-${{ matrix.target.name }}-v${VERSION}"
mkdir -p "${PKG_NAME}"
cp target/${{ matrix.target.name }}/final-release/vstyle "${PKG_NAME}/vstyle"
cp target/${{ matrix.target.name }}/final-release/cargo-vstyle "${PKG_NAME}/cargo-vstyle"
tar -czf "${PKG_NAME}.tgz" "${PKG_NAME}"
- name: Archive binaries (Windows)
if: matrix.target.os == 'windows-latest'
shell: pwsh
run: |
$version = $env:GITHUB_REF_NAME.Substring(1)
$pkgName = "vibe-style-${{ matrix.target.name }}-v$version"
New-Item -ItemType Directory -Path $pkgName | Out-Null
Copy-Item "target/${{ matrix.target.name }}/final-release/vstyle.exe" "$pkgName/vstyle.exe"
Copy-Item "target/${{ matrix.target.name }}/final-release/cargo-vstyle.exe" "$pkgName/cargo-vstyle.exe"
Compress-Archive -Path $pkgName -DestinationPath "$pkgName.zip"
- name: Archive binaries (Linux)
if: matrix.target.os == 'ubuntu-latest'
run: |
VERSION="${GITHUB_REF_NAME#v}"
PKG_NAME="vibe-style-${{ matrix.target.name }}-v${VERSION}"
mkdir -p "${PKG_NAME}"
cp target/${{ matrix.target.name }}/final-release/vstyle "${PKG_NAME}/vstyle"
cp target/${{ matrix.target.name }}/final-release/cargo-vstyle "${PKG_NAME}/cargo-vstyle"
tar -czf "${PKG_NAME}.tgz" "${PKG_NAME}"
- name: Upload artifact
uses: actions/upload-artifact@v6
with:
name: vibe-style-${{ matrix.target.name }}
path: vibe-style-${{ matrix.target.name }}-v*.*
retention-days: 1
release:
name: Publish binary release
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Download artifacts
uses: actions/download-artifact@v7
- name: Hash
run: |
mkdir -p artifacts
mv vibe-style-*/* artifacts/
cd artifacts
sha256sum * | tee ../SHA256
md5sum * | tee ../MD5
mv ../SHA256 .
mv ../MD5 .
- name: Publish
uses: softprops/action-gh-release@v2
with:
discussion_category_name: Announcements
generate_release_notes: true
files: artifacts/*
publish-on-crates-io:
name: Publish on crates.io
runs-on: ubuntu-latest
needs: [release]
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Fetch latest code
uses: actions/checkout@v6
- name: Set up Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: true
components: rustfmt, clippy
- name: Publish
run: cargo publish --locked --token "${{ secrets.CARGO_REGISTRY_TOKEN }}"