name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
workflow_dispatch:
inputs:
tag_name:
description: 'The tag name to release (e.g. v1.2.3). Optional if triggered from a tag.'
required: false
type: string
permissions:
contents: write
jobs:
build-and-upload:
name: Build and Upload
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: loc
asset_name: loc-linux-amd64
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: loc
asset_name: loc-macos-amd64
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: loc
asset_name: loc-macos-arm64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: loc.exe
asset_name: loc-windows-amd64.exe
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install musl-tools
if: contains(matrix.target, 'musl')
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Build Release Binary
run: cargo build --release --target ${{ matrix.target }}
- name: Prepare Binary
shell: bash
run: |
mkdir -p dist
cp target/${{ matrix.target }}/release/${{ matrix.artifact_name }} dist/${{ matrix.asset_name }}
- name: Upload Release Asset
uses: softprops/action-gh-release@v2
with:
files: dist/${{ matrix.asset_name }}
name: Release ${{ inputs.tag_name || github.ref_name }}
tag_name: ${{ inputs.tag_name || github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}