Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions .github/workflows/deb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: 📦 Build .deb Packages

on:
push:
branches: [main, customer-*]
tags: ["v*"]

permissions:
contents: write

jobs:
build:
name: 📦 PG ${{ matrix.pg }} ${{ matrix.os.arch }}
runs-on: ${{ matrix.os.runner }}
strategy:
fail-fast: false
matrix:
pg: [18, 17, 16]
os:
- { arch: amd64, runner: ubuntu-22.04 }
- { arch: arm64, runner: ubuntu-22.04-arm }
steps:
- name: Add PostgreSQL APT Repository
run: |
sudo apt-get update
sudo apt-get install -y curl ca-certificates gnupg
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null
echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt-get update

- name: Install Build Dependencies
run: |
sudo apt-get install -y \
postgresql-${{ matrix.pg }} \
postgresql-server-dev-${{ matrix.pg }} \
cmake ninja-build g++ libssl-dev

- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Configure
run: |
cmake --preset release \
-DPG_CONFIG=/usr/lib/postgresql/${{ matrix.pg }}/bin/pg_config

- name: Build
run: cmake --build build --parallel

- name: Install to Staging Directory
run: DESTDIR=${{ github.workspace }}/dest cmake --install build

- name: Extract Version
id: meta
run: |
VERSION=$(jq -r '.version' META.json)
PKG_NAME="pg-stat-ch-${VERSION}-pg${{ matrix.pg }}-${{ matrix.os.arch }}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "pkg_name=$PKG_NAME" >> "$GITHUB_OUTPUT"

- name: Install nfpm
run: |
curl -fsSL -o /tmp/nfpm.deb https://github.com/goreleaser/nfpm/releases/download/v2.46.0/nfpm_2.46.0_${{ matrix.os.arch }}.deb
sudo dpkg -i /tmp/nfpm.deb

- name: Build .deb
env:
PG_MAJOR: ${{ matrix.pg }}
VERSION: ${{ steps.meta.outputs.version }}
ARCH: ${{ matrix.os.arch }}
DESTDIR: ${{ github.workspace }}/dest
run: |
envsubst < nfpm.yml > nfpm-resolved.yml
nfpm package -f nfpm-resolved.yml -p deb -t ${{ steps.meta.outputs.pkg_name }}.deb

- name: Upload .deb Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.meta.outputs.pkg_name }}
path: ${{ steps.meta.outputs.pkg_name }}.deb

release:
name: 🚀 Upload to Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Download All .deb Artifacts
uses: actions/download-artifact@v4
with:
path: debs
pattern: pg-stat-ch-*
merge-multiple: true

- name: Determine Release Tag
id: tag
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
echo "prerelease=false" >> "$GITHUB_OUTPUT"
elif [[ "$GITHUB_REF" == refs/heads/main ]]; then
echo "tag=dev" >> "$GITHUB_OUTPUT"
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
# customer-foo -> customer-foo
BRANCH="${GITHUB_REF#refs/heads/}"
echo "tag=$BRANCH" >> "$GITHUB_OUTPUT"
echo "prerelease=true" >> "$GITHUB_OUTPUT"
fi

- name: Create or Update Release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.tag.outputs.tag }}
PRERELEASE: ${{ steps.tag.outputs.prerelease }}
run: |
ls -la debs/

if [[ "$PRERELEASE" == "true" ]]; then
# Create the release if it doesn't exist yet.
gh release view "$TAG" -R "$GITHUB_REPOSITORY" >/dev/null 2>&1 || \
gh release create "$TAG" -R "$GITHUB_REPOSITORY" \
--prerelease \
--title "$TAG" \
--notes "Rolling pre-release for \`$TAG\`. Updated on every push."
else
# For version tags, ensure the release exists before uploading assets.
gh release view "$TAG" -R "$GITHUB_REPOSITORY" >/dev/null 2>&1 || \
gh release create "$TAG" -R "$GITHUB_REPOSITORY" \
--title "$TAG" \
--notes "Release $TAG"
fi
Comment on lines +121 to +133
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For tag builds, this job assumes the release already exists (created by release.yml) and only waits up to ~50 seconds before attempting gh release upload. release.yml creates the release only after its own build matrix completes, which can take many minutes, so this workflow can fail spuriously on tags. Consider creating the release here if it doesn’t exist (even for version tags), or waiting/polling until it exists with a longer timeout and failing explicitly if it never appears.

Suggested change
# Create the release if it doesn't exist yet.
gh release view "$TAG" -R "$GITHUB_REPOSITORY" >/dev/null 2>&1 || \
gh release create "$TAG" -R "$GITHUB_REPOSITORY" \
--prerelease \
--title "$TAG" \
--notes "Rolling pre-release for \`$TAG\`. Updated on every push."
# Upload .deb files, replacing any existing ones.
gh release upload "$TAG" debs/*.deb -R "$GITHUB_REPOSITORY" --clobber
else
# For version tags, the release is created by release.yml.
# Wait briefly for it to exist, then attach .debs.
for i in 1 2 3 4 5; do
gh release view "$TAG" -R "$GITHUB_REPOSITORY" >/dev/null 2>&1 && break
echo "Waiting for release $TAG to be created..."
sleep 10
done
gh release upload "$TAG" debs/*.deb -R "$GITHUB_REPOSITORY" --clobber
fi
# Create the pre-release if it doesn't exist yet.
gh release view "$TAG" -R "$GITHUB_REPOSITORY" >/dev/null 2>&1 || \
gh release create "$TAG" -R "$GITHUB_REPOSITORY" \
--prerelease \
--title "$TAG" \
--notes "Rolling pre-release for \`$TAG\`. Updated on every push."
else
# For version tags, ensure the release exists before uploading assets.
gh release view "$TAG" -R "$GITHUB_REPOSITORY" >/dev/null 2>&1 || \
gh release create "$TAG" -R "$GITHUB_REPOSITORY" \
--title "$TAG" \
--notes "Release $TAG"
fi
# Upload .deb files, replacing any existing ones.
gh release upload "$TAG" debs/*.deb -R "$GITHUB_REPOSITORY" --clobber

Copilot uses AI. Check for mistakes.

# Upload .deb files, replacing any existing ones.
gh release upload "$TAG" debs/*.deb -R "$GITHUB_REPOSITORY" --clobber
25 changes: 25 additions & 0 deletions nfpm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: postgresql-${PG_MAJOR}-pg-stat-ch
arch: ${ARCH}
version: ${VERSION}
release: 1
platform: linux
section: database
priority: optional
maintainer: "Kaushik Iska <iska.kaushik@gmail.com>"
description: "PostgreSQL Query Telemetry Exporter to ClickHouse for PostgreSQL ${PG_MAJOR}"
vendor: ClickHouse
homepage: https://github.com/ClickHouse/pg_stat_ch
license: Apache-2.0

depends:
- postgresql-${PG_MAJOR}
- libssl3

contents:
# Extension SQL and control files.
- src: ${DESTDIR}/usr/share/postgresql/${PG_MAJOR}/extension/*.*
dst: /usr/share/postgresql/${PG_MAJOR}/extension/

# Shared library.
- src: ${DESTDIR}/usr/lib/postgresql/${PG_MAJOR}/lib/pg_stat_ch.so
dst: /usr/lib/postgresql/${PG_MAJOR}/lib/pg_stat_ch.so
Loading