更新 GitHub Actions 工作流,升级上传工件的版本 #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.80.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 }}-${{ matrix.rust }}-${{ github.sha }} | |
| path: | | |
| treegen-*.tar.gz | |
| treegen-*.zip | |
| retention-days: 5 |