Skip to content

! Add test tag support for GitHub Actions workflow #5

! Add test tag support for GitHub Actions workflow

! Add test tag support for GitHub Actions workflow #5

Workflow file for this run

name: Build and Release
on:
push:
tags:
- "*-alpha"
- "*-beta"
- "*-test" # Added for testing the workflow without affecting crates.io
- "[0-9]+.[0-9]+.[0-9]+"
jobs:
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
# Temporarily disable these targets until we fix the macOS x86_64 build
# - os: ubuntu-latest
# target: x86_64-unknown-linux-gnu
# artifact_name: omr-bumper
# asset_name: omr-bumper-linux-x86_64
# - os: windows-latest
# target: x86_64-pc-windows-msvc
# artifact_name: omr-bumper.exe
# asset_name: omr-bumper-windows-x86_64.exe
# - os: macos-latest
# target: aarch64-apple-darwin
# artifact_name: omr-bumper
# asset_name: omr-bumper-macos-aarch64
# comment: "Native build on Apple Silicon"
# Only run the macOS Intel build for testing
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: omr-bumper
asset_name: omr-bumper-macos-x86_64
comment: "Cross-compilation to Intel from Apple Silicon"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Rust
run: |
rustup update stable
rustup target add ${{ matrix.target }}
rustup default stable
# Install nightly for unstable features if needed for cross-compilation
if [[ "${{ matrix.os }}" == "macos-latest" && "${{ matrix.target }}" == "x86_64-apple-darwin" ]]; then
rustup toolchain install nightly
rustup component add rust-src --toolchain nightly
fi
- name: Install dependencies (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install openssl@3 lld llvm pkg-config
# Get OpenSSL path
OPENSSL_DIR=$(brew --prefix openssl@3)
echo "OPENSSL_DIR=$OPENSSL_DIR" >> "$GITHUB_ENV"
echo "OPENSSL_ROOT_DIR=$OPENSSL_DIR" >> "$GITHUB_ENV"
echo "OPENSSL_INCLUDE_DIR=$OPENSSL_DIR/include" >> "$GITHUB_ENV"
echo "OPENSSL_LIB_DIR=$OPENSSL_DIR/lib" >> "$GITHUB_ENV"
echo "LIBRARY_PATH=$(brew --prefix)/lib" >> "$GITHUB_ENV"
echo "PKG_CONFIG_PATH=$OPENSSL_DIR/lib/pkgconfig" >> "$GITHUB_ENV"
# Set SDK paths for both native and cross builds
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> "$GITHUB_ENV"
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> "$GITHUB_ENV"
# Intel cross-compilation requires extra flags
if [[ "${{ matrix.target }}" == "x86_64-apple-darwin" ]]; then
echo "Setup for cross-compiling to Intel x86_64 from Apple Silicon"
echo "ARCHFLAGS=-arch x86_64" >> "$GITHUB_ENV"
# Explicitly install x86_64 OpenSSL via homebrew for cross-compilation
echo "LDFLAGS=-L$OPENSSL_DIR/lib -L$(brew --prefix)/lib" >> "$GITHUB_ENV"
echo "CPPFLAGS=-I$OPENSSL_DIR/include" >> "$GITHUB_ENV"
# Link against both architectures if possible
echo "RUSTFLAGS=-C target-feature=+crt-static -L $OPENSSL_DIR/lib" >> "$GITHUB_ENV"
fi
- name: Install dependencies (Windows)
if: matrix.os == 'windows-latest'
run: |
vcpkg integrate install
vcpkg install openssl:x64-windows-static-md
- name: Install dependencies (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev pkg-config
- name: Report architecture
if: matrix.os == 'macos-latest'
run: |
echo "macOS runner architecture:"
uname -m
echo "Target architecture: ${{ matrix.target }}"
- name: Build
timeout-minutes: 30 # Increase timeout for long builds
run: |
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then
echo "Current environment variables for debugging:"
env | sort
if [[ "${{ matrix.target }}" == "x86_64-apple-darwin" ]]; then
echo "Building for x86_64-apple-darwin (Intel) on Apple Silicon..."
# Try to find the libssl/libcrypto in the path
find $OPENSSL_DIR -name "libssl.*" || echo "libssl not found"
find $OPENSSL_DIR -name "libcrypto.*" || echo "libcrypto not found"
# Cross-compile with explicit linking to OpenSSL
# Use nightly for the advanced features
rustup run nightly cargo build --release --target ${{ matrix.target }} \
--verbose \
-Z build-std=panic_abort,std \
-Z build-std-features=panic_immediate_abort
else
# Native ARM64 build
echo "Building for aarch64-apple-darwin (ARM64) natively..."
cargo build --release --target ${{ matrix.target }}
fi
else
# Standard build for other platforms
cargo build --release --target ${{ matrix.target }}
fi
- name: Prepare artifact
shell: bash
run: |
mkdir -p dist
# List build artifacts to debug
ls -la target/${{ matrix.target }}/release/ || echo "Release directory not found"
if [ "${{ matrix.os }}" = "windows-latest" ]; then
cp "target/${{ matrix.target }}/release/${{ matrix.artifact_name }}" "dist/${{ matrix.asset_name }}" || echo "Failed to copy Windows artifact"
else
cp "target/${{ matrix.target }}/release/${{ matrix.artifact_name }}" "dist/${{ matrix.asset_name }}" || echo "Failed to copy Unix artifact"
chmod +x "dist/${{ matrix.asset_name }}" || echo "Failed to make executable"
fi
# List the dist directory to confirm copy worked
ls -la dist/ || echo "Dist directory empty or not found"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: dist/${{ matrix.asset_name }}
if-no-files-found: error
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: dist
- name: Get version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
- name: Get tag type
id: get_tag_type
run: |
TAG="${{ steps.get_version.outputs.VERSION }}"
if [[ "$TAG" == *-alpha ]]; then
echo "TAG_TYPE=alpha" >> "$GITHUB_OUTPUT"
elif [[ "$TAG" == *-beta ]]; then
echo "TAG_TYPE=beta" >> "$GITHUB_OUTPUT"
elif [[ "$TAG" == *-test ]]; then
echo "TAG_TYPE=test" >> "$GITHUB_OUTPUT"
else
echo "TAG_TYPE=release" >> "$GITHUB_OUTPUT"
fi
- name: Get previous tag
id: get_previous_tag
run: |
TAG="${{ steps.get_version.outputs.VERSION }}"
TAG_TYPE="${{ steps.get_tag_type.outputs.TAG_TYPE }}"
if [[ "$TAG_TYPE" == "alpha" ]]; then
PREV_TAG=$(git tag --sort=-version:refname | grep -E '.*-alpha$' | grep -v "$TAG" | head -n 1)
elif [[ "$TAG_TYPE" == "beta" ]]; then
PREV_TAG=$(git tag --sort=-version:refname | grep -E '.*-beta$' | grep -v "$TAG" | head -n 1)
elif [[ "$TAG_TYPE" == "test" ]]; then
PREV_TAG=$(git tag --sort=-version:refname | grep -E '.*-test$' | grep -v "$TAG" | head -n 1)
else
PREV_TAG=$(git tag --sort=-version:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | grep -v "$TAG" | head -n 1)
fi
echo "PREVIOUS_TAG=$PREV_TAG" >> "$GITHUB_OUTPUT"
- name: Generate changelog
id: changelog
run: |
PREV_TAG="${{ steps.get_previous_tag.outputs.PREVIOUS_TAG }}"
VERSION="${{ steps.get_version.outputs.VERSION }}"
{
echo "CHANGELOG<<EOF"
if [ -z "$PREV_TAG" ]; then
# If no previous tag exists, use all commits
git log --pretty=format:"- %s"
else
# Generate changelog between tags
git log --pretty=format:"- %s" "${PREV_TAG}..${VERSION}"
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create release
id: create_release
uses: softprops/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ steps.get_version.outputs.VERSION }}
name: Release ${{ steps.get_version.outputs.VERSION }}
draft: false
prerelease: ${{ steps.get_tag_type.outputs.TAG_TYPE != 'release' }}
body: |
# Changes since ${{ steps.get_previous_tag.outputs.PREVIOUS_TAG }}
${{ steps.changelog.outputs.CHANGELOG }}
files: |
dist/**/*
# Generate cargo-binstall metadata
binstall:
name: Generate cargo-binstall metadata
needs: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
- name: Generate cargo-binstall metadata
run: |
cat > binstall.json << EOF
{
"package_id": "omr-bumper",
"version": "${{ steps.get_version.outputs.VERSION }}",
"artifacts": {
"x86_64-unknown-linux-gnu": {
"kind": "executable",
"url": "https://github.com/${{ github.repository }}/releases/download/${{ steps.get_version.outputs.VERSION }}/omr-bumper-linux-x86_64",
"name": "omr-bumper"
},
"x86_64-pc-windows-msvc": {
"kind": "executable",
"url": "https://github.com/${{ github.repository }}/releases/download/${{ steps.get_version.outputs.VERSION }}/omr-bumper-windows-x86_64.exe",
"name": "omr-bumper.exe"
},
"x86_64-apple-darwin": {
"kind": "executable",
"url": "https://github.com/${{ github.repository }}/releases/download/${{ steps.get_version.outputs.VERSION }}/omr-bumper-macos-x86_64",
"name": "omr-bumper"
},
"aarch64-apple-darwin": {
"kind": "executable",
"url": "https://github.com/${{ github.repository }}/releases/download/${{ steps.get_version.outputs.VERSION }}/omr-bumper-macos-aarch64",
"name": "omr-bumper"
}
}
}
EOF
- name: Upload binstall.json
uses: softprops/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ steps.get_version.outputs.VERSION }}
files: binstall.json