-
Notifications
You must be signed in to change notification settings - Fork 4
Add .deb packaging workflow with GitHub Releases #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iskakaushik
wants to merge
2
commits into
main
Choose a base branch
from
add-deb-packaging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| 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 | ||
|
|
||
| # Upload .deb files, replacing any existing ones. | ||
| gh release upload "$TAG" debs/*.deb -R "$GITHUB_REPOSITORY" --clobber | ||
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
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 attemptinggh release upload.release.ymlcreates 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.