name: build and release
on:
workflow_dispatch:
release:
types: [created]
permissions:
contents: write
jobs:
build:
name: ${{ matrix.platform.os_name }} with Rust ${{ matrix.toolchain }}
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform:
- os_name: Linux-aarch64
os: ubuntu-22.04
target: aarch64-unknown-linux-musl
bin: cpd-linux-arm64
- os_name: Linux-x86_64
os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
bin: cpd-linux-amd64
- os_name: Windows-x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
bin: cpd-amd64.exe
- os_name: macOS-x86_64
os: macos-latest
target: x86_64-apple-darwin
bin: cpd-darwin-amd64
- os_name: macOS-aarch64
os: macos-latest
target: aarch64-apple-darwin
bin: cpd-darwin-arm64
toolchain:
- stable
steps:
- uses: actions/checkout@v4
- name: Build binary
uses: houseabsolute/actions-rust-cross@v0
with:
command: "build"
target: ${{ matrix.platform.target }}
toolchain: ${{ matrix.toolchain }}
args: "--locked --release"
strip: true
- name: Rename binary (Linux/macOS)
if: matrix.platform.os_name != 'Windows-x86_64'
run: mv target/${{ matrix.platform.target }}/release/cpd target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}
- name: Rename binary (Windows)
if: matrix.platform.os_name == 'Windows-x86_64'
shell: pwsh
run: Rename-Item "target/${{ matrix.platform.target }}/release/cpd.exe" "${{ matrix.platform.bin }}"
- name: Generate SHA-256 (Linux)
if: startsWith(matrix.platform.os_name, 'Linux')
run: sha256sum target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }} > target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}.sha256
- name: Generate SHA-256 (macOS)
if: startsWith(matrix.platform.os_name, 'macOS')
run: shasum -a 256 target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }} | cut -d ' ' -f 1 > target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}.sha256
- name: Generate SHA-256 (Windows)
if: matrix.platform.os_name == 'Windows-x86_64'
shell: pwsh
run: |
$hash = Get-FileHash -Algorithm SHA256 "target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}"
$hash.Hash | Out-File -Encoding ascii "target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}.sha256"
- name: Release binary & checksum to GitHub
uses: softprops/action-gh-release@v1
with:
files: |
target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}
target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}.sha256
publish-crate:
name: Publish crate to crates.io
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: katyo/publish-crates@v2
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}