Release #11
Workflow file for this run
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: Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' # 当推送以 v 开头的 tag 时触发,例如 v0.1.0 | |
| workflow_dispatch: # 允许手动触发 | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| build: | |
| name: Build ${{ matrix.target }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-22.04 | |
| artifact_name: piri-x86_64-unknown-linux-gnu | |
| strip: true | |
| - target: aarch64-unknown-linux-gnu | |
| os: ubuntu-22.04 | |
| artifact_name: piri-aarch64-unknown-linux-gnu | |
| strip: true | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Cache cargo registry | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| target/ | |
| key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo-${{ matrix.target }}- | |
| - name: Install cross-compilation dependencies | |
| if: matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y gcc-aarch64-linux-gnu | |
| sudo apt-get install -y libc6-dev-arm64-cross | |
| sudo apt-get install -y binutils-aarch64-linux-gnu | |
| - name: Set up cross-compilation | |
| if: matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: | | |
| echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV | |
| echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV | |
| echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV | |
| - name: Build release binary | |
| run: | | |
| cargo build --release --target ${{ matrix.target }} | |
| - name: Strip binary | |
| if: matrix.strip | |
| run: | | |
| if [ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]; then | |
| aarch64-linux-gnu-strip target/${{ matrix.target }}/release/piri | |
| else | |
| strip target/${{ matrix.target }}/release/piri | |
| fi | |
| - name: Create archive | |
| working-directory: ${{ github.workspace }} | |
| run: | | |
| BINARY_PATH="target/${{ matrix.target }}/release/piri" | |
| ARCHIVE_NAME="${{ matrix.artifact_name }}.tar.gz" | |
| # 检查二进制文件是否存在 | |
| if [ ! -f "$BINARY_PATH" ]; then | |
| echo "错误: 二进制文件不存在: $BINARY_PATH" | |
| ls -la "target/${{ matrix.target }}/release/" || true | |
| exit 1 | |
| fi | |
| # 创建归档(在项目根目录) | |
| tar czf "$ARCHIVE_NAME" -C "target/${{ matrix.target }}/release" piri | |
| # 验证归档是否创建成功 | |
| if [ ! -f "$ARCHIVE_NAME" ]; then | |
| echo "错误: 归档文件创建失败: $ARCHIVE_NAME" | |
| echo "当前工作目录: $(pwd)" | |
| echo "文件列表:" | |
| ls -la || true | |
| exit 1 | |
| fi | |
| # 显示归档信息 | |
| ls -lh "$ARCHIVE_NAME" | |
| echo "归档文件已创建: $ARCHIVE_NAME" | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.artifact_name }} | |
| path: ${{ matrix.artifact_name }}.tar.gz | |
| retention-days: 30 | |
| release: | |
| name: Create Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Get tag name | |
| id: tag | |
| run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Create checksums | |
| run: | | |
| cd artifacts | |
| find . -type f -name "*.tar.gz" | while read file; do | |
| sha256sum "$file" > "$file.sha256" | |
| done | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ steps.tag.outputs.TAG_NAME }} | |
| name: Release ${{ steps.tag.outputs.TAG_NAME }} | |
| files: | | |
| artifacts/**/*.tar.gz | |
| artifacts/**/*.sha256 | |
| generate_release_notes: true | |
| draft: false | |
| prerelease: ${{ contains(steps.tag.outputs.TAG_NAME, '-') }} | |