diff --git a/.github/workflows/deb.yml b/.github/workflows/deb.yml new file mode 100644 index 0000000..ae6d396 --- /dev/null +++ b/.github/workflows/deb.yml @@ -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 + + # Upload .deb files, replacing any existing ones. + gh release upload "$TAG" debs/*.deb -R "$GITHUB_REPOSITORY" --clobber diff --git a/nfpm.yml b/nfpm.yml new file mode 100644 index 0000000..c3eae05 --- /dev/null +++ b/nfpm.yml @@ -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 " +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