Files
dht/.github/workflows/release.yml
T

202 lines
7.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Release
on:
workflow_dispatch: # 只允许手动触发
inputs:
version:
description: '版本号(例如:v1.0.0'
required: true
default: 'v1.0.0'
env:
CARGO_TERM_COLOR: always
jobs:
# ──────────────────────────────────────────────────────────────────
# Java fat JAR(平台无关,只需构建一次)
# 运行方式:java -Djava.library.path=<so/dll 目录> -jar dht-crawler-jni-example-<ver>.jar
# ──────────────────────────────────────────────────────────────────
build-java-jar:
name: Build Java Example JAR
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
- name: Build fat JAR
working-directory: examples-jni
run: |
chmod +x gradlew 2>/dev/null || true
gradle shadowJar -PprojectVersion=${{ github.event.inputs.version }} --no-daemon
shell: bash
- name: Upload JAR to Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.event.inputs.version }}
files: examples-jni/build/libs/dht-crawler-jni-example-${{ github.event.inputs.version }}.jar
# ──────────────────────────────────────────────────────────────────
# 各平台 Rust 构建(example 可执行 + JNI so/dll/dylib
# ──────────────────────────────────────────────────────────────────
build-and-release:
name: Build and Release for ${{ matrix.target }}
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
# Linux x86_64 (GNU)
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
use_cross: false
platform: linux
jni_lib: libdht_crawler.so
# Linux x86_64 (MUSL - 静态链接,无依赖)
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
use_cross: true
platform: linux
jni_lib: libdht_crawler.so
# Linux ARM64
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
use_cross: true
platform: linux
jni_lib: libdht_crawler.so
# Windows x86_64 (GNU/MinGW,与 Linux/macOS 一致用 GNU 工具链,无需 VC++ 运行库)
- target: x86_64-pc-windows-gnu
os: ubuntu-latest
use_cross: true
platform: windows
jni_lib: dht_crawler.dll
# macOS x86_64
- target: x86_64-apple-darwin
os: macos-latest
use_cross: false
platform: macos
jni_lib: libdht_crawler.dylib
# macOS ARM64 (Apple Silicon)
- target: aarch64-apple-darwin
os: macos-latest
use_cross: false
platform: macos
jni_lib: libdht_crawler.dylib
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
if: matrix.use_cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
# release 构建不缓存 target 目录,避免占用 GitHub 缓存配额
- name: Run tests
run: |
if [ "${{ matrix.use_cross }}" = "true" ]; then
cross test --target ${{ matrix.target }} --verbose
else
cargo test --target ${{ matrix.target }} --verbose
fi
shell: bash
- name: Run tests with features
run: |
if [ "${{ matrix.use_cross }}" = "true" ]; then
cross test --target ${{ matrix.target }} --verbose --features metrics,mimalloc
else
cargo test --target ${{ matrix.target }} --verbose --features metrics,mimalloc
fi
shell: bash
- name: Build (lib cdylib + examples)
run: |
if [ "${{ matrix.use_cross }}" = "true" ]; then
cross build --release --target ${{ matrix.target }} --lib --examples --features mimalloc,metrics,jni
else
cargo build --release --target ${{ matrix.target }} --lib --examples --features mimalloc,metrics,jni
fi
shell: bash
- name: Get version
id: get_version
run: |
VERSION="${{ github.event.inputs.version }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
shell: bash
# ────────── example 产物打包 ──────────
- name: Prepare example artifacts (Linux/macOS)
if: "!contains(matrix.target, 'windows')"
run: |
cd target/${{ matrix.target }}/release/examples
tar czf dht_crawler_example-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.tar.gz dht_crawler_example
mv dht_crawler_example-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.tar.gz ${{ github.workspace }}/
shell: bash
- name: Prepare example artifacts (Windows GNU)
if: contains(matrix.target, 'windows')
run: |
cd target/${{ matrix.target }}/release/examples
zip dht_crawler_example-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.zip dht_crawler_example.exe
mv dht_crawler_example-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.zip ${{ github.workspace }}/
shell: bash
# ────────── JNI 动态库打包(仅含单个 so/dll/dylib,体积最小)──────────
- name: Prepare JNI artifacts
run: |
VERSION=${{ steps.get_version.outputs.version }}
TARGET=${{ matrix.target }}
LIB=${{ matrix.jni_lib }}
WORKDIR=$(mktemp -d)
cp target/${TARGET}/release/${LIB} ${WORKDIR}/
cd ${WORKDIR}
zip dht_crawler_jni-${VERSION}-${TARGET}.zip ${LIB}
mv dht_crawler_jni-${VERSION}-${TARGET}.zip ${{ github.workspace }}/
shell: bash
# ────────── 上传到 Release ──────────
- name: Upload Release Assets
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.event.inputs.version }}
files: |
dht_crawler_example-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.*
dht_crawler_jni-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.zip