Skip to content

更新 GitHub Actions 工作流,升级上传工件的版本 #9

更新 GitHub Actions 工作流,升级上传工件的版本

更新 GitHub Actions 工作流,升级上传工件的版本 #9

Workflow file for this run

name: Build and Test
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build-and-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: [stable, 1.70.0]
fail-fast: false
max-parallel: 2
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
components: rustfmt, clippy
- name: Rust Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-rust-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-rust-${{ matrix.rust }}-
${{ runner.os }}-rust-
- name: Check formatting
run: cargo fmt --all -- --check
continue-on-error: true
- name: Run clippy
run: cargo clippy -- -D warnings
continue-on-error: true
- name: Build project
run: cargo build --release
timeout-minutes: 20
if: always()
- name: Run tests
run: cargo test --release
timeout-minutes: 30
if: success()
- name: Create dist directory
run: mkdir -p dist
shell: bash
- name: Package binary
shell: bash
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
cp target/release/treegen.exe LICENSE README.md dist/
7z a "treegen-${RUNNER_OS}-${GITHUB_SHA}.zip" ./dist/*
else
cp target/release/treegen LICENSE README.md dist/
tar -czvf "treegen-${RUNNER_OS}-${GITHUB_SHA}.tar.gz" dist/
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
if: success()
with:
name: treegen-${{ runner.os }}-${{ github.sha }}
path: |
treegen-*.tar.gz
treegen-*.zip
retention-days: 5