From efca9b0a8e453feee64b3c5df60e9429691de877 Mon Sep 17 00:00:00 2001 From: Adam Hendel Date: Tue, 14 May 2024 08:16:46 -0500 Subject: [PATCH] build deb package (#210) build deb package --- .github/workflows/build_extension_deb.yml | 109 ++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 .github/workflows/build_extension_deb.yml diff --git a/.github/workflows/build_extension_deb.yml b/.github/workflows/build_extension_deb.yml new file mode 100644 index 00000000..add78041 --- /dev/null +++ b/.github/workflows/build_extension_deb.yml @@ -0,0 +1,109 @@ +name: Build Extension .deb + +defaults: + run: + shell: bash + working-directory: ./ + +on: + release: + types: + - created + +jobs: + build-deb: + # source: https://github.com/supabase/pg_jsonschema/blob/29fcd5b23abe3dd6a78a490082f34113de7813a1/.github/workflows/release.yml + name: release .deb + if: github.event_name == 'release' + strategy: + matrix: + extension_name: + - pgmq + package_name: + - pgmq + pgrx_version: + - 0.11.3 + postgres: + - 14 + - 15 + - 16 + box: + - { runner: ubuntu-20.04, arch: amd64 } + - { runner: arm-runner, arch: arm64 } + runs-on: ${{ matrix.box.runner }} + timeout-minutes: 90 + steps: + - uses: actions/checkout@v4 + + - name: build release artifacts + run: | + # Add postgres package repo + sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' + wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null + + sudo apt-get update + sudo apt-get install -y --no-install-recommends git build-essential libpq-dev curl libreadline6-dev zlib1g-dev pkg-config cmake + sudo apt-get install -y --no-install-recommends libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache + sudo apt-get install -y --no-install-recommends clang libclang-dev gcc tree + + sudo apt install -y postgresql-${{ matrix.postgres }} postgresql-server-dev-${{ matrix.postgres }} -y + + export PATH=$PATH:/usr/lib/postgresql/${{ matrix.postgres }}/bin + + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --default-toolchain stable && \ + rustup --version && \ + rustc --version && \ + cargo --version + + source "$HOME/.cargo/env" + + pgrx_ver=$(grep '^pgrx' Cargo.toml | head -1 | awk -F '"' '{print $2}') + cargo install cargo-pgrx --version ${pgrx_ver} --locked + cargo pgrx init --pg${{ matrix.postgres }}=/usr/lib/postgresql/${{ matrix.postgres }}/bin/pg_config + + cargo pgrx package --pg-config $(cargo pgrx info pg-config ${{ matrix.postgres }}) + + # Create installable package + mkdir archive + cp `find target/release -type f -name "${{ matrix.extension_name }}*"` archive + + # name of the package directory before packaging + package_dir=${{ matrix.extension_name }}-${{ github.ref_name }}-pg${{ matrix.postgres }}-${{ matrix.box.arch }}-linux-gnu + + # Copy files into directory structure + mkdir -p ${package_dir}/usr/lib/postgresql/lib + mkdir -p ${package_dir}/var/lib/postgresql/extension + cp archive/*.so ${package_dir}/usr/lib/postgresql/lib + cp archive/*.control ${package_dir}/var/lib/postgresql/extension + cp archive/*.sql ${package_dir}/var/lib/postgresql/extension + + deb_version=$(grep '^version' Cargo.toml | head -1 | awk -F '"' '{print $2}') + + mkdir -p ${package_dir}/DEBIAN + touch ${package_dir}/DEBIAN/control + echo 'Package: ${{ matrix.package_name }}' >> ${package_dir}/DEBIAN/control + echo 'Version:' ${deb_version} >> ${package_dir}/DEBIAN/control + echo 'Architecture: ${{ matrix.box.arch }}' >> ${package_dir}/DEBIAN/control + echo 'Maintainer: tembo' >> ${package_dir}/DEBIAN/control + echo 'Description: A PostgreSQL queue extension' >> ${package_dir}/DEBIAN/control + + # Create deb package + sudo chown -R root:root ${package_dir} + sudo chmod -R 00755 ${package_dir} + sudo dpkg-deb --build --root-owner-group ${package_dir} + + - name: Prepare release + run: | + deb_version=$(grep '^version' Cargo.toml | head -1 | awk -F '"' '{print $2}') + echo UPLOAD_URL=$(curl --silent https://api.github.com/repos/${{ github.repository }}/releases/tags/v${deb_version} | jq .upload_url --raw-output) >> $GITHUB_ENV + echo ASSET_NAME=${{ matrix.extension_name }}-${deb_version}-pg${{ matrix.postgres }}-${{ matrix.box.arch }}-linux-gnu.deb >> $GITHUB_ENV + + - name: Upload deb to github release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ env.UPLOAD_URL }} + asset_path: ./${{ env.ASSET_NAME }} + asset_name: ${{ env.ASSET_NAME }} + asset_content_type: application/vnd.debian.binary-package