Publish #8
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish | |
on: | |
workflow_dispatch: | |
push: | |
tags: | |
- v[0-9]+.* | |
permissions: | |
contents: write | |
jobs: | |
publish: | |
name: Publish to crates.io and GitHub | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
- name: Cache dependencies | |
uses: Swatinem/rust-cache@v2 | |
- name: Run tests | |
run: cargo test | |
- name: Check version matches tag | |
if: github.event_name == 'push' | |
run: | | |
PKG_VERSION=$(cargo pkgid | cut -d# -f2 | cut -d: -f2) | |
TAG_VERSION=${GITHUB_REF#refs/tags/v} | |
if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then | |
echo "Version mismatch: Tag version ($TAG_VERSION) doesn't match Cargo.toml version ($PKG_VERSION)" | |
exit 1 | |
fi | |
- name: Publish to crates.io | |
if: github.event_name == 'push' | |
run: cargo publish | |
env: | |
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
- name: Create GitHub Release | |
if: github.event_name == 'push' | |
uses: softprops/action-gh-release@v1 | |
with: | |
generate_release_notes: true | |
build-macos: | |
name: Build macOS binary | |
runs-on: macos-latest | |
needs: publish | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
- uses: Swatinem/rust-cache@v2 | |
- name: Build release binary | |
run: | | |
cargo build --release | |
mkdir -p release-artifacts | |
cp target/release/termv release-artifacts/termv-${{ github.ref_name }}-darwin-x86_64 | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: macos-binary | |
path: release-artifacts/* | |
- name: Upload to release | |
if: github.event_name == 'push' | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: release-artifacts/* | |
build-windows: | |
name: Build Windows binary | |
runs-on: windows-latest | |
needs: publish | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
- uses: Swatinem/rust-cache@v2 | |
- name: Build release binary | |
run: | | |
cargo build --release | |
mkdir release-artifacts | |
copy target\release\termv.exe release-artifacts\termv-${{ github.ref_name }}-windows-x86_64.exe | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: windows-binary | |
path: release-artifacts\* | |
- name: Upload to release | |
if: github.event_name == 'push' | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: release-artifacts\* | |
build-linux-arm64: | |
name: Build Linux ARM64 binary | |
runs-on: ubuntu-latest | |
needs: publish | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: aarch64-unknown-linux-gnu | |
- uses: Swatinem/rust-cache@v2 | |
- name: Install cross-compilation dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y gcc-aarch64-linux-gnu | |
- name: Build release binary | |
run: | | |
cargo build --release --target aarch64-unknown-linux-gnu | |
mkdir -p release-artifacts | |
cp target/aarch64-unknown-linux-gnu/release/termv release-artifacts/termv-${{ github.ref_name }}-linux-arm64 | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: linux-arm64-binary | |
path: release-artifacts/* | |
- name: Upload to release | |
if: github.event_name == 'push' | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: release-artifacts/* | |
build-linux-x86: | |
name: Build Linux x86 (32-bit) binary | |
runs-on: ubuntu-latest | |
needs: publish | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: i686-unknown-linux-gnu | |
- uses: Swatinem/rust-cache@v2 | |
- name: Install cross-compilation dependencies | |
run: | | |
sudo dpkg --add-architecture i386 | |
sudo apt-get update | |
sudo apt-get install -y gcc-multilib | |
- name: Build release binary | |
run: | | |
cargo build --release --target i686-unknown-linux-gnu | |
mkdir -p release-artifacts | |
cp target/i686-unknown-linux-gnu/release/termv release-artifacts/termv-${{ github.ref_name }}-linux-x86 | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: linux-x86-binary | |
path: release-artifacts/* | |
- name: Upload to release | |
if: github.event_name == 'push' | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: release-artifacts/* | |
build-linux-x86_64: | |
name: Build Linux x86_64 (64-bit) binary | |
runs-on: ubuntu-latest | |
needs: publish | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: x86_64-unknown-linux-gnu | |
- uses: Swatinem/rust-cache@v2 | |
- name: Build release binary | |
run: | | |
cargo build --release --target x86_64-unknown-linux-gnu | |
mkdir -p release-artifacts | |
cp target/x86_64-unknown-linux-gnu/release/termv release-artifacts/termv-${{ github.ref_name }}-linux-x86_64 | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: linux-x86_64-binary | |
path: release-artifacts/* | |
- name: Upload to release | |
if: github.event_name == 'push' | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: release-artifacts/* |