init
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
workflow_dispatch: # 只允许手动触发
|
||||
inputs:
|
||||
version:
|
||||
description: '版本号(例如:v1.0.0)'
|
||||
required: true
|
||||
default: 'v1.0.0'
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
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
|
||||
|
||||
# Linux x86_64 (MUSL - 静态链接,无依赖)
|
||||
- target: x86_64-unknown-linux-musl
|
||||
os: ubuntu-latest
|
||||
use_cross: true
|
||||
platform: linux
|
||||
|
||||
# Linux ARM64
|
||||
- target: aarch64-unknown-linux-gnu
|
||||
os: ubuntu-latest
|
||||
use_cross: true
|
||||
platform: linux
|
||||
|
||||
# Windows x86_64
|
||||
- target: x86_64-pc-windows-msvc
|
||||
os: windows-latest
|
||||
use_cross: false
|
||||
platform: windows
|
||||
|
||||
# macOS x86_64
|
||||
- target: x86_64-apple-darwin
|
||||
os: macos-latest
|
||||
use_cross: false
|
||||
platform: macos
|
||||
|
||||
# macOS ARM64 (Apple Silicon)
|
||||
- target: aarch64-apple-darwin
|
||||
os: macos-latest
|
||||
use_cross: false
|
||||
platform: macos
|
||||
|
||||
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') }}
|
||||
|
||||
- name: Cache target directory
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: target
|
||||
key: ${{ runner.os }}-${{ matrix.target }}-cargo-target-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
if [ "${{ matrix.use_cross }}" = "true" ]; then
|
||||
cross build --release --target ${{ matrix.target }}
|
||||
else
|
||||
cargo build --release --target ${{ matrix.target }}
|
||||
fi
|
||||
shell: bash
|
||||
|
||||
- name: Get version
|
||||
id: get_version
|
||||
run: |
|
||||
# 使用用户输入的版本号
|
||||
VERSION="${{ github.event.inputs.version }}"
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
|
||||
- name: Prepare artifacts (Unix)
|
||||
if: runner.os != 'Windows'
|
||||
run: |
|
||||
cd target/${{ matrix.target }}/release
|
||||
tar czf dht_crawler-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.tar.gz dht_crawler
|
||||
mv dht_crawler-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.tar.gz ${{ github.workspace }}/
|
||||
shell: bash
|
||||
|
||||
- name: Prepare artifacts (Windows)
|
||||
if: runner.os == 'Windows'
|
||||
run: |
|
||||
cd target/${{ matrix.target }}/release
|
||||
7z a dht_crawler-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.zip dht_crawler.exe
|
||||
Move-Item dht_crawler-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.zip ${{ github.workspace }}/
|
||||
shell: pwsh
|
||||
|
||||
- name: Upload Release Assets
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
tag_name: ${{ github.event.inputs.version }}
|
||||
files: |
|
||||
dht_crawler-${{ steps.get_version.outputs.version }}-${{ matrix.target }}.*
|
||||
Reference in New Issue
Block a user