Create Release #6
This file contains hidden or 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
# .github/workflows/release.yml | |
name: Create Release | |
on: | |
push: | |
tags: | |
- 'v*.*.*' # This workflow runs when we push a tag like v0.2.1 | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
create-release: | |
name: Create Release | |
runs-on: ubuntu-latest | |
outputs: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
steps: | |
- name: Checkout code # <-- ADD THIS STEP | |
uses: actions/checkout@v4 | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.ref }} | |
release_name: Release ${{ github.ref }} | |
body_path: CHANGELOG.md | |
draft: true # Keeping this as true for testing | |
prerelease: true # Keeping this as true for testing | |
build-and-upload: | |
name: Build and Upload Binaries | |
needs: create-release | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-pc-windows-msvc | |
os: windows-latest | |
asset_name_suffix: "windows-x86_64.zip" | |
- target: x86_64-unknown-linux-musl | |
os: ubuntu-latest | |
asset_name_suffix: "linux-x86_64.tar.gz" | |
- target: x86_64-apple-darwin | |
os: macos-latest | |
asset_name_suffix: "macos-x86_64.tar.gz" | |
- target: aarch64-apple-darwin | |
os: macos-latest | |
asset_name_suffix: "macos-arm64.tar.gz" | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
target: ${{ matrix.target }} | |
override: true | |
- name: Build binary | |
run: cargo build --release --target ${{ matrix.target }} | |
# For MUSL target, we might need to set up cross-compilation | |
# if: matrix.target == 'x86_64-unknown-linux-musl' ... | |
- name: Prepare package | |
shell: bash | |
run: | | |
# Define the final package name from the matrix | |
PACKAGE_NAME="lstr-${{ matrix.asset_name_suffix }}" | |
# Create a temporary staging directory to hold the assets | |
mkdir staging | |
# Copy the correct binary into the staging directory | |
if [[ "${{ runner.os }}" == "Windows" ]]; then | |
cp target/${{ matrix.target }}/release/lstr.exe staging/ | |
else | |
cp target/${{ matrix.target }}/release/lstr staging/ | |
fi | |
# Copy documentation into the staging directory | |
cp README.md staging/ | |
cp LICENSE staging/ | |
# Create the final archive from the contents of the staging directory | |
if [[ "${{ runner.os }}" == "Windows" ]]; then | |
# For zip, archive the files inside the staging directory | |
7z a "$PACKAGE_NAME" ./staging/* | |
else | |
# For tar.gz, change directory to staging and archive its contents | |
tar -czf "$PACKAGE_NAME" -C staging . | |
fi | |
# Set the asset name for the next step | |
echo "ASSET=$PACKAGE_NAME" >> $GITHUB_ENV | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.create-release.outputs.upload_url }} | |
asset_path: ${{ env.ASSET }} | |
asset_name: ${{ env.ASSET }} | |
asset_content_type: application/octet-stream |