|
| 1 | +name: Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-x86_64: |
| 13 | + name: Build (x86_64) |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Install base dependencies |
| 17 | + shell: bash |
| 18 | + run: | |
| 19 | + set -euo pipefail |
| 20 | + export DEBIAN_FRONTEND=noninteractive |
| 21 | + sudo apt-get update |
| 22 | + sudo apt-get install -y --no-install-recommends \ |
| 23 | + ca-certificates \ |
| 24 | + pkg-config \ |
| 25 | + libssl-dev \ |
| 26 | + build-essential \ |
| 27 | + git \ |
| 28 | + curl \ |
| 29 | + unzip |
| 30 | +
|
| 31 | + - name: Check out repository |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Set up Rust toolchain |
| 35 | + uses: dtolnay/rust-toolchain@stable |
| 36 | + |
| 37 | + - name: Add Rust target |
| 38 | + run: rustup target add x86_64-unknown-linux-gnu |
| 39 | + |
| 40 | + - name: Build binary |
| 41 | + run: cargo build --release --target x86_64-unknown-linux-gnu |
| 42 | + |
| 43 | + - name: Package release artifact |
| 44 | + id: package |
| 45 | + shell: bash |
| 46 | + run: | |
| 47 | + set -euo pipefail |
| 48 | + binary_path="target/x86_64-unknown-linux-gnu/release/echokit_server" |
| 49 | + if [ ! -f "$binary_path" ]; then |
| 50 | + echo "Release binary not found at $binary_path" >&2 |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | +
|
| 54 | + archive_name="echokit_server-${{ github.ref_name }}-x86_64-unknown-linux-gnu.tar.gz" |
| 55 | + mkdir -p dist |
| 56 | + cp "$binary_path" dist/echokit_server |
| 57 | + chmod +x dist/echokit_server |
| 58 | + tar -C dist -czf "$archive_name" echokit_server |
| 59 | + rm dist/echokit_server |
| 60 | +
|
| 61 | + echo "archive=$archive_name" >> "$GITHUB_OUTPUT" |
| 62 | +
|
| 63 | + - name: Upload artifact |
| 64 | + uses: actions/upload-artifact@v4 |
| 65 | + with: |
| 66 | + name: echokit_server-x86_64-unknown-linux-gnu |
| 67 | + path: ${{ steps.package.outputs.archive }} |
| 68 | + |
| 69 | + build-aarch64: |
| 70 | + name: Build (aarch64) |
| 71 | + runs-on: ubuntu-latest |
| 72 | + container: |
| 73 | + image: debian:bookworm-slim |
| 74 | + steps: |
| 75 | + - name: Install base dependencies |
| 76 | + shell: bash |
| 77 | + run: | |
| 78 | + set -euo pipefail |
| 79 | + export DEBIAN_FRONTEND=noninteractive |
| 80 | + dpkg --add-architecture arm64 |
| 81 | + apt-get update |
| 82 | + apt-get install -y --no-install-recommends \ |
| 83 | + ca-certificates \ |
| 84 | + pkg-config \ |
| 85 | + libssl-dev \ |
| 86 | + libssl-dev:arm64 \ |
| 87 | + gcc-aarch64-linux-gnu \ |
| 88 | + libc6-dev-arm64-cross \ |
| 89 | + build-essential \ |
| 90 | + git \ |
| 91 | + curl \ |
| 92 | + unzip |
| 93 | +
|
| 94 | + - name: Check out repository |
| 95 | + uses: actions/checkout@v4 |
| 96 | + |
| 97 | + - name: Set up Rust toolchain |
| 98 | + uses: dtolnay/rust-toolchain@stable |
| 99 | + |
| 100 | + - name: Add Rust target |
| 101 | + run: rustup target add aarch64-unknown-linux-gnu |
| 102 | + |
| 103 | + - name: Build binary |
| 104 | + env: |
| 105 | + CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc |
| 106 | + AR_aarch64_unknown_linux_gnu: aarch64-linux-gnu-ar |
| 107 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc |
| 108 | + PKG_CONFIG_ALLOW_CROSS: "1" |
| 109 | + PKG_CONFIG_PATH: /usr/lib/aarch64-linux-gnu/pkgconfig |
| 110 | + run: cargo build --release --target aarch64-unknown-linux-gnu |
| 111 | + |
| 112 | + - name: Package release artifact |
| 113 | + id: package |
| 114 | + shell: bash |
| 115 | + run: | |
| 116 | + set -euo pipefail |
| 117 | + binary_path="target/aarch64-unknown-linux-gnu/release/echokit_server" |
| 118 | + if [ ! -f "$binary_path" ]; then |
| 119 | + echo "Release binary not found at $binary_path" >&2 |
| 120 | + exit 1 |
| 121 | + fi |
| 122 | +
|
| 123 | + archive_name="echokit_server-${{ github.ref_name }}-aarch64-unknown-linux-gnu.tar.gz" |
| 124 | + mkdir -p dist |
| 125 | + cp "$binary_path" dist/echokit_server |
| 126 | + chmod +x dist/echokit_server |
| 127 | + tar -C dist -czf "$archive_name" echokit_server |
| 128 | + rm dist/echokit_server |
| 129 | +
|
| 130 | + echo "archive=$archive_name" >> "$GITHUB_OUTPUT" |
| 131 | +
|
| 132 | + - name: Upload artifact |
| 133 | + uses: actions/upload-artifact@v4 |
| 134 | + with: |
| 135 | + name: echokit_server-aarch64-unknown-linux-gnu |
| 136 | + path: ${{ steps.package.outputs.archive }} |
| 137 | + |
| 138 | + release: |
| 139 | + name: Publish release |
| 140 | + runs-on: ubuntu-latest |
| 141 | + needs: |
| 142 | + - build-x86_64 |
| 143 | + - build-aarch64 |
| 144 | + steps: |
| 145 | + - name: Download artifacts |
| 146 | + uses: actions/download-artifact@v4 |
| 147 | + with: |
| 148 | + pattern: echokit_server-* |
| 149 | + path: artifacts |
| 150 | + merge-multiple: true |
| 151 | + |
| 152 | + - name: Prepare release files |
| 153 | + id: prepare |
| 154 | + shell: bash |
| 155 | + run: | |
| 156 | + set -euo pipefail |
| 157 | + mapfile -t archives < <(find artifacts -name '*.tar.gz' -type f) |
| 158 | + if [ "${#archives[@]}" -eq 0 ]; then |
| 159 | + echo "No release archives found" >&2 |
| 160 | + exit 1 |
| 161 | + fi |
| 162 | + { |
| 163 | + echo "files<<EOF" |
| 164 | + for archive in "${archives[@]}"; do |
| 165 | + echo "$archive" |
| 166 | + done |
| 167 | + echo "EOF" |
| 168 | + } >> "$GITHUB_OUTPUT" |
| 169 | +
|
| 170 | + - name: Publish GitHub release |
| 171 | + uses: softprops/action-gh-release@v1 |
| 172 | + with: |
| 173 | + tag_name: ${{ github.ref_name }} |
| 174 | + name: Echokit Server ${{ github.ref_name }} |
| 175 | + files: ${{ steps.prepare.outputs.files }} |
| 176 | + env: |
| 177 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments