name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., v1.0.0)'
required: true
type: string
env:
CARGO_TERM_COLOR: always
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Run tests
run: cargo test --verbose
build:
name: Build
needs: test
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
name: envswitch-linux-x86_64
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
name: envswitch-linux-x86_64-musl
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
name: envswitch-linux-aarch64
- target: x86_64-apple-darwin
os: macos-latest
name: envswitch-macos-x86_64
- target: aarch64-apple-darwin
os: macos-latest
name: envswitch-macos-aarch64
- target: x86_64-pc-windows-msvc
os: windows-latest
name: envswitch-windows-x86_64.exe
- target: aarch64-pc-windows-msvc
os: windows-latest
name: envswitch-windows-aarch64.exe
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross-compilation tools (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y gcc-multilib
if [[ "${{ matrix.target }}" == "x86_64-unknown-linux-musl" ]]; then
sudo apt-get install -y musl-tools
elif [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]]; then
sudo apt-get install -y gcc-aarch64-linux-gnu
fi
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build binary
run: |
if [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]]; then
export CC=aarch64-linux-gnu-gcc
export CXX=aarch64-linux-gnu-g++
fi
cargo build --release --target ${{ matrix.target }}
- name: Prepare binary (Unix)
if: matrix.os != 'windows-latest'
run: |
cp target/${{ matrix.target }}/release/envswitch ${{ matrix.name }}
chmod +x ${{ matrix.name }}
- name: Prepare binary (Windows)
if: matrix.os == 'windows-latest'
run: |
cp target/${{ matrix.target }}/release/envswitch.exe ${{ matrix.name }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: ${{ matrix.name }}
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create checksums
run: |
cd artifacts
for dir in */; do
cd "$dir"
sha256sum * > ../checksums-$(basename "$dir").txt
cd ..
done
- name: Get version
id: version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.version }}
release_name: Release ${{ steps.version.outputs.version }}
body: |
## Changes in ${{ steps.version.outputs.version }}
### Downloads
Choose the appropriate binary for your platform:
- **Linux x86_64**: `envswitch-linux-x86_64`
- **Linux x86_64 (musl)**: `envswitch-linux-x86_64-musl` (static binary)
- **Linux ARM64**: `envswitch-linux-aarch64`
- **macOS x86_64**: `envswitch-macos-x86_64`
- **macOS ARM64**: `envswitch-macos-aarch64`
- **Windows x86_64**: `envswitch-windows-x86_64.exe`
- **Windows ARM64**: `envswitch-windows-aarch64.exe`
### Installation
1. Download the appropriate binary for your platform
2. Make it executable (Unix systems): `chmod +x envswitch-*`
3. Move to a directory in your PATH: `mv envswitch-* /usr/local/bin/envswitch`
### Verification
All binaries are provided with SHA256 checksums for verification.
draft: false
prerelease: false
- name: Upload Release Assets
run: |
cd artifacts
for dir in */; do
binary_name=$(basename "$dir")
binary_path="$dir/$binary_name"
# Upload binary
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$binary_path" \
"${{ steps.create_release.outputs.upload_url }}?name=$binary_name"
# Upload checksum
checksum_file="checksums-$binary_name.txt"
if [[ -f "$checksum_file" ]]; then
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: text/plain" \
--data-binary @"$checksum_file" \
"${{ steps.create_release.outputs.upload_url }}?name=$checksum_file"
fi
done