Skip to content

Commit

Permalink
Merge pull request #3 from chris-short/release-gh-action
Browse files Browse the repository at this point in the history
Release GH Action
  • Loading branch information
chris-short authored Dec 12, 2024
2 parents 8b047ae + fe564eb commit d226d8b
Showing 1 changed file with 70 additions and 33 deletions.
103 changes: 70 additions & 33 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,83 @@ name: Release

on:
push:
tags:
- v[0-9]+.*
branches: [ "main" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]

permissions:
contents: write

jobs:
create-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/create-gh-release-action@v1
with:
# (optional)
changelog: CHANGELOG.md
# (required)
token: ${{ secrets.GITHUB_TOKEN }}
build-and-upload:
name: Build and upload
runs-on: ${{ matrix.os }}

upload-assets:
needs: create-release
strategy:
matrix:
# You can add more, for any target you'd like!
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
build-tool: cargo-zigbuild
# cargo-zigbuild's glibc version suffix is also supported.
- target: aarch64-unknown-linux-gnu.2.17
- build: linux
os: ubuntu-latest
build-tool: cargo-zigbuild
- target: aarch64-apple-darwin
target: x86_64-unknown-linux-musl

- build: macos
os: macos-latest
build-tool: cargo
runs-on: ${{ matrix.os }}
target: x86_64-apple-darwin

- build: windows-gnu
os: windows-latest
target: x86_64-pc-windows-gnu

steps:
- uses: actions/checkout@v4
- uses: taiki-e/upload-rust-binary-action@v1
- name: Checkout
uses: actions/checkout@v3

- name: Get the release version from the tag
shell: bash
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Install Rust
# Or @nightly if you want
uses: dtolnay/rust-toolchain@stable
# Arguments to pass in
with:
# Make Rust compile to our target (defined in the matrix)
targets: ${{ matrix.target }}

- name: Build
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --verbose --release --target ${{ matrix.target }}

- name: Build archive
shell: bash
run: |
# Replace with the name of your binary
binary_name="spitter"
dirname="$binary_name-${{ env.VERSION }}-${{ matrix.target }}"
mkdir "$dirname"
if [ "${{ matrix.os }}" = "windows-latest" ]; then
mv "target/${{ matrix.target }}/release/$binary_name.exe" "$dirname"
else
mv "target/${{ matrix.target }}/release/$binary_name" "$dirname"
fi
if [ "${{ matrix.os }}" = "windows-latest" ]; then
7z a "$dirname.zip" "$dirname"
echo "ASSET=$dirname.zip" >> $GITHUB_ENV
else
tar -czf "$dirname.tar.gz" "$dirname"
echo "ASSET=$dirname.tar.gz" >> $GITHUB_ENV
fi
- name: Release
uses: softprops/action-gh-release@v1
with:
# (required)
bin: ...
# (optional) Target triple, default is host triple.
target: ${{ matrix.target }}
# (optional) Tool to build binaries (cargo, cross, or cargo-zigbuild)
build-tool: ${{ matrix.build-tool }}
# (required) GitHub token for uploading assets to GitHub Releases.
token: ${{ secrets.GITHUB_TOKEN }}
files: |
${{ env.ASSET }}

0 comments on commit d226d8b

Please sign in to comment.