Skip to content

fix:updated version of workflow #43

fix:updated version of workflow

fix:updated version of workflow #43

Workflow file for this run

name: build
on:
push:
branches:
- main
- workflow/*
tags:
- v*
pull_request:
branches:
- main
permissions:
contents: write
jobs:
build-rust:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest] # 定义操作系统矩阵
arch: [x86_64, aarch64] # 定义架构矩阵
runs-on: ${{ matrix.platform }} # 定义作业运行的操作系统
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Install Rust
run: rustup toolchain install stable --component llvm-tools-preview
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: install nextest
uses: taiki-e/install-action@nextest
- uses: Swatinem/rust-cache@v2
- name: Check code format
run: cargo fmt -- --check
- name: Check the package for errors
run: cargo check --all
- name: Lint rust sources
run: cargo clippy --all-targets --all-features --tests --benches -- -D warnings
- name: Execute rust tests
run: cargo nextest run --all-features
- name: Build project
run: cargo build --release # 构建项目的发布版本
# 上传Linux x86_64平台的构建产物
- name: Upload artifact (Linux)
if: matrix.platform == 'ubuntu-latest' && matrix.arch == 'x86_64'
uses: actions/upload-artifact@v4
with:
name: ubuntu-latest-rust-cli
path: target/release/rust-cli
# 上传Linux aarch64平台的构建产物
- name: Upload artifact (Linux arch64)
if: matrix.platform == 'ubuntu-latest' && matrix.arch == 'aarch64'
uses: actions/upload-artifact@v4
with:
name: ubuntu-latest-rust-cli-aarch64
path: target/release/rust-cli
# 上传macOS x86_64平台的构建产物
- name: Upload artifact (macOS)
if: matrix.platform == 'macos-latest' && matrix.arch == 'x86_64'
uses: actions/upload-artifact@v4
with:
name: macos-latest-rust-cli
path: target/release/rust-cli
# 上传macOS aarch64平台的构建产物
- name: Upload artifact (macOS aarch64)
if: matrix.platform == 'macos-latest' && matrix.arch == 'aarch64'
uses: actions/upload-artifact@v4
with:
name: macos-latest-rust-cli-aarch64
path: target/release/rust-cli
# 上传Windows x86_64平台的构建产物
- name: Upload artifact (Windows)
if: matrix.platform == 'windows-latest' && matrix.arch == 'x86_64'
uses: actions/upload-artifact@v4
with:
name: windows-latest-rust-cli
path: target/release/rust-cli.exe
# 上传Windows aarch64平台的构建产物
- name: Upload artifact (Windows aarch64)
if: matrix.platform == 'windows-latest' && matrix.arch == 'aarch64'
uses: actions/upload-artifact@v4
with:
name: windows-latest-rust-cli-aarch64
path: target/release/rust-cli.exe
release:
runs-on: ubuntu-latest # 定义作业运行在Ubuntu系统上
needs: build-rust # 依赖于 build-rust作业
steps:
- name: Checkout code
uses: actions/checkout@v4 # 检出仓库代码
with:
fetch-depth: 0
# 下载Linux x86_64平台的构建产物
- name: Download artifact (Linux-x86_64)
uses: actions/download-artifact@v4
with:
name: ubuntu-latest-rust-cli
path: artifacts/ubuntu
# 下载macOS x86_64平台的构建产物
- name: Download artifact (macOS-x86_64)
uses: actions/download-artifact@v4
with:
name: macos-latest-rust-cli
path: artifacts/macos
# 下载Windows x86_64平台的构建产物
- name: Download artifact (Windows-x86_64)
uses: actions/download-artifact@v4
with:
name: windows-latest-rust-cli
path: artifacts/windows
# 下载Linux aarch64平台的构建产物
- name: Download artifact (Linux-aarch64)
uses: actions/download-artifact@v4
with:
name: ubuntu-latest-rust-cli-aarch64
path: artifacts/ubuntu
# 下载macOS aarch64平台的构建产物
- name: Download artifact (macOS-aarch64)
uses: actions/download-artifact@v4
with:
name: macos-latest-rust-cli-aarch64
path: artifacts/macos
# 下载Windows aarch64平台的构建产物
- name: Download artifact (Windows-aarch64)
uses: actions/download-artifact@v4
with:
name: windows-latest-rust-cli-aarch64
path: artifacts/windows
- name: Generate a changelog
uses: orhun/git-cliff-action@v4 # 生成changelog
id: git-cliff
if: startsWith(github.ref, 'refs/tags/')
with:
config: cliff.toml
args: -vv --latest --strip header
env:
OUTPUT: CHANGES.md
- name: Print the changelog
run: echo "${{ steps.git-cliff.outputs.changelog }}" # 打印changelog
- name: Create release
id: create_release
uses: softprops/action-gh-release@v2 # 创建GitHub release
if: startsWith(github.ref, 'refs/tags/') # 只在推送标签时创建发布
with:
body: ${{ steps.git-cliff.outputs.content }} # 使用生成的changelog作为发布内容
draft: true # 是否为草稿
prerelease: false # 是否为预发布
# 上传Linux x86_64平台的构建产物到发布页面
- name: Upload Linux x86_64 artifact
uses: actions/upload-release-asset@v1
if: startsWith(github.ref, 'refs/tags/') # 只在推送标签时上传构建产物
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} # 使用GitHub令牌进行身份验证
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # 使用创建发布步骤生成的上传URL
asset_path: artifacts/ubuntu/rust-cli # 上传的文件路径
asset_name: rust-cli-linux-x86_64 # 上传的文件名
asset_content_type: application/octet-stream # 文件内容类型
# 上传macOS x86_64平台的构建产物到发布页面
- name: Upload macOS x86_64 artifact
uses: actions/upload-release-asset@v1
if: startsWith(github.ref, 'refs/tags/') # 只在推送标签时上传构建产物
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} # 使用GitHub令牌进行身份验证
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # 使用创建发布步骤生成的上传URL
asset_path: artifacts/macos/rust-cli # 上传的文件路径
asset_name: rust-cli-macos-x86_64 # 上传的文件名
asset_content_type: application/octet-stream # 文件内容类型
# 上传Windows x86_64平台的构建产物到发布页面
- name: Upload Windows x86_64 artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} # 使用GitHub令牌进行身份验证
if: startsWith(github.ref, 'refs/tags/') # 只在推送标签时上传构建产物
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # 使用创建发布步骤生成的上传URL
asset_path: artifacts/windows/rust-cli.exe # 上传的文件路径
asset_name: rust-cli-windows-x86_64.exe # 上传的文件名
asset_content_type: application/octet-stream # 文件内容类型
# 上传Linux aarch64平台的构建产物到发布页面
- name: Upload Linux aarch64 artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} # 使用GitHub令牌进行身份验证
if: startsWith(github.ref, 'refs/tags/') # 只在推送标签时上传构建产物
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # 使用创建发布步骤生成的上传URL
asset_path: artifacts/ubuntu/rust-cli # 上传的文件路径
asset_name: rust-cli-linux-aarch64 # 上传的文件名
asset_content_type: application/octet-stream # 文件内容类型
# 上传macOS aarch64平台的构建产物到发布页面
- name: Upload macOS aarch64 artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} # 使用GitHub令牌进行身份验证
if: startsWith(github.ref, 'refs/tags/') # 只在推送标签时上传构建产物
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # 使用创建发布步骤生成的上传URL
asset_path: artifacts/macos/rust-cli # 上传的文件路径
asset_name: rust-cli-macos-aarch64 # 上传的文件名
asset_content_type: application/octet-stream # 文件内容类型
# 上传Windows aarch64平台的构建产物到发布页面
- name: Upload Windows aarch64 artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} # 使用GitHub令牌进行身份验证
if: startsWith(github.ref, 'refs/tags/') # 只在推送标签时上传构建产物
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # 使用创建发布步骤生成的上传URL
asset_path: artifacts/windows/rust-cli.exe # 上传的文件路径
asset_name: rust-cli-windows-aarch64.exe # 上传的文件名
asset_content_type: application/octet-stream # 文件内容类型