ci: simplify arch package build script #20
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
push: | |
tags: | |
- "v*" | |
env: | |
CARGO_TERM_COLOR: always | |
CARGO_INCREMENTAL: 0 | |
CARGO_NET_RETRY: 10 | |
RUSTUP_MAX_RETRIES: 10 | |
RUST_BACKTRACE: short | |
PKG_CONFIG_ALLOW_CROSS: 1 | |
jobs: | |
# First run the same checks as in CI | |
check: | |
name: Check | |
uses: ./.github/workflows/ci.yml | |
build-deb: | |
name: Build Debian Package | |
needs: check | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
target: | |
- armv7-unknown-linux-gnueabihf | |
- aarch64-unknown-linux-gnu | |
- x86_64-unknown-linux-gnu | |
include: | |
- target: armv7-unknown-linux-gnueabihf | |
arch: armhf | |
- target: aarch64-unknown-linux-gnu | |
arch: arm64 | |
- target: x86_64-unknown-linux-gnu | |
arch: amd64 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install common dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y pkg-config | |
- name: Install target specific dependencies | |
run: | | |
case ${{ matrix.target }} in | |
"x86_64-unknown-linux-gnu") | |
sudo apt-get update | |
sudo apt-get install -y libudev-dev dpkg-dev | |
;; | |
"armv7-unknown-linux-gnueabihf") | |
sudo apt-get update | |
sudo apt-get install -y binutils-arm-linux-gnueabihf crossbuild-essential-armhf | |
;; | |
"aarch64-unknown-linux-gnu") | |
sudo apt-get update | |
sudo apt-get install -y binutils-aarch64-linux-gnu crossbuild-essential-arm64 | |
;; | |
esac | |
- name: Set library path | |
if: matrix.target == 'x86_64-unknown-linux-gnu' | |
run: | | |
echo "LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH" >> $GITHUB_ENV | |
echo "LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH" >> $GITHUB_ENV | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: ${{ matrix.target }} | |
- name: Install cross | |
uses: taiki-e/install-action@cross | |
- name: Cache cargo | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
${{ runner.os }}-cargo-${{ matrix.target }}- | |
- name: Cache cross | |
if: matrix.target != 'x86_64-unknown-linux-gnu' | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cargo/.cross | |
key: ${{ runner.os }}-cross-${{ matrix.target }}-${{ hashFiles('Cross.toml') }} | |
restore-keys: | | |
${{ runner.os }}-cross-${{ matrix.target }}- | |
- name: Install cargo-deb | |
run: cargo install cargo-deb | |
- name: Build and package | |
env: | |
PKG_CONFIG_ALLOW_CROSS: "1" | |
run: | | |
if [ "${{ matrix.target }}" = "x86_64-unknown-linux-gnu" ]; then | |
# Native build | |
cargo build --release --target ${{ matrix.target }} | |
cargo deb --target ${{ matrix.target }} | |
else | |
# Cross compilation requires special paths | |
if [ "${{ matrix.target }}" = "armv7-unknown-linux-gnueabihf" ]; then | |
PKG_PATH="/usr/lib/arm-linux-gnueabihf/pkgconfig" | |
LD_PATH="/usr/arm-linux-gnueabihf/lib" | |
elif [ "${{ matrix.target }}" = "aarch64-unknown-linux-gnu" ]; then | |
PKG_PATH="/usr/lib/aarch64-linux-gnu/pkgconfig" | |
LD_PATH="/usr/aarch64-linux-gnu/lib" | |
fi | |
PKG_CONFIG_PATH="$PKG_PATH" \ | |
PKG_CONFIG_SYSROOT_DIR="/usr" \ | |
PKG_CONFIG_LIBDIR="$PKG_PATH" \ | |
cross build --release --target ${{ matrix.target }} | |
# Setup cargo config for cross-compilation strip | |
mkdir -p .cargo | |
cp dist/debian/cargo-config.toml .cargo/config.toml | |
LD_LIBRARY_PATH="$LD_PATH" \ | |
cargo deb --no-build --target ${{ matrix.target }} | |
fi | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: deb-${{ matrix.arch }} | |
path: target/${{ matrix.target }}/debian/*.deb | |
build-arch: | |
name: Build Arch Package | |
needs: check | |
runs-on: ubuntu-latest | |
container: | |
image: archlinux:base-devel | |
options: --privileged | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install dependencies | |
run: | | |
# Update system | |
pacman -Syu --noconfirm | |
# Install common dependencies | |
pacman -S --noconfirm \ | |
git \ | |
rustup \ | |
cargo \ | |
pkg-config \ | |
systemd \ | |
systemd-libs | |
- name: Setup Rust | |
run: | | |
rustup default stable | |
rustup target add x86_64-unknown-linux-gnu | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: x86_64-unknown-linux-gnu | |
- name: Cache cargo | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
key: ${{ runner.os }}-arch-cargo-x86_64-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
${{ runner.os }}-arch-cargo-x86_64- | |
- name: Build | |
run: cargo build --release --target x86_64-unknown-linux-gnu | |
- name: Prepare PKGBUILD | |
run: | | |
VERSION=$(grep -m1 'version =' Cargo.toml | cut -d '"' -f2) | |
sed -i "s/pkgver=.*/pkgver=$VERSION/" dist/arch/PKGBUILD | |
cp dist/arch/PKGBUILD . | |
- name: Build package | |
run: | | |
chown -R nobody:nobody . | |
runuser -u nobody -- makepkg -s --noconfirm | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: pkg-x86_64 | |
path: ./*.pkg.tar.zst | |
create-release: | |
name: Create Release | |
needs: [build-deb, build-arch] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: deb-*/*.deb pkg-*/*.pkg.tar.zst | |
generate_release_notes: true |