|
| 1 | +name: Release Binaries |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'elizacp-v*' |
| 7 | + - 'yopo-v*' |
| 8 | + - 'sacp-conductor-v*' |
| 9 | + - 'sacp-tee-v*' |
| 10 | + - 'sacp-trace-viewer-v*' |
| 11 | + |
| 12 | +env: |
| 13 | + CARGO_TERM_COLOR: always |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: Build ${{ matrix.binary }} for ${{ matrix.target }} |
| 18 | + runs-on: ${{ matrix.os }} |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + matrix: |
| 22 | + include: |
| 23 | + # x86_64 |
| 24 | + - target: x86_64-unknown-linux-gnu |
| 25 | + os: ubuntu-latest |
| 26 | + archive: tar.gz |
| 27 | + - target: x86_64-apple-darwin |
| 28 | + os: macos-latest |
| 29 | + archive: tar.gz |
| 30 | + - target: x86_64-pc-windows-msvc |
| 31 | + os: windows-latest |
| 32 | + archive: zip |
| 33 | + # aarch64 |
| 34 | + - target: aarch64-unknown-linux-gnu |
| 35 | + os: ubuntu-latest |
| 36 | + archive: tar.gz |
| 37 | + cross: true |
| 38 | + - target: aarch64-apple-darwin |
| 39 | + os: macos-latest |
| 40 | + archive: tar.gz |
| 41 | + - target: aarch64-pc-windows-msvc |
| 42 | + os: windows-latest |
| 43 | + archive: zip |
| 44 | + |
| 45 | + steps: |
| 46 | + - name: Checkout repository |
| 47 | + uses: actions/checkout@v5 |
| 48 | + |
| 49 | + - name: Extract binary name and version from tag |
| 50 | + id: extract |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + # Tag format: {binary}-v{version} |
| 54 | + TAG="${GITHUB_REF#refs/tags/}" |
| 55 | + BINARY="${TAG%-v*}" |
| 56 | + VERSION="${TAG#*-}" |
| 57 | + echo "tag=$TAG" >> $GITHUB_OUTPUT |
| 58 | + echo "binary=$BINARY" >> $GITHUB_OUTPUT |
| 59 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 60 | + echo "Extracted: binary=$BINARY, version=$VERSION" |
| 61 | +
|
| 62 | + - name: Install Rust toolchain |
| 63 | + uses: dtolnay/rust-toolchain@stable |
| 64 | + with: |
| 65 | + targets: ${{ matrix.target }} |
| 66 | + |
| 67 | + - name: Install cross-compilation tools (Linux aarch64) |
| 68 | + if: matrix.cross |
| 69 | + run: | |
| 70 | + sudo apt-get update |
| 71 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 72 | + echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV |
| 73 | +
|
| 74 | + - name: Build binary |
| 75 | + run: cargo build --release --package ${{ steps.extract.outputs.binary }} --target ${{ matrix.target }} |
| 76 | + |
| 77 | + - name: Package (Unix) |
| 78 | + if: matrix.archive == 'tar.gz' |
| 79 | + shell: bash |
| 80 | + run: | |
| 81 | + BINARY="${{ steps.extract.outputs.binary }}" |
| 82 | + VERSION="${{ steps.extract.outputs.version }}" |
| 83 | + TARGET="${{ matrix.target }}" |
| 84 | + ARCHIVE_NAME="${BINARY}-${TARGET}-${VERSION}.tar.gz" |
| 85 | +
|
| 86 | + cd target/$TARGET/release |
| 87 | + tar -czvf "../../../$ARCHIVE_NAME" "$BINARY" |
| 88 | + cd ../../.. |
| 89 | + echo "ARCHIVE_NAME=$ARCHIVE_NAME" >> $GITHUB_ENV |
| 90 | +
|
| 91 | + - name: Package (Windows) |
| 92 | + if: matrix.archive == 'zip' |
| 93 | + shell: pwsh |
| 94 | + run: | |
| 95 | + $BINARY = "${{ steps.extract.outputs.binary }}" |
| 96 | + $VERSION = "${{ steps.extract.outputs.version }}" |
| 97 | + $TARGET = "${{ matrix.target }}" |
| 98 | + $ARCHIVE_NAME = "${BINARY}-${TARGET}-${VERSION}.zip" |
| 99 | +
|
| 100 | + Compress-Archive -Path "target\$TARGET\release\$BINARY.exe" -DestinationPath $ARCHIVE_NAME |
| 101 | + echo "ARCHIVE_NAME=$ARCHIVE_NAME" >> $env:GITHUB_ENV |
| 102 | +
|
| 103 | + - name: Upload artifact |
| 104 | + uses: actions/upload-artifact@v4 |
| 105 | + with: |
| 106 | + name: ${{ steps.extract.outputs.binary }}-${{ matrix.target }} |
| 107 | + path: ${{ env.ARCHIVE_NAME }} |
| 108 | + retention-days: 1 |
| 109 | + |
| 110 | + release: |
| 111 | + name: Upload to Release |
| 112 | + needs: build |
| 113 | + runs-on: ubuntu-latest |
| 114 | + permissions: |
| 115 | + contents: write |
| 116 | + steps: |
| 117 | + - name: Download all artifacts |
| 118 | + uses: actions/download-artifact@v4 |
| 119 | + with: |
| 120 | + path: artifacts |
| 121 | + |
| 122 | + - name: Upload to GitHub Release |
| 123 | + uses: softprops/action-gh-release@v2 |
| 124 | + with: |
| 125 | + files: artifacts/**/* |
0 commit comments