Skip to content

Release

Release #4

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*.*.*' # Trigger on version tags like v1.0.0
workflow_dispatch: # Allows manual triggering
inputs:
version:
description: 'The version tag to use for the release (e.g., v1.0.0)'
required: true
type: string
permissions:
contents: write # Needed for softprops/action-gh-release to create releases and upload assets
env:
CARGO_TERM_COLOR: always
CRATE_NAME: rustdocs_mcp_server
jobs:
build_assets:
name: Build Asset (${{ matrix.target }})
strategy:
matrix:
include:
# Nix builds (native)
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
build_method: nix
asset_name_suffix: linux-x86_64
binary_name_suffix: ""
- target: x86_64-apple-darwin
os: macos-latest
build_method: nix
asset_name_suffix: macos-x86_64
binary_name_suffix: ""
# Cross builds
- target: aarch64-apple-darwin
os: macos-latest # Cross-compile from x86_64 runner
build_method: cross
asset_name_suffix: macos-aarch64
binary_name_suffix: ""
- target: x86_64-pc-windows-msvc
os: windows-latest
build_method: cross
asset_name_suffix: windows-x86_64.exe
binary_name_suffix: ".exe"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
# --- Nix Setup (only runs if build_method is nix) ---
- name: Install Nix
uses: cachix/install-nix-action@v31
if: matrix.build_method == 'nix'
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
# Ensure flakes are enabled (default in recent versions, but explicit is safe)
extra_nix_config: |
experimental-features = nix-command flakes
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
# --- Dependency Setup for Cross-Compile (only runs if build_method is cross) ---
- name: Install macOS dependencies (for cross-compile)
# Only needed when cross-compiling aarch64 on an x86_64 macOS runner
if: matrix.build_method == 'cross' && matrix.target == 'aarch64-apple-darwin'
run: |
brew install openssl@3 pkg-config
echo "OPENSSL_DIR=$(brew --prefix openssl@3)" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$(brew --prefix openssl@3)/lib/pkgconfig" >> $GITHUB_ENV
# --- Build Steps (conditional) ---
- name: Build binary using Nix
if: matrix.build_method == 'nix'
# Assuming your flake provides the crate binary via the default package `.#rustdocs_mcp_server`
# or adjust the flake output reference as needed (e.g., .#packages.${system}.default)
run: nix build .#${CRATE_NAME} --print-build-logs
- name: Build binary using actions-rust-cross
if: matrix.build_method == 'cross'
uses: houseabsolute/actions-rust-cross@v1
with:
target: ${{ matrix.target }}
args: "--release --verbose"
strip: false # Keep strip false for consistency, especially with cross-compiles
# --- Artifact Handling ---
- name: Determine Artifact Path and Name
id: artifact_details
shell: bash
run: |
BINARY_NAME="${{ env.CRATE_NAME }}${{ matrix.binary_name_suffix }}"
ASSET_NAME="${{ env.CRATE_NAME }}-${{ matrix.asset_name_suffix }}"
if [[ "${{ matrix.build_method }}" == "nix" ]]; then
# Nix build output path (adjust if flake output is different)
# Assumes the binary is directly in result/bin/
BINARY_PATH="./result/bin/$BINARY_NAME"
else
# Cross build output path
BINARY_PATH="target/${{ matrix.target }}/release/$BINARY_NAME"
fi
echo "Build method: ${{ matrix.build_method }}"
echo "Calculated binary path: $BINARY_PATH"
echo "Calculated asset name: $ASSET_NAME"
# Check if the binary exists
if [[ ! -f "$BINARY_PATH" ]]; then
echo "Error: Binary not found at $BINARY_PATH"
echo "Listing contents of potential output directories:"
echo "--- Nix build (./result/bin):"
ls -l ./result/bin || echo "Directory ./result/bin not found or empty."
echo "--- Cross build (target/${{ matrix.target }}/release):"
ls -l target/${{ matrix.target }}/release || echo "Directory target/${{ matrix.target }}/release not found or empty."
exit 1
fi
# Create a temporary directory for consistent artifact upload
mkdir -p ./artifacts_temp
RENAMED_PATH="./artifacts_temp/$ASSET_NAME"
# Move the binary to the temp dir with the final asset name
mv "$BINARY_PATH" "$RENAMED_PATH"
echo "Moved/Renamed binary to $RENAMED_PATH"
echo "asset_path=$RENAMED_PATH" >> $GITHUB_OUTPUT
echo "asset_name=$ASSET_NAME" >> $GITHUB_OUTPUT
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.artifact_details.outputs.asset_name }} # Use asset name for artifact name
path: ${{ steps.artifact_details.outputs.asset_path }}
if-no-files-found: error # Error if the artifact isn't found
release:
name: Create GitHub Release
needs: build_assets
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts # Download all artifacts to a directory named 'artifacts'
- name: List downloaded artifacts for debugging
run: |
echo "Listing downloaded artifacts:"
find artifacts -type f
echo "---"
- name: Create Release and Upload Assets
uses: softprops/action-gh-release@v2
with:
# Use the input version for manual triggers, otherwise use the tag ref
tag_name: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.ref_name }}
name: Release ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.ref_name }}
body: |
Automated release for ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.ref_name }}
draft: false
prerelease: false
files: artifacts/*/* # Upload all files from all subdirectories within artifacts