Automate deb and rpm package generation #14
This file contains hidden or 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: Build and Test Packages | |
on: | |
push: | |
tags: | |
- "v*" | |
branches: | |
- "main" | |
- "release-test" | |
pull_request: | |
branches: | |
- "main" | |
paths: | |
- "debian/**" | |
- "rpm/**" | |
- "scripts/build-*.sh" | |
- ".github/workflows/packages.yml" | |
workflow_dispatch: | |
workflow_call: | |
permissions: | |
contents: write | |
actions: read | |
jobs: | |
build-deb: | |
name: Build Debian Package | |
runs-on: ubuntu-20.04 # Use older Ubuntu for wider glibc compatibility | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install build dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y \ | |
debhelper \ | |
dh-make \ | |
devscripts \ | |
lintian \ | |
dpkg-dev \ | |
build-essential \ | |
unixodbc-dev \ | |
freetds-dev \ | |
libssl-dev \ | |
pkg-config | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: x86_64-unknown-linux-gnu | |
- name: Set up cargo cache | |
uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 | |
- name: Build Debian package | |
run: | | |
# Update changelog with current version | |
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') | |
sed -i "1s/.*/sqlpage ($VERSION-1) unstable; urgency=medium/" debian/changelog | |
# Build package (use -d to bypass build dependency checks since Rust is provided by CI) | |
dpkg-buildpackage -us -uc -b -d | |
- name: Collect build artifacts | |
run: | | |
mkdir -p build-output | |
mv ../*.deb build-output/ || true | |
mv ../*.changes build-output/ || true | |
mv ../*.buildinfo build-output/ || true | |
ls -lh build-output/ | |
- name: Run lintian checks | |
run: | | |
lintian --no-tag-display-limit build-output/*.deb || true | |
- name: List package contents | |
run: | | |
dpkg-deb --contents build-output/*.deb | |
dpkg-deb --info build-output/*.deb | |
- name: Upload DEB package | |
uses: actions/upload-artifact@v4 | |
with: | |
name: debian-package | |
path: build-output/*.deb | |
if-no-files-found: error | |
- name: Upload DEB changes | |
uses: actions/upload-artifact@v4 | |
with: | |
name: debian-changes | |
path: build-output/*.changes | |
if-no-files-found: warn | |
build-rpm: | |
name: Build RPM Package | |
runs-on: ubuntu-latest | |
container: quay.io/pypa/manylinux_2_28_x86_64 # Maximum glibc compatibility (glibc 2.28) | |
steps: | |
- name: Install git for checkout | |
run: yum install -y git | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Configure git safe directory | |
run: git config --global --add safe.directory /__w/SQLPage/SQLPage | |
- name: Install build dependencies | |
run: | | |
yum update -y | |
yum install -y \ | |
rpm-build \ | |
rpmdevtools \ | |
openssl-devel \ | |
systemd \ | |
unixODBC-devel \ | |
freetds-devel | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: x86_64-unknown-linux-gnu | |
- name: Set up cargo cache | |
uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 | |
- name: Set up RPM build tree | |
run: rpmdev-setuptree | |
- name: Update spec file version | |
run: | | |
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') | |
# RPM doesn't allow hyphens in Version field, convert to tilde for pre-releases | |
RPM_VERSION=$(echo "$VERSION" | sed 's/-/~/') | |
sed -i "s/^Version:.*/Version: ${RPM_VERSION}/" rpm/sqlpage.spec | |
cp rpm/sqlpage.spec ~/rpmbuild/SPECS/ | |
- name: Create source tarball | |
run: | | |
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') | |
RPM_VERSION=$(echo "$VERSION" | sed 's/-/~/') | |
# Create tarball with version prefix matching spec file Source0 | |
git archive --format=tar.gz --prefix="SQLPage-${RPM_VERSION}/" \ | |
-o ~/rpmbuild/SOURCES/v${RPM_VERSION}.tar.gz HEAD | |
- name: Build RPM package | |
run: | | |
# Use --nodeps to bypass build dependency checks since Rust is provided by CI | |
rpmbuild -ba --nodeps ~/rpmbuild/SPECS/sqlpage.spec | |
- name: Run rpmlint checks | |
run: | | |
rpmlint ~/rpmbuild/RPMS/*/sqlpage*.rpm || true | |
rpmlint ~/rpmbuild/SRPMS/sqlpage*.rpm || true | |
- name: List package contents | |
run: | | |
rpm -qilp ~/rpmbuild/RPMS/*/sqlpage*.rpm | |
- name: Upload RPM package | |
uses: actions/upload-artifact@v4 | |
with: | |
name: rpm-package | |
path: ~/rpmbuild/RPMS/*/sqlpage*.rpm | |
if-no-files-found: error | |
- name: Upload SRPM package | |
uses: actions/upload-artifact@v4 | |
with: | |
name: srpm-package | |
path: ~/rpmbuild/SRPMS/sqlpage*.rpm | |
if-no-files-found: error | |
test-deb-debian: | |
name: Test DEB on Debian ${{ matrix.version }} | |
needs: build-deb | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
version: ["bookworm", "bullseye"] | |
container: debian:${{ matrix.version }} | |
steps: | |
- name: Download DEB package | |
uses: actions/download-artifact@v4 | |
with: | |
name: debian-package | |
- name: Install package | |
run: | | |
apt-get update | |
apt-get install -y ./sqlpage*.deb | |
- name: Verify installation | |
run: | | |
sqlpage --version | |
which sqlpage | |
dpkg -l | grep sqlpage | |
test -f /usr/bin/sqlpage | |
test -d /etc/sqlpage | |
test -f /etc/sqlpage/sqlpage.json | |
test -d /etc/sqlpage/templates | |
test -f /lib/systemd/system/sqlpage.service | |
- name: Test service file | |
run: | | |
systemctl cat sqlpage.service || cat /lib/systemd/system/sqlpage.service | |
- name: Verify user creation | |
run: | | |
id sqlpage | |
getent passwd sqlpage | |
test-deb-ubuntu: | |
name: Test DEB on Ubuntu ${{ matrix.version }} | |
needs: build-deb | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
version: ["24.04", "22.04", "20.04"] | |
container: ubuntu:${{ matrix.version }} | |
steps: | |
- name: Download DEB package | |
uses: actions/download-artifact@v4 | |
with: | |
name: debian-package | |
- name: Install package | |
run: | | |
apt-get update | |
apt-get install -y ./sqlpage*.deb | |
- name: Verify installation | |
run: | | |
sqlpage --version | |
which sqlpage | |
dpkg -l | grep sqlpage | |
test -f /usr/bin/sqlpage | |
test -d /etc/sqlpage | |
test -f /etc/sqlpage/sqlpage.json | |
- name: Test service file | |
run: | | |
systemctl cat sqlpage.service || cat /lib/systemd/system/sqlpage.service | |
test-rpm-fedora: | |
name: Test RPM on Fedora ${{ matrix.version }} | |
needs: build-rpm | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
version: ["latest", "39", "40"] | |
container: fedora:${{ matrix.version }} | |
steps: | |
- name: Download RPM package | |
uses: actions/download-artifact@v4 | |
with: | |
name: rpm-package | |
- name: Install package | |
run: | | |
ls -la | |
ls -la x86_64/ || true | |
dnf install -y ./x86_64/*.rpm | |
- name: Verify installation | |
run: | | |
sqlpage --version | |
command -v sqlpage | |
rpm -q sqlpage | |
test -f /usr/bin/sqlpage | |
test -d /etc/sqlpage | |
test -f /etc/sqlpage/sqlpage.json | |
test -d /etc/sqlpage/templates | |
test -f /usr/lib/systemd/system/sqlpage.service | |
- name: Test service file | |
run: | | |
systemctl cat sqlpage.service || cat /usr/lib/systemd/system/sqlpage.service | |
- name: Verify user creation | |
run: | | |
id sqlpage | |
getent passwd sqlpage | |
test-rpm-rhel: | |
name: Test RPM on RHEL-based ${{ matrix.distro }}:${{ matrix.version }} | |
needs: build-rpm | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- distro: rockylinux | |
version: "9" | |
- distro: rockylinux | |
version: "8" | |
- distro: almalinux | |
version: "9" | |
- distro: almalinux | |
version: "8" | |
container: ${{ matrix.distro }}:${{ matrix.version }} | |
steps: | |
- name: Download RPM package | |
uses: actions/download-artifact@v4 | |
with: | |
name: rpm-package | |
- name: Install package | |
run: | | |
ls -la | |
ls -la x86_64/ || true | |
yum install -y ./x86_64/*.rpm | |
- name: Verify installation | |
run: | | |
sqlpage --version | |
command -v sqlpage | |
rpm -q sqlpage | |
test -f /usr/bin/sqlpage | |
test -d /etc/sqlpage | |
publish-packages: | |
name: Publish Packages to GitHub Release | |
needs: [test-deb-debian, test-deb-ubuntu, test-rpm-fedora, test-rpm-rhel] | |
runs-on: ubuntu-latest | |
if: startsWith(github.ref, 'refs/tags/') | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
- name: Prepare release assets | |
run: | | |
mkdir -p release-assets | |
cp debian-package/*.deb release-assets/ | |
cp rpm-package/*.rpm release-assets/ | |
cp srpm-package/*.rpm release-assets/ | |
ls -lh release-assets/ | |
- name: Generate package checksums | |
run: | | |
cd release-assets | |
sha256sum * > SHA256SUMS | |
cat SHA256SUMS | |
- name: Upload to GitHub Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: | | |
release-assets/*.deb | |
release-assets/*.rpm | |
release-assets/SHA256SUMS | |
fail_on_unmatched_files: true |