Skip to content

new features and improvements #50

new features and improvements

new features and improvements #50

Workflow file for this run

name: Release
on:
pull_request_target:
types: [closed]
branches: [main]
workflow_dispatch:
jobs:
check_release:
if: |
(github.event_name == 'workflow_dispatch' && github.actor == 'triyanox') ||
(github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release'))
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
should_release: ${{ steps.check_version.outputs.should_release }}
current_version: ${{ steps.check_version.outputs.current_version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check version changes
id: check_version
run: |
# Get the latest release version
OLD_VERSION=$(gh release view --json tagName --jq '.tagName' | sed 's/^v//' || echo "0.0.0")
# Get the current version from Cargo.toml
CURRENT_VERSION=$(sed -n '/^\[workspace\.package\]/,/^\[/p' Cargo.toml | grep '^version = ' | cut -d '"' -f 2)
echo "Old version: $OLD_VERSION"
echo "Current version: $CURRENT_VERSION"
if [ "$OLD_VERSION" != "$CURRENT_VERSION" ]; then
echo "Version changed from $OLD_VERSION to $CURRENT_VERSION"
echo "should_release=true" >> "$GITHUB_OUTPUT"
echo "current_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
else
echo "Version unchanged"
echo "should_release=false" >> "$GITHUB_OUTPUT"
echo "current_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build:
needs: check_release
if: needs.check_release.outputs.should_release == 'true'
name: Build Release Binaries
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
# Linux builds
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: lla-linux-amd64
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
artifact_name: lla-linux-arm64
cross_compile: true
- os: ubuntu-latest
target: i686-unknown-linux-gnu
artifact_name: lla-linux-i686
cross_compile: true
# macOS builds
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: lla-macos-amd64
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: lla-macos-arm64
steps:
- uses: actions/checkout@v4
- name: Setup Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.71.0
targets: ${{ matrix.target }}
- name: Install cross-compilation tools
if: matrix.cross_compile && runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu gcc-i686-linux-gnu
sudo apt-get install -y crossbuild-essential-arm64 crossbuild-essential-i386
- name: Set cross-compilation environment
if: matrix.cross_compile && runner.os == 'Linux'
run: |
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CARGO_TARGET_I686_UNKNOWN_LINUX_GNU_LINKER=i686-linux-gnu-gcc" >> $GITHUB_ENV
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build release
run: cargo build --release --target ${{ matrix.target }}
- name: Prepare binary
run: |
cp target/${{ matrix.target }}/release/lla ${{ matrix.artifact_name }}
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.artifact_name }}
path: ${{ matrix.artifact_name }}
publish:
needs: [check_release, build]
if: needs.check_release.outputs.should_release == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Setup Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.71.0
- name: Rust Cache
uses: Swatinem/rust-cache@v2
- name: Update dependency version
run: |
VERSION="${{ needs.check_release.outputs.current_version }}"
# Update the version in lla/Cargo.toml
sed -i 's/version = "[0-9]*\.[0-9]*\.[0-9]*"/version = "'$VERSION'"/' lla/Cargo.toml
- name: Check and publish to crates.io
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: |
cargo login ${{ secrets.CRATES_IO_TOKEN }}
# Get current version without 'v' prefix
VERSION="${{ needs.check_release.outputs.current_version }}"
# Check if lla_plugin_interface version exists (using awk to get just the version)
PUBLISHED_VERSION=$(cargo search lla_plugin_interface --limit 1 | awk -F '"' '{print $2}')
if [ "$PUBLISHED_VERSION" != "$VERSION" ]; then
echo "Publishing lla_plugin_interface v$VERSION"
cargo publish -p lla_plugin_interface
# Wait for crates.io indexing
sleep 30
else
echo "lla_plugin_interface v$VERSION already published, skipping..."
fi
# Check and publish lla_plugin_utils
PUBLISHED_VERSION=$(cargo search lla_plugin_utils --limit 1 | awk -F '"' '{print $2}')
if [ "$PUBLISHED_VERSION" != "$VERSION" ]; then
echo "Publishing lla_plugin_utils v$VERSION"
cargo publish -p lla_plugin_utils
# Wait for crates.io indexing
sleep 30
else
echo "lla_plugin_utils v$VERSION already published, skipping..."
fi
echo "Publishing lla v$VERSION"
cargo publish -p lla
create_release:
needs: [check_release, build, publish]
if: needs.check_release.outputs.should_release == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Generate SHA256 checksums
run: |
cd artifacts
for artifact in */*; do
sha256sum "$artifact" >> ../SHA256SUMS
done
cd ..
- name: Create Release Notes
run: |
{
echo "# Release v${{ needs.check_release.outputs.current_version }}"
echo
if [ -f CHANGELOG.md ]; then
echo "## Changelog"
echo
sed -n "/## \[${{ needs.check_release.outputs.current_version }}\]/,/## \[/p" CHANGELOG.md | sed '$d'
echo
fi
echo "## SHA256 Checksums"
echo "\`\`\`"
cat SHA256SUMS
echo "\`\`\`"
} > RELEASE_NOTES.md
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.check_release.outputs.current_version }}
release_name: Release v${{ needs.check_release.outputs.current_version }}
body_path: RELEASE_NOTES.md
draft: false
prerelease: false
- name: Upload Release Assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Upload binaries
for asset in artifacts/*/*; do
filename=$(basename "$asset")
echo "Uploading $filename..."
gh release upload "v${{ needs.check_release.outputs.current_version }}" "$asset" --clobber
done
# Upload checksums
gh release upload "v${{ needs.check_release.outputs.current_version }}" SHA256SUMS --clobber