|
| 1 | +name: Build Linux Debian Packages |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + marketing_version: |
| 7 | + description: Marketing version (ex: 3.0) |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + build_number: |
| 11 | + description: Build number (ex: 4) |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + server_commit: |
| 15 | + description: Server commit SHA (optional) |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + release_tag: |
| 19 | + description: Release tag (ex: v3.0+4) |
| 20 | + required: true |
| 21 | + type: string |
| 22 | + package_name: |
| 23 | + description: Debian package name |
| 24 | + required: true |
| 25 | + default: wired3 |
| 26 | + type: string |
| 27 | + maintainer: |
| 28 | + description: Debian maintainer field |
| 29 | + required: true |
| 30 | + default: Wired Team <team@example.com> |
| 31 | + type: string |
| 32 | + depends: |
| 33 | + description: Debian depends field |
| 34 | + required: true |
| 35 | + default: libc6 |
| 36 | + type: string |
| 37 | + service_enable: |
| 38 | + description: Install systemd unit (1/0) |
| 39 | + required: true |
| 40 | + default: "1" |
| 41 | + type: string |
| 42 | + debian_artifact_name: |
| 43 | + description: Final workflow artifact name |
| 44 | + required: false |
| 45 | + default: linux-deb-packages |
| 46 | + type: string |
| 47 | + |
| 48 | +jobs: |
| 49 | + build-amd64: |
| 50 | + name: Build deb amd64 |
| 51 | + runs-on: ubuntu-latest |
| 52 | + env: |
| 53 | + TARGET_ARCH: amd64 |
| 54 | + FILE_ARCH_TOKEN: x86-64 |
| 55 | + steps: |
| 56 | + - name: Checkout |
| 57 | + uses: actions/checkout@v4 |
| 58 | + with: |
| 59 | + fetch-depth: 0 |
| 60 | + |
| 61 | + - name: Checkout requested commit |
| 62 | + if: ${{ inputs.server_commit != '' }} |
| 63 | + run: git checkout "${{ inputs.server_commit }}" |
| 64 | + |
| 65 | + - name: Install build dependencies |
| 66 | + run: | |
| 67 | + set -euo pipefail |
| 68 | + sudo apt-get update |
| 69 | + sudo apt-get install -y --no-install-recommends \ |
| 70 | + file \ |
| 71 | + dpkg-dev \ |
| 72 | + liblz4-dev \ |
| 73 | + libsqlite3-dev \ |
| 74 | + libssl-dev \ |
| 75 | + zlib1g-dev |
| 76 | +
|
| 77 | + - name: Build and package |
| 78 | + run: | |
| 79 | + set -euo pipefail |
| 80 | +
|
| 81 | + swift build -c release --product wired3 |
| 82 | + BIN_DIR="$(swift build -c release --show-bin-path)" |
| 83 | + BIN_PATH="$BIN_DIR/wired3" |
| 84 | + DEB_NAME="${{ inputs.package_name }}_${{ inputs.marketing_version }}+${{ inputs.build_number }}_${TARGET_ARCH}.deb" |
| 85 | + STAGE_DIR="$RUNNER_TEMP/deb-stage-$TARGET_ARCH" |
| 86 | + OUT_DIR="$RUNNER_TEMP/out-$TARGET_ARCH" |
| 87 | + VERIFY_DIR="$RUNNER_TEMP/verify-$TARGET_ARCH" |
| 88 | + OUT_DEB="$OUT_DIR/$DEB_NAME" |
| 89 | +
|
| 90 | + file "$BIN_PATH" |
| 91 | + file "$BIN_PATH" | grep -q "$FILE_ARCH_TOKEN" |
| 92 | + ldd "$BIN_PATH" || true |
| 93 | +
|
| 94 | + rm -rf "$STAGE_DIR" "$OUT_DIR" "$VERIFY_DIR" |
| 95 | + mkdir -p "$STAGE_DIR/DEBIAN" "$STAGE_DIR/usr/local/bin" "$OUT_DIR" "$VERIFY_DIR" |
| 96 | +
|
| 97 | + cp "$BIN_PATH" "$STAGE_DIR/usr/local/bin/wired3" |
| 98 | + chmod 0755 "$STAGE_DIR/usr/local/bin/wired3" |
| 99 | +
|
| 100 | + sed \ |
| 101 | + -e "s|__PACKAGE_NAME__|${{ inputs.package_name }}|g" \ |
| 102 | + -e "s|__VERSION__|${{ inputs.marketing_version }}+${{ inputs.build_number }}|g" \ |
| 103 | + -e "s|__ARCH__|$TARGET_ARCH|g" \ |
| 104 | + -e "s|__MAINTAINER__|${{ inputs.maintainer }}|g" \ |
| 105 | + -e "s|__DEPENDS__|${{ inputs.depends }}|g" \ |
| 106 | + Scripts/debian/control.template > "$STAGE_DIR/DEBIAN/control" |
| 107 | +
|
| 108 | + cp Scripts/debian/postinst "$STAGE_DIR/DEBIAN/postinst" |
| 109 | + cp Scripts/debian/prerm "$STAGE_DIR/DEBIAN/prerm" |
| 110 | + chmod 0755 "$STAGE_DIR/DEBIAN/postinst" "$STAGE_DIR/DEBIAN/prerm" |
| 111 | +
|
| 112 | + if [[ "${{ inputs.service_enable }}" == "1" ]]; then |
| 113 | + mkdir -p "$STAGE_DIR/lib/systemd/system" |
| 114 | + cp Scripts/debian/wired3.service "$STAGE_DIR/lib/systemd/system/wired3.service" |
| 115 | + fi |
| 116 | +
|
| 117 | + dpkg-deb --build --root-owner-group "$STAGE_DIR" "$OUT_DEB" |
| 118 | + dpkg-deb -x "$OUT_DEB" "$VERIFY_DIR" |
| 119 | + file "$VERIFY_DIR/usr/local/bin/wired3" |
| 120 | + file "$VERIFY_DIR/usr/local/bin/wired3" | grep -q "$FILE_ARCH_TOKEN" |
| 121 | +
|
| 122 | + - name: Upload arch artifact |
| 123 | + uses: actions/upload-artifact@v4 |
| 124 | + with: |
| 125 | + name: deb-amd64 |
| 126 | + path: ${{ runner.temp }}/out-amd64/*.deb |
| 127 | + if-no-files-found: error |
| 128 | + |
| 129 | + build-arm64: |
| 130 | + name: Build deb arm64 |
| 131 | + runs-on: ubuntu-24.04-arm |
| 132 | + env: |
| 133 | + TARGET_ARCH: arm64 |
| 134 | + FILE_ARCH_TOKEN: aarch64 |
| 135 | + steps: |
| 136 | + - name: Checkout |
| 137 | + uses: actions/checkout@v4 |
| 138 | + with: |
| 139 | + fetch-depth: 0 |
| 140 | + |
| 141 | + - name: Checkout requested commit |
| 142 | + if: ${{ inputs.server_commit != '' }} |
| 143 | + run: git checkout "${{ inputs.server_commit }}" |
| 144 | + |
| 145 | + - name: Install build dependencies |
| 146 | + run: | |
| 147 | + set -euo pipefail |
| 148 | + sudo apt-get update |
| 149 | + sudo apt-get install -y --no-install-recommends \ |
| 150 | + file \ |
| 151 | + dpkg-dev \ |
| 152 | + liblz4-dev \ |
| 153 | + libsqlite3-dev \ |
| 154 | + libssl-dev \ |
| 155 | + zlib1g-dev |
| 156 | +
|
| 157 | + - name: Build and package |
| 158 | + run: | |
| 159 | + set -euo pipefail |
| 160 | +
|
| 161 | + swift build -c release --product wired3 |
| 162 | + BIN_DIR="$(swift build -c release --show-bin-path)" |
| 163 | + BIN_PATH="$BIN_DIR/wired3" |
| 164 | + DEB_NAME="${{ inputs.package_name }}_${{ inputs.marketing_version }}+${{ inputs.build_number }}_${TARGET_ARCH}.deb" |
| 165 | + STAGE_DIR="$RUNNER_TEMP/deb-stage-$TARGET_ARCH" |
| 166 | + OUT_DIR="$RUNNER_TEMP/out-$TARGET_ARCH" |
| 167 | + VERIFY_DIR="$RUNNER_TEMP/verify-$TARGET_ARCH" |
| 168 | + OUT_DEB="$OUT_DIR/$DEB_NAME" |
| 169 | +
|
| 170 | + file "$BIN_PATH" |
| 171 | + file "$BIN_PATH" | grep -q "$FILE_ARCH_TOKEN" |
| 172 | + ldd "$BIN_PATH" || true |
| 173 | +
|
| 174 | + rm -rf "$STAGE_DIR" "$OUT_DIR" "$VERIFY_DIR" |
| 175 | + mkdir -p "$STAGE_DIR/DEBIAN" "$STAGE_DIR/usr/local/bin" "$OUT_DIR" "$VERIFY_DIR" |
| 176 | +
|
| 177 | + cp "$BIN_PATH" "$STAGE_DIR/usr/local/bin/wired3" |
| 178 | + chmod 0755 "$STAGE_DIR/usr/local/bin/wired3" |
| 179 | +
|
| 180 | + sed \ |
| 181 | + -e "s|__PACKAGE_NAME__|${{ inputs.package_name }}|g" \ |
| 182 | + -e "s|__VERSION__|${{ inputs.marketing_version }}+${{ inputs.build_number }}|g" \ |
| 183 | + -e "s|__ARCH__|$TARGET_ARCH|g" \ |
| 184 | + -e "s|__MAINTAINER__|${{ inputs.maintainer }}|g" \ |
| 185 | + -e "s|__DEPENDS__|${{ inputs.depends }}|g" \ |
| 186 | + Scripts/debian/control.template > "$STAGE_DIR/DEBIAN/control" |
| 187 | +
|
| 188 | + cp Scripts/debian/postinst "$STAGE_DIR/DEBIAN/postinst" |
| 189 | + cp Scripts/debian/prerm "$STAGE_DIR/DEBIAN/prerm" |
| 190 | + chmod 0755 "$STAGE_DIR/DEBIAN/postinst" "$STAGE_DIR/DEBIAN/prerm" |
| 191 | +
|
| 192 | + if [[ "${{ inputs.service_enable }}" == "1" ]]; then |
| 193 | + mkdir -p "$STAGE_DIR/lib/systemd/system" |
| 194 | + cp Scripts/debian/wired3.service "$STAGE_DIR/lib/systemd/system/wired3.service" |
| 195 | + fi |
| 196 | +
|
| 197 | + dpkg-deb --build --root-owner-group "$STAGE_DIR" "$OUT_DEB" |
| 198 | + dpkg-deb -x "$OUT_DEB" "$VERIFY_DIR" |
| 199 | + file "$VERIFY_DIR/usr/local/bin/wired3" |
| 200 | + file "$VERIFY_DIR/usr/local/bin/wired3" | grep -q "$FILE_ARCH_TOKEN" |
| 201 | +
|
| 202 | + - name: Upload arch artifact |
| 203 | + uses: actions/upload-artifact@v4 |
| 204 | + with: |
| 205 | + name: deb-arm64 |
| 206 | + path: ${{ runner.temp }}/out-arm64/*.deb |
| 207 | + if-no-files-found: error |
| 208 | + |
| 209 | + assemble-artifacts: |
| 210 | + name: Assemble deb artifacts |
| 211 | + runs-on: ubuntu-latest |
| 212 | + needs: |
| 213 | + - build-amd64 |
| 214 | + - build-arm64 |
| 215 | + steps: |
| 216 | + - name: Download amd64 artifact |
| 217 | + uses: actions/download-artifact@v4 |
| 218 | + with: |
| 219 | + name: deb-amd64 |
| 220 | + path: out |
| 221 | + |
| 222 | + - name: Download arm64 artifact |
| 223 | + uses: actions/download-artifact@v4 |
| 224 | + with: |
| 225 | + name: deb-arm64 |
| 226 | + path: out |
| 227 | + |
| 228 | + - name: Verify expected filenames |
| 229 | + run: | |
| 230 | + set -euo pipefail |
| 231 | + ls -la out |
| 232 | + test -f "out/${{ inputs.package_name }}_${{ inputs.marketing_version }}+${{ inputs.build_number }}_amd64.deb" |
| 233 | + test -f "out/${{ inputs.package_name }}_${{ inputs.marketing_version }}+${{ inputs.build_number }}_arm64.deb" |
| 234 | +
|
| 235 | + - name: Upload final artifact bundle |
| 236 | + uses: actions/upload-artifact@v4 |
| 237 | + with: |
| 238 | + name: ${{ inputs.debian_artifact_name }} |
| 239 | + path: out/*.deb |
| 240 | + if-no-files-found: error |
0 commit comments