Skip to content

Release

Release #8

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:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest # Use Linux runner for Nix
asset_name_suffix: linux-x86_64
binary_name_suffix: ""
use_nix: true
- target: x86_64-apple-darwin
os: macos-latest # Use macOS runner for Nix
asset_name_suffix: macos-x86_64
binary_name_suffix: ""
use_nix: true
- target: aarch64-apple-darwin
os: macos-latest # Use macOS runner for Nix
asset_name_suffix: macos-aarch64
binary_name_suffix: ""
use_nix: true
- target: x86_64-pc-windows-msvc
os: windows-latest # Windows runner, build natively
asset_name_suffix: windows-x86_64.exe
binary_name_suffix: ".exe"
use_nix: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
# --- Nix Setup (Linux/macOS) ---
- name: Install Nix
if: matrix.use_nix == true
uses: cachix/install-nix-action@v31
with:
# Use GitHub token to avoid rate limiting when fetching flakes
github_access_token: ${{ secrets.GITHUB_TOKEN }}
# extra_nix_config: |
# experimental-features = nix-command flakes
# --- Native Rust Setup (Windows) ---
- name: Set up Rust toolchain (Windows only)
if: matrix.use_nix == false
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
# --- Build Step ---
- name: Build binary (Nix)
if: matrix.use_nix == true
# Run the cargo build command within the Nix development shell
# This ensures all dependencies from flake.nix (like openssl) are available
run: |
nix develop .#default --command bash -c ' \
echo "Adding target ${{ matrix.target }} with rustup..." && \
rustup target add ${{ matrix.target }} && \
echo "Building for target ${{ matrix.target }}..." && \
cargo build --release --target ${{ matrix.target }} --verbose \
'
- name: Build binary
if: matrix.use_nix == false
run: cargo build --release --target ${{ matrix.target }} --verbose
# --- 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 }}"
TARGET_DIR="target/${{ matrix.target }}/release"
BINARY_PATH="$TARGET_DIR/$BINARY_NAME"
echo "Calculated binary path: $BINARY_PATH"
echo "Calculated asset name: $ASSET_NAME"
if [[ ! -f "$BINARY_PATH" ]]; then
echo "Error: Binary not found at $BINARY_PATH"
echo "Listing contents of $TARGET_DIR:"
if [[ -d "$TARGET_DIR" ]]; then
ls -l "$TARGET_DIR"
else
echo "Target directory $TARGET_DIR does not exist."
echo "Listing contents of ./target directory:"
ls -l ./target || echo "Could not list ./target"
fi
exit 1
fi
# Rename binary to the desired asset name
mv "$BINARY_PATH" "$TARGET_DIR/$ASSET_NAME"
echo "Renamed binary to $TARGET_DIR/$ASSET_NAME"
echo "asset_path=$TARGET_DIR/$ASSET_NAME" >> $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 }}
path: ${{ steps.artifact_details.outputs.asset_path }}
if-no-files-found: error
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:
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