这是indexloc提供的服务,不要输入任何密码
Skip to content

Release

Release #22

Workflow file for this run

# .github/workflows/release.yml
name: Release
on:
push:
tags:
- '*' # Trigger on any tag push
defaults:
run:
shell: bash
env:
# Global RUSTFLAGS (applied unless overridden in a step)
RUSTFLAGS: --deny warnings
# Project name used in the justfile for artifact naming
PROJECT_NAME: lichen
jobs:
prerelease:
# This job determines if the tag is a pre-release based on its format.
# It remains unchanged as it controls the GitHub Release 'prerelease' flag.
runs-on: ubuntu-latest
outputs:
value: ${{ steps.prerelease.outputs.value }}
steps:
- name: Prerelease Check
id: prerelease
run: |
if [[ ${{ github.ref_name }} =~ ^[0-9]+[.][0-9]+[.][0-9]+$ ]]; then
echo "value=false" >> $GITHUB_OUTPUT
else
echo "value=true" >> $GITHUB_OUTPUT
fi
package:
# This job builds and packages the project for various targets using the justfile.
strategy:
fail-fast: false # Don't cancel other jobs if one fails
matrix:
target:
- aarch64-apple-darwin
- aarch64-unknown-linux-musl
- arm-unknown-linux-musleabihf
- armv7-unknown-linux-musleabihf
- x86_64-apple-darwin
- x86_64-pc-windows-msvc
- aarch64-pc-windows-msvc
- x86_64-unknown-linux-musl
include:
# Define OS and specific RUSTFLAGS for cross-compilation targets
- target: aarch64-apple-darwin
os: macos-latest
target_rustflags: ''
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
target_rustflags: '--codegen linker=aarch64-linux-gnu-gcc'
- target: arm-unknown-linux-musleabihf
os: ubuntu-latest
target_rustflags: '--codegen linker=arm-linux-gnueabihf-gcc'
- target: armv7-unknown-linux-musleabihf
os: ubuntu-latest
target_rustflags: '--codegen linker=arm-linux-gnueabihf-gcc'
- target: x86_64-apple-darwin
os: macos-latest
target_rustflags: ''
- target: x86_64-pc-windows-msvc
os: windows-latest
target_rustflags: '' # No extra flags needed usually
- target: aarch64-pc-windows-msvc
os: windows-latest
target_rustflags: '' # Needs target added via rustup
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
target_rustflags: '' # MUSL target often needs static linking setup
runs-on: ${{ matrix.os }}
needs:
- prerelease # Wait for prerelease check
environment:
name: main
steps:
- name: Checkout code
uses: actions/checkout@v4
# Cache the Cargo registry/index, registry/cache and git DB
- name: Cache Cargo registry and git
uses: actions/cache@v3
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Set up Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
# Ensure the specific Rust target for the matrix job is installed
target: ${{ matrix.target }}
- name: Install Just (Command Runner)
run: |
set -euxo pipefail
# Using || true to prevent failure if package isn't found to catch on fallback
# Try installing via native package manager first
if [[ "$RUNNER_OS" == "Linux" ]]; then
echo "Attempting to install just via apt..."
sudo apt-get update -y
sudo apt-get install -y just || echo "apt install failed or package not found."
elif [[ "$RUNNER_OS" == "macOS" ]]; then
echo "Attempting to install just via Homebrew..."
brew install just || echo "brew install failed."
elif [[ "$RUNNER_OS" == "Windows" ]]; then
echo "Attempting to install just via Chocolatey..."
choco install just --yes || echo "choco install failed."
else
echo "Unsupported OS for package manager installation: $RUNNER_OS."
fi
# Fallback to cargo install if 'just' command is not found after package manager attempt
if ! command -v just &>/dev/null; then
echo "Just not found after package manager attempt. Installing via cargo install..."
cargo install just
else
echo "Just installed successfully via package manager or was already present."
fi
# --- Toolchain Installation (Keep these conditional steps) ---
- name: Install AArch64 Linux Toolchain (Ubuntu)
if: matrix.target == 'aarch64-unknown-linux-musl'
run: |
sudo apt-get update -y
sudo apt-get install -y gcc-aarch64-linux-gnu libc6-dev-arm64-cross
- name: Install ARM Linux Toolchain (Ubuntu)
if: matrix.target == 'arm-unknown-linux-musleabihf' || matrix.target == 'armv7-unknown-linux-musleabihf'
run: |
sudo apt-get update -y
sudo apt-get install -y gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
# No specific apt install needed for Windows MSVC targets,
# but ensure the target is added via rustup (done by setup-rust-toolchain)
# --- Build using Just ---
- name: Build the release version
# Set RUSTFLAGS combining global and target-specific flags for cargo inside just
env:
RUSTFLAGS: ${{ env.RUSTFLAGS }} ${{ matrix.target_rustflags }}
# Run the just recipe, passing the target from the matrix
run: just build-release ${{ matrix.target }}
- name: Compress the binaries
run: just compress-binaries "dist/"
# --- Publish Artifact ---
- name: Determine Artifact Name
id: artifact_name
run: |
ARTIFACT_PATH="dist/${{ env.PROJECT_NAME }}-${{ matrix.target }}"
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
ARTIFACT_PATH="${ARTIFACT_PATH}.exe"
fi
# Use the compressed versions
echo "path=${ARTIFACT_PATH}.tar.gz" >> $GITHUB_OUTPUT
- name: Extract changelog for the tag
id: extract_changelog
run: just create-notes ${{ github.ref_name }} release_notes.md CHANGELOG.md
- name: Publish Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: ${{ steps.artifact_name.outputs.path }}
body_path: release_notes.md
draft: false
prerelease: ${{ needs.prerelease.outputs.value }}
token: ${{ secrets.PAT }}
checksum:
# This job downloads all published artifacts and creates a checksum file.
runs-on: ubuntu-latest
needs:
- package # Wait for all package jobs to potentially complete
- prerelease
# Only run for tag pushes
if: startsWith(github.ref, 'refs/tags/')
environment:
name: main
steps:
- name: Install GitHub CLI
run: sudo apt-get update && sudo apt-get install -y gh
- name: Download Release Archives
env:
# Use PAT for gh CLI authentication
GH_TOKEN: ${{ secrets.PAT }}
# Get the tag name from the ref
TAG_NAME: ${{ github.ref_name }}
run: |
gh release download "$TAG_NAME" \
--repo "$GITHUB_REPOSITORY" \
--pattern '*' \
--dir release
- name: Create Checksums
run: |
find release/ -type f \
! -name "checksums.sha256" \
! -name "README*" \
! -name "*.sha256" \
-print0 \
| while IFS= read -r -d '' file; do
sha256sum "$file" > "$file.sha256"
done
- name: Publish Individual Checksums
uses: softprops/action-gh-release@v2
with:
# Use a wildcard to upload all generated .sha256 files from the release dir
files: release/*.sha256
draft: false
prerelease: ${{ needs.prerelease.outputs.value }}
token: ${{ secrets.PAT }}