|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*.*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +env: |
| 12 | + CARGO_TERM_COLOR: always |
| 13 | + BINARY_NAME: loadgen-rs |
| 14 | + |
| 15 | +jobs: |
| 16 | + prepare: |
| 17 | + name: Prepare release |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + version: ${{ steps.version.outputs.version }} |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + - name: Extract version from Cargo.toml |
| 24 | + id: version |
| 25 | + run: | |
| 26 | + VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/') |
| 27 | + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" |
| 28 | + TAG_VERSION="${GITHUB_REF_NAME#v}" |
| 29 | + if [ "$VERSION" != "$TAG_VERSION" ]; then |
| 30 | + echo "::error::Tag version (${TAG_VERSION}) does not match Cargo.toml version (${VERSION})" |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | +
|
| 34 | + build: |
| 35 | + name: Build ${{ matrix.target }} |
| 36 | + needs: prepare |
| 37 | + runs-on: ${{ matrix.runner }} |
| 38 | + strategy: |
| 39 | + fail-fast: false |
| 40 | + matrix: |
| 41 | + include: |
| 42 | + - target: x86_64-unknown-linux-gnu |
| 43 | + runner: ubuntu-latest |
| 44 | + use_cross: false |
| 45 | + archive_ext: tar |
| 46 | + - target: x86_64-unknown-linux-musl |
| 47 | + runner: ubuntu-latest |
| 48 | + use_cross: false |
| 49 | + archive_ext: tar |
| 50 | + - target: aarch64-unknown-linux-musl |
| 51 | + runner: ubuntu-latest |
| 52 | + use_cross: true |
| 53 | + archive_ext: tar |
| 54 | + - target: x86_64-apple-darwin |
| 55 | + runner: macos-13 |
| 56 | + use_cross: false |
| 57 | + archive_ext: tar |
| 58 | + - target: aarch64-apple-darwin |
| 59 | + runner: macos-latest |
| 60 | + use_cross: false |
| 61 | + archive_ext: tar |
| 62 | + - target: x86_64-pc-windows-msvc |
| 63 | + runner: windows-latest |
| 64 | + use_cross: false |
| 65 | + archive_ext: zip |
| 66 | + |
| 67 | + env: |
| 68 | + VERSION: ${{ needs.prepare.outputs.version }} |
| 69 | + |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - name: Install musl-tools |
| 74 | + if: contains(matrix.target, 'musl') && !matrix.use_cross |
| 75 | + run: sudo apt-get update --yes && sudo apt-get install --yes musl-tools |
| 76 | + |
| 77 | + - name: Install Rust toolchain |
| 78 | + uses: dtolnay/rust-toolchain@stable |
| 79 | + with: |
| 80 | + targets: ${{ matrix.target }} |
| 81 | + |
| 82 | + - name: Install cross |
| 83 | + if: matrix.use_cross |
| 84 | + uses: taiki-e/install-action@v2 |
| 85 | + with: |
| 86 | + tool: cross |
| 87 | + |
| 88 | + - uses: Swatinem/rust-cache@v2 |
| 89 | + with: |
| 90 | + key: release-${{ matrix.target }} |
| 91 | + |
| 92 | + - name: Build release binary |
| 93 | + shell: bash |
| 94 | + run: | |
| 95 | + if [ "${{ matrix.use_cross }}" = "true" ]; then |
| 96 | + cross build --release --locked --package loadgen-rs --target ${{ matrix.target }} |
| 97 | + else |
| 98 | + cargo build --release --locked --package loadgen-rs --target ${{ matrix.target }} |
| 99 | + fi |
| 100 | +
|
| 101 | + - name: Determine binary path |
| 102 | + id: bin |
| 103 | + shell: bash |
| 104 | + run: | |
| 105 | + if [ "${{ matrix.archive_ext }}" = "zip" ]; then |
| 106 | + echo "path=target/${{ matrix.target }}/release/${BINARY_NAME}.exe" >> "$GITHUB_OUTPUT" |
| 107 | + else |
| 108 | + echo "path=target/${{ matrix.target }}/release/${BINARY_NAME}" >> "$GITHUB_OUTPUT" |
| 109 | + fi |
| 110 | +
|
| 111 | + - name: Create tar.gz and tar.xz archives |
| 112 | + if: matrix.archive_ext == 'tar' |
| 113 | + shell: bash |
| 114 | + run: | |
| 115 | + STAGING="${BINARY_NAME}-v${VERSION}-${{ matrix.target }}" |
| 116 | + mkdir -p "${STAGING}" |
| 117 | + cp "${{ steps.bin.outputs.path }}" "${STAGING}/" |
| 118 | + cp README.md "${STAGING}/" 2>/dev/null || true |
| 119 | + tar czf "${STAGING}.tar.gz" "${STAGING}" |
| 120 | + tar cJf "${STAGING}.tar.xz" "${STAGING}" |
| 121 | +
|
| 122 | + - name: Create zip archive |
| 123 | + if: matrix.archive_ext == 'zip' |
| 124 | + shell: pwsh |
| 125 | + run: | |
| 126 | + $STAGING = "${{ env.BINARY_NAME }}-v${{ env.VERSION }}-${{ matrix.target }}" |
| 127 | + New-Item -ItemType Directory -Path $STAGING |
| 128 | + Copy-Item "${{ steps.bin.outputs.path }}" $STAGING |
| 129 | + Copy-Item README.md $STAGING -ErrorAction SilentlyContinue |
| 130 | + Compress-Archive -Path $STAGING -DestinationPath "${STAGING}.zip" |
| 131 | +
|
| 132 | + - name: Upload artifacts |
| 133 | + uses: actions/upload-artifact@v4 |
| 134 | + with: |
| 135 | + name: ${{ env.BINARY_NAME }}-v${{ env.VERSION }}-${{ matrix.target }} |
| 136 | + path: | |
| 137 | + ${{ env.BINARY_NAME }}-v${{ env.VERSION }}-${{ matrix.target }}.tar.gz |
| 138 | + ${{ env.BINARY_NAME }}-v${{ env.VERSION }}-${{ matrix.target }}.tar.xz |
| 139 | + ${{ env.BINARY_NAME }}-v${{ env.VERSION }}-${{ matrix.target }}.zip |
| 140 | + if-no-files-found: ignore |
| 141 | + |
| 142 | + - name: Upload tar.gz to release |
| 143 | + if: matrix.archive_ext == 'tar' |
| 144 | + uses: svenstaro/upload-release-action@v2 |
| 145 | + with: |
| 146 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 147 | + file: ${{ env.BINARY_NAME }}-v${{ env.VERSION }}-${{ matrix.target }}.tar.gz |
| 148 | + tag: ${{ github.ref }} |
| 149 | + |
| 150 | + - name: Upload tar.xz to release |
| 151 | + if: matrix.archive_ext == 'tar' |
| 152 | + uses: svenstaro/upload-release-action@v2 |
| 153 | + with: |
| 154 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 155 | + file: ${{ env.BINARY_NAME }}-v${{ env.VERSION }}-${{ matrix.target }}.tar.xz |
| 156 | + tag: ${{ github.ref }} |
| 157 | + |
| 158 | + - name: Upload zip to release |
| 159 | + if: matrix.archive_ext == 'zip' |
| 160 | + uses: svenstaro/upload-release-action@v2 |
| 161 | + with: |
| 162 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 163 | + file: ${{ env.BINARY_NAME }}-v${{ env.VERSION }}-${{ matrix.target }}.zip |
| 164 | + tag: ${{ github.ref }} |
0 commit comments