Skip to content

Commit daa0c46

Browse files
Add .deb package generation for Linux releases (#18)
## Summary Adds `.deb` package generation to the release workflow for all Linux architectures. As a template repo, this demonstrates how to produce Debian packages from a Rust CI pipeline. ## Changes - Added `debArch` field to each Linux target in the build matrix (`i386`, `amd64`, `armel`, `armhf`, `arm64`) - Added a `Build .deb package` step that uses `dpkg-deb` to create Debian packages after the binary is compiled - Added `Upload .deb Release Asset` step with `--clobber` for idempotent re-runs - Uses `env.APP_NAME` consistently for binary paths and package naming - Binary installs to `/usr/bin/hello_world` ## How it works On a `release` event, each Linux matrix job creates a `.deb` package using `dpkg-deb --build`. The package contains the binary at `/usr/bin/hello_world` and a `DEBIAN/control` file with package name, version (from the release tag), and architecture. The `.deb` is uploaded to the GitHub Release alongside existing raw binaries. ## Architectures | Debian Arch | Rust Target | |---|---| | `amd64` | `x86_64-unknown-linux-gnu` | | `i386` | `i686-unknown-linux-gnu` | | `arm64` | `aarch64-unknown-linux-gnu` | | `armhf` | `armv7-unknown-linux-gnueabihf` | | `armel` | `arm-unknown-linux-gnueabi` | ## Usage ```bash sudo dpkg -i hello_world_0.02_amd64.deb hello_world ``` --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c43fbde commit daa0c46

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,27 @@ jobs:
3434
# Linux
3535
- { displayName: 32-bit Linux,
3636
rustTarget: i686-unknown-linux-gnu,
37+
debArch: i386,
3738
runner: 'ubuntu-latest' }
3839

3940
- { displayName: 64-bit Linux,
4041
rustTarget: x86_64-unknown-linux-gnu,
42+
debArch: amd64,
4143
runner: 'ubuntu-latest' }
4244

4345
- { displayName: ARM32 ARMv6 Linux,
4446
rustTarget: arm-unknown-linux-gnueabi,
47+
debArch: armel,
4548
runner: 'ubuntu-latest' }
4649

4750
- { displayName: ARM32 ARMv7 Linux,
4851
rustTarget: armv7-unknown-linux-gnueabihf,
52+
debArch: armhf,
4953
runner: 'ubuntu-latest' }
5054

5155
- { displayName: ARM64 Linux,
5256
rustTarget: aarch64-unknown-linux-gnu,
57+
debArch: arm64,
5358
runner: 'ubuntu-latest' }
5459

5560
# macOS
@@ -110,3 +115,30 @@ jobs:
110115
run: |
111116
cp ./target/${{ matrix.target.rustTarget }}/release/${{ env.APP_NAME }}${{ endsWith(matrix.target.rustTarget, '-windows-gnu') && '.exe' || '' }} ./${{ env.APP_NAME }}-${{ github.ref_name }}-${{ matrix.target.rustTarget }}${{ endsWith(matrix.target.rustTarget, '-windows-gnu') && '.exe' || '' }} &&
112117
gh release upload ${{ github.event.release.tag_name }} ./${{ env.APP_NAME }}-${{ github.ref_name }}-${{ matrix.target.rustTarget }}${{ endsWith(matrix.target.rustTarget, '-windows-gnu') && '.exe' || '' }}#"${{ env.APP_NAME }}-${{ github.ref_name }}-${{ matrix.target.rustTarget }}${{ endsWith(matrix.target.rustTarget, '-windows-gnu') && '.exe' || '' }} (${{ matrix.target.displayName }})"
118+
119+
- name: Build .deb package
120+
if: ${{ github.event_name == 'release' && matrix.target.debArch != '' }}
121+
run: |
122+
mkdir -p dpkg/DEBIAN dpkg/usr/bin
123+
cp ./target/${{ matrix.target.rustTarget }}/release/${{ env.APP_NAME }} dpkg/usr/bin/
124+
chmod 755 dpkg/usr/bin/${{ env.APP_NAME }}
125+
VERSION="${{ github.ref_name }}"
126+
VERSION="${VERSION#v}"
127+
cat > dpkg/DEBIAN/control << EOF
128+
Package: ${{ env.APP_NAME }}
129+
Version: $VERSION
130+
Architecture: ${{ matrix.target.debArch }}
131+
Maintainer: richardsondev
132+
Description: Rust application template
133+
EOF
134+
sed -i 's/^ //' dpkg/DEBIAN/control
135+
dpkg-deb --build dpkg ${{ env.APP_NAME }}_${VERSION}_${{ matrix.target.debArch }}.deb
136+
137+
- name: Upload .deb Release Asset
138+
if: ${{ github.event_name == 'release' && matrix.target.debArch != '' }}
139+
env:
140+
GH_TOKEN: ${{ github.token }}
141+
run: |
142+
VERSION="${{ github.ref_name }}"
143+
VERSION="${VERSION#v}"
144+
gh release upload ${{ github.event.release.tag_name }} --clobber ./${{ env.APP_NAME }}_${VERSION}_${{ matrix.target.debArch }}.deb

0 commit comments

Comments
 (0)