name: Release
on:
push:
tags:
- "*"
workflow_dispatch:
inputs:
version:
description: "Version to release (without v prefix)"
required: false
type: string
permissions:
contents: write
env:
BINARY_NAME: mcp-gmailcal
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
outputs:
version: ${{ env.VERSION }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set version (from tag)
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Set version (from input)
if: github.event_name == 'workflow_dispatch' && github.event.inputs.version != ''
run: echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
- name: Set version (from Cargo.toml)
if: env.VERSION == ''
run: |
VERSION=$(grep -m1 'version =' Cargo.toml | sed -E 's/version = "([^"]+)"/\1/g')
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Show version
run: echo "Building release for version ${{ env.VERSION }}"
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: Release ${{ env.VERSION }}
tag_name: v${{ env.VERSION }}
draft: false
generate_release_notes: true
token: ${{ github.token }}
build:
name: Build for ${{ matrix.platform }}
needs: release
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
platform: macOS Universal Binary
target: universal-apple-darwin
binary_path: target/universal-apple-darwin/release/mcp-gmailcal
asset_name: mcp-gmailcal-macos-universal.tar.gz
use_universal: true
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.use_universal == true && 'x86_64-apple-darwin,aarch64-apple-darwin' || matrix.target }}
- name: Build (standard)
if: matrix.use_universal != true
run: cargo build --release --target ${{ matrix.target }}
- name: Build macOS Universal Binary
if: matrix.use_universal == true
run: |
# Build for Intel
cargo build --release --target x86_64-apple-darwin
# Build for Apple Silicon
cargo build --release --target aarch64-apple-darwin
# Create output directory
mkdir -p target/universal-apple-darwin/release
# Create universal binary using lipo
lipo -create -output target/universal-apple-darwin/release/mcp-gmailcal \
target/x86_64-apple-darwin/release/mcp-gmailcal \
target/aarch64-apple-darwin/release/mcp-gmailcal
- name: Strip binary (Unix)
if: runner.os != 'Windows'
run: strip ${{ matrix.binary_path }}
continue-on-error: true
- name: Package for Unix
if: runner.os != 'Windows'
run: |
mkdir -p dist
cp ${{ matrix.binary_path }} dist/${{ env.BINARY_NAME }}
cd dist && tar -czf ${{ matrix.asset_name }} ${{ env.BINARY_NAME }}
- name: Package for Windows
if: runner.os == 'Windows'
shell: bash
run: |
mkdir -p dist
cp ${{ matrix.binary_path }} dist/
cd dist && 7z a -tzip ${{ matrix.asset_name }} ${{ env.BINARY_NAME }}.exe
- name: Upload assets
uses: softprops/action-gh-release@v1
with:
files: dist/${{ matrix.asset_name }}
tag_name: v${{ needs.release.outputs.version }}
token: ${{ github.token }}