Skip to content

Handle Release

Handle Release #14

Workflow file for this run

name: Handle Release
on:
workflow_dispatch:
inputs:
do_github_release:
description: "Perform a GitHub release?"
required: true
type: boolean
default: false
do_crates_release:
description: "Perform a crates.io release?"
required: true
type: boolean
default: false
push:
tags:
- "v*"
env:
CARGO_TERM_COLOR: always
jobs:
build-windows:
runs-on: windows-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Build
run: cargo build --release --bin aplang
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: windows-binary
path: target/release/aplang.exe
build-macos:
runs-on: macos-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Add Targets
run: |
rustup target add aarch64-apple-darwin
rustup target add x86_64-apple-darwin
- name: Build x86_64
run: cargo build --release --bin aplang --target x86_64-apple-darwin
- name: Build aarch64
run: cargo build --release --bin aplang --target aarch64-apple-darwin
- name: Lipo Pack
run: lipo -create -output out/aplang target/x86_64-apple-darwin/release/aplang target/aarch64-apple-darwin/release/aplang
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: macos-binary
path: out/aplang
release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [build-windows, build-macos]
steps:
- name: Download Windows binary
uses: actions/download-artifact@v4
with:
name: windows-binary
path: artifacts/windows/
- name: Download macOS binary
uses: actions/download-artifact@v4
with:
name: macos-binary
path: artifacts/macos/
- name: List Downloaded Files
run: ls -R artifacts
- name: Create GitHub Release
if: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.do_github_release == 'true') }}
uses: softprops/action-gh-release@v2
with:
prerelease: true
generate_release_notes: true
draft: ${{ github.event_name != 'push' }}
files: |
artifacts/windows/aplang.exe
artifacts/macos/aplang
cargo-publish:
name: Publish to Crates.io
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && github.event.inputs.do_crates_release == 'true') }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Read version from Cargo.toml
id: cargo_toml_version
uses: SebRollen/toml-action@v1.2.0
with:
file: Cargo.toml
field: package.version
- name: Ensure Cargo.toml version matches tag
if: startsWith(github.ref, 'refs/tags/v')
run: |
TAG_VERSION="${GITHUB_REF_NAME#v}"
CARGO_VERSION="${{ steps.cargo_toml_version.outputs.value }}"
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "Error: Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
# allow dirty is to make sure the Cargo.lock is always submited
run: cargo publish --allow-dirty