new: use goreleaser for publishing #173
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: | |
push: | |
tags: | |
- 'v*.*.*' | |
pull_request: | |
branches: [master, release/*] | |
jobs: | |
build: | |
name: Build for ${{ matrix.name }} | |
runs-on: ${{ matrix.runner }} | |
env: | |
CARGO: cargo | |
strategy: | |
matrix: | |
name: | |
- linux-x86-gnu | |
- linux-x86-musl | |
- linux-arm-gnu | |
- linux-arm-musl | |
- macos-x86 | |
- macos-arm | |
- macos-universal | |
- windows-x86 | |
include: | |
- name: linux-x86-gnu | |
runner: ubuntu-latest | |
family: linux | |
arch: x86_64 | |
target: x86_64-unknown-linux-gnu | |
archiver: tar.gz | |
asset: hl-linux-x86_64-gnu.tar.gz | |
skip: true | |
- name: linux-x86-musl | |
runner: ubuntu-latest | |
family: linux | |
arch: x86_64 | |
target: x86_64-unknown-linux-musl | |
archiver: tar.gz | |
asset: hl-linux-x86_64-musl.tar.gz | |
cross: true | |
- name: linux-arm-gnu | |
runner: ubuntu-latest | |
family: linux | |
arch: aarch64 | |
target: aarch64-unknown-linux-gnu | |
archiver: tar.gz | |
asset: hl-linux-arm64-gnu.tar.gz | |
cross: true | |
skip: true | |
- name: linux-arm-musl | |
runner: ubuntu-latest | |
family: linux | |
arch: aarch64 | |
target: aarch64-unknown-linux-musl | |
archiver: tar.gz | |
asset: hl-linux-arm64-musl.tar.gz | |
cross: true | |
- name: macos-x86 | |
runner: macos-latest | |
family: macos | |
arch: x86_64 | |
target: x86_64-apple-darwin | |
archiver: tar.gz | |
asset: hl-macos-x86_64.tar.gz | |
- name: macos-arm | |
runner: macos-latest | |
family: macos | |
arch: aarch64 | |
target: aarch64-apple-darwin | |
archiver: tar.gz | |
asset: hl-macos-arm64.tar.gz | |
- name: macos-universal | |
runner: macos-latest | |
family: macos | |
arch: '{aarch64,x86_64}' | |
target: '{aarch64,x86_64}-apple-darwin' | |
archiver: tar.gz | |
asset: hl-macos.tar.gz | |
universal: true | |
- name: windows-x86 | |
runner: windows-latest | |
family: windows | |
arch: x86_64 | |
target: x86_64-pc-windows-msvc | |
archiver: 7z | |
asset: hl-windows.zip | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions-rust-lang/setup-rust-toolchain@v1 | |
with: | |
toolchain: stable | |
rustflags: '' | |
- name: Install Cross | |
if: matrix.cross | |
run: | | |
cargo install cross | |
echo "CARGO=cross" >> $GITHUB_ENV | |
- name: Add Target | |
if: matrix.cross == false && matrix.target != '' | |
run: | | |
rustup target add ${{ matrix.target }} | |
- name: Build | |
run: echo ${{ matrix.target }} | xargs -n 1 ${{ env.CARGO }} build --release --locked --verbose --target | |
- name: Sign | |
if: matrix.family == 'macos' | |
run: codesign --force --deep --sign - ./target/${{ matrix.target }}/release/hl | |
- name: Package using `tar` | |
if: matrix.archiver == 'tar.gz' && matrix.universal == false | |
run: tar -C ./target/${{ matrix.target }}/release -cz -f ${{ matrix.asset }} hl | |
- name: Package using `7z` | |
if: matrix.archiver == '7z' && matrix.universal == false | |
run: 7z a ${{ matrix.asset }} .\target\${{ matrix.target }}\release\hl.exe | |
- name: Make universal binary | |
if: matrix.family == 'macos' && matrix.universal == true | |
run: lipo ./target/${{ matrix.target }}/release/hl -create -output ./target/hl | |
- name: Package universal binary using `tar` | |
if: matrix.archiver == 'tar.gz' && matrix.universal == true | |
run: tar -C ./target -cz -f ${{ matrix.asset }} hl | |
- name: Store artifact | |
if: matrix.skip != true | |
uses: actions/upload-artifact@v4 | |
with: | |
name: hl-${{ matrix.arch }}-${{ matrix.family }} | |
path: target/${{ matrix.target }}/release/hl${{ matrix.family == 'windows' && '.exe' || '' }} | |
retention-days: 1 | |
- name: Upload binaries to release | |
if: startsWith(github.ref, 'refs/tags/v') | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: ${{ matrix.asset }} | |
tag: ${{ github.ref }} | |
publish: | |
name: Publish | |
needs: [build] | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout Git repo | |
uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
path: artifacts | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
- name: Run GoReleaser | |
uses: goreleaser/goreleaser-action@v5 | |
with: | |
distribution: goreleaser | |
version: latest | |
args: release --clean --skip=validate --snapshot | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |