Skip to content

Automate deb and rpm package generation #3

Automate deb and rpm package generation

Automate deb and rpm package generation #3

Workflow file for this run

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-22.04
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: Run lintian checks
run: |
lintian --no-tag-display-limit ../*.deb || true
- name: List package contents
run: |
dpkg-deb --contents ../*.deb
dpkg-deb --info ../*.deb
- name: Upload DEB package
uses: actions/upload-artifact@v4
with:
name: debian-package
path: ../*.deb
if-no-files-found: error
- name: Upload DEB changes
uses: actions/upload-artifact@v4
with:
name: debian-changes
path: ../*.changes
if-no-files-found: warn
build-rpm:
name: Build RPM Package
runs-on: ubuntu-latest
container: fedora:latest
steps:
- name: Install git for checkout
run: dnf 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: |
dnf install -y \
rpm-build \
rpmdevtools \
rpmlint \
rust \
cargo \
openssl-devel \
systemd-rpm-macros \
unixODBC-devel \
freetds-devel
- 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/')
sed -i "s/^Version:.*/Version: ${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/')
git archive --format=tar.gz --prefix="SQLPage-${VERSION}/" \
-o ~/rpmbuild/SOURCES/sqlpage-${VERSION}.tar.gz HEAD
- name: Build RPM package
run: |
rpmbuild -ba ~/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: |
dnf install -y ./sqlpage*.rpm
- name: Verify installation
run: |
sqlpage --version
which 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: |
yum install -y ./sqlpage*.rpm
- name: Verify installation
run: |
sqlpage --version
which 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