Skip to content

Build PostgreSQL (14~18) #12

Build PostgreSQL (14~18)

Build PostgreSQL (14~18) #12

name: Build PostgreSQL (14~18)
on:
workflow_dispatch:
inputs:
pg_versions:
description: PostgreSQL versions to build (comma separated)
required: true
default: "14.23,15.18,16.14,17.10,18.4"
packaging-repo:
description: packaging repo to be used
default: percona/postgres-packaging
required: true
distro:
description: RPM/Deb
required: true
default: both
type: choice
options:
- "rpm-and-deb"
- "rpm"
- "deb"
ppg-repo-type:
description: ppg repo type
required: true
default: experimental
type: choice
options:
- experimental
- testing
debugging:
description: tmate session required
default: false
type: boolean
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
prepare-matrix:
runs-on: ubuntu-latest
outputs:
BUILD_ID: ${{ steps.set-buildID.outputs.build_id }}
PG_MATRIX: ${{ steps.set-pg-matrix.outputs.pg_matrix }}
SOURCE_MATRIX: ${{ steps.set-source-matrix.outputs.source_matrix }}
BUILD_MATRIX: ${{ steps.set-build-matrix.outputs.build_matrix }}
steps:
- name: Set timestamp
run: echo "TIMESTAMP=$(date +'%Y%m%d-%H%M%S')" >> $GITHUB_ENV
- name: Set Build ID
id: set-buildID
run: echo "build_id=${{ env.TIMESTAMP }}/${GITHUB_RUN_NUMBER}" >> "$GITHUB_OUTPUT"
- name: Set PG Matrix
id: set-pg-matrix
run: |
PG_MATRIX=$(echo "${{ inputs.pg_versions }}" | tr -d ' ' | jq -c -R 'split(",") | {pg_version: .}')
echo "pg_matrix=$PG_MATRIX" >> $GITHUB_OUTPUT
- name: Set source rpm/deb matrix
id: set-source-matrix
run: |
PG_VERSION=$(echo "${{ inputs.pg_versions }}" | tr -d ' ' | jq -c -R 'split(",")')
if [ "${{ inputs.distro }}" = "rpm" ]; then
PLATFORM='["oraclelinux:8"]'
elif [ "${{ inputs.distro }}" = "deb" ]; then
PLATFORM='["ubuntu:noble"]'
else
PLATFORM='["oraclelinux:8","ubuntu:noble"]'
fi
SOURCE_MATRIX=$(jq -c -n \
--argjson pg_version "$PG_VERSION" \
--argjson platform "$PLATFORM" \
'{pg_version:$pg_version, platform:$platform}')
echo "source_matrix=$SOURCE_MATRIX" >> $GITHUB_OUTPUT
- name: Set rpm/deb build matrix
id: set-build-matrix
run: |
ARCH='["amd64","arm64"]'
PG_VERSION=$(echo "${{ inputs.pg_versions }}" | tr -d ' ' | jq -c -R 'split(",")')
if [ "${{ inputs.distro }}" = "rpm" ]; then
PLATFORM='["oraclelinux:8","oraclelinux:9","oraclelinux:10"]'
elif [ "${{ inputs.distro }}" = "deb" ]; then
PLATFORM='["ubuntu:noble","ubuntu:jammy","ubuntu:resolute","debian:bookworm","debian:bullseye","debian:trixie"]'
else
PLATFORM='["oraclelinux:8","oraclelinux:9","oraclelinux:10","ubuntu:noble","ubuntu:jammy","ubuntu:resolute","debian:bookworm","debian:bullseye","debian:trixie"]'
fi
BUILD_MATRIX=$(jq -c -n \
--argjson pg_version "$PG_VERSION" \
--argjson platform "$PLATFORM" \
--argjson arch "$ARCH" \
'{pg_version:$pg_version, platform:$platform, arch:$arch}')
echo "build_matrix=$BUILD_MATRIX" >> $GITHUB_OUTPUT
pull-build-files:
runs-on: ubuntu-latest
needs: [prepare-matrix]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare-matrix.outputs.PG_MATRIX) }}
steps:
- name: Checkout packaging repo
uses: actions/checkout@v5
with:
fetch-depth: 0
repository: ${{ inputs.packaging-repo }}
ref: ${{ matrix.pg_version }}
path: src
- name: Create build files directory
run: mkdir pkg
- name: Collect PG packaging files
run: |
cp src/common-functions.sh pkg/
cp src/install-deps.sh pkg/
cp src/versions.sh pkg/
cp src/postgres/ppg_builder.sh pkg/
shell: bash
- name: Upload build files as artifact
uses: actions/upload-artifact@v4
with:
name: build-files-${{ matrix.pg_version }}
path: pkg/
build-source-tarball:
runs-on: ubuntu-latest
needs: [prepare-matrix, pull-build-files]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare-matrix.outputs.PG_MATRIX) }}
steps:
- name: Get build script artifact
uses: actions/download-artifact@v5
with:
name: build-files-${{ matrix.pg_version }}
path: ./
- name: Update permissions of the build scripts
run: |
chmod 755 *.sh
shell: bash
- name: Build Sources
run: |
mkdir test
sudo -E ./ppg_builder.sh --builddir=$(pwd)/test --get_sources=1 --repo_component=${{ inputs.ppg-repo-type }}
shell: bash
- name: Upload source tarballs as artifact
uses: actions/upload-artifact@v4
with:
name: PG${{ matrix.pg_version }}-source_tarball
path: source_tarball
build-srpm-sdeb:
runs-on: ubuntu-latest
needs: [prepare-matrix, pull-build-files, build-source-tarball]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare-matrix.outputs.SOURCE_MATRIX) }}
container:
image: ${{ matrix.platform }}
steps:
- name: Check OS
run: cat /etc/os-release
- name: Install build tools
run: |
if [[ "${{ matrix.platform }}" == *"linux"* ]]; then
yum install -y gcc make tar rpm-build rpmdevtools git sudo
else
apt-get update
apt-get install -y wget curl gcc tar git build-essential devscripts debhelper fakeroot lintian sudo
fi
echo "Ready to build!"
- name: Get build files from artifact
uses: actions/download-artifact@v5
with:
name: build-files-${{ matrix.pg_version }}
path: ./
- name: Update permissions of the build scripts
run: |
chmod 755 *.sh
shell: bash
- name: Get source tarball from artifact
uses: actions/download-artifact@v5
with:
name: PG${{ matrix.pg_version }}-source_tarball
path: test/source_tarball/
- name: Install dependencies
run: |
sudo ./ppg_builder.sh --builddir=$(pwd)/test --install_deps=1 --repo_component=${{ inputs.ppg-repo-type }}
shell: bash
- name: Build Source RPM/DEB
run: |
if [[ "${{ matrix.platform }}" == *"linux"* ]]; then
sudo ./ppg_builder.sh --builddir=$(pwd)/test --build_src_rpm=1 --repo_component=${{ inputs.ppg-repo-type }}
else
sudo ./ppg_builder.sh --builddir=$(pwd)/test --build_src_deb=1 --repo_component=${{ inputs.ppg-repo-type }}
fi
shell: bash
- name: Upload source rpm as artifact
if: ${{ contains(matrix.platform, 'linux') }}
uses: actions/upload-artifact@v4
with:
name: PG${{ matrix.pg_version }}-srpm
path: srpm
- name: Upload source deb as artifact
if: ${{ !contains(matrix.platform, 'linux') }}
uses: actions/upload-artifact@v4
with:
name: PG${{ matrix.pg_version }}-source_deb
path: source_deb
build-rpm-deb:
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
needs: [prepare-matrix, pull-build-files, build-source-tarball, build-srpm-sdeb]
strategy:
fail-fast: false
max-parallel: 16
matrix: ${{ fromJson(needs.prepare-matrix.outputs.BUILD_MATRIX) }}
container:
image: ${{ matrix.platform }}
steps:
- name: Check OS
run: cat /etc/os-release
- name: Install build tools
run: |
if [[ "${{ matrix.platform }}" == *"linux"* ]]; then
yum install -y gcc make tar rpm-build rpmdevtools git sudo
else
apt-get update
apt-get install -y wget curl gcc tar git build-essential devscripts debhelper fakeroot lintian sudo
fi
echo "Ready to build!"
- name: Get build files artifact
uses: actions/download-artifact@v5
with:
name: build-files-${{ matrix.pg_version }}
path: ./
- name: Update permissions of the build scripts
run: |
chmod 755 *.sh
shell: bash
- name: Get source rpm from artifact
if: ${{ contains(matrix.platform, 'linux') }}
uses: actions/download-artifact@v5
with:
name: PG${{ matrix.pg_version }}-srpm
path: test/srpm/
- name: Get source deb from artifact
if: ${{ !contains(matrix.platform, 'linux') }}
uses: actions/download-artifact@v5
with:
name: PG${{ matrix.pg_version }}-source_deb
path: test/source_deb/
- name: Install dependencies
run: |
set -xe
sudo ./ppg_builder.sh --builddir=$(pwd)/test --install_deps=1 --repo_component=${{ inputs.ppg-repo-type }}
shell: bash
- name: Build RPM/DEB
run: |
if [[ "${{ matrix.platform }}" == *"linux"* ]]; then
sudo ./ppg_builder.sh --builddir=$(pwd)/test --build_rpm=1
else
sudo ./ppg_builder.sh --builddir=$(pwd)/test --build_deb=1
fi
shell: bash
- name: Compute platform label
run: |
PLATFORM="${{ matrix.platform }}"
if [[ "$PLATFORM" == *linux* ]]; then
echo "PLATFORM_LABEL=ol${PLATFORM##*:}" >> "$GITHUB_ENV"
else
echo "PLATFORM_LABEL=${PLATFORM##*:}" >> "$GITHUB_ENV"
fi
shell: bash
- name: Upload rpms as artifact
if: ${{ contains(matrix.platform, 'linux') }}
uses: actions/upload-artifact@v4
with:
name: PG${{ matrix.pg_version }}-${{ env.PLATFORM_LABEL }}-${{ matrix.arch }}
path: rpm
- name: Upload debs as artifact
if: ${{ !contains(matrix.platform, 'linux') }}
uses: actions/upload-artifact@v4
with:
name: PG${{ matrix.pg_version }}-${{ env.PLATFORM_LABEL }}-${{ matrix.arch }}
path: deb
upload-draft-release:
runs-on: ubuntu-latest
needs: [prepare-matrix, pull-build-files, build-source-tarball, build-srpm-sdeb, build-rpm-deb]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare-matrix.outputs.PG_MATRIX) }}
steps:
- name: Get package full name and upload path
run: |
pkg_name="PG${{ matrix.pg_version }}"
echo "pkg_name=$pkg_name" >> "$GITHUB_ENV"
echo "UPLOAD_PATH="postgresql/$pkg_name/${{ needs.prepare-matrix.outputs.BUILD_ID }}"" >> "$GITHUB_ENV"
- name: Create final artifact structure
run: |
mkdir -p ${{ env.UPLOAD_PATH }}/source_tarball
mkdir -p ${{ env.UPLOAD_PATH }}/srpm
mkdir -p ${{ env.UPLOAD_PATH }}/source_deb
mkdir -p ${{ env.UPLOAD_PATH }}/rpm
mkdir -p ${{ env.UPLOAD_PATH }}/deb
- name: Get all the artifacts
uses: actions/download-artifact@v5
with:
pattern: PG${{ matrix.pg_version }}-*
path: artifacts
- name: Copy all the artifacts to required location
run: |
cp -n artifacts/PG*-source_tarball/* "${{ env.UPLOAD_PATH }}/source_tarball/"
if [ "${{ inputs.distro }}" = "rpm" ] || [ "${{ inputs.distro }}" = "rpm-and-deb" ]; then
cp -n artifacts/PG*-srpm/* "${{ env.UPLOAD_PATH }}/srpm/"
cp -n artifacts/PG*-ol8-*/* "${{ env.UPLOAD_PATH }}/rpm/"
cp -n artifacts/PG*-ol9-*/* "${{ env.UPLOAD_PATH }}/rpm/"
cp -n artifacts/PG*-ol10-*/* "${{ env.UPLOAD_PATH }}/rpm/"
fi
if [ "${{ inputs.distro }}" = "deb" ] || [ "${{ inputs.distro }}" = "rpm-and-deb" ]; then
cp -n artifacts/PG*-source_deb/* "${{ env.UPLOAD_PATH }}/source_deb/"
cp -n artifacts/PG*-bookworm-*/* "${{ env.UPLOAD_PATH }}/deb/"
cp -n artifacts/PG*-bullseye-*/* "${{ env.UPLOAD_PATH }}/deb/"
cp -n artifacts/PG*-jammy-*/* "${{ env.UPLOAD_PATH }}/deb/"
cp -n artifacts/PG*-noble-*/* "${{ env.UPLOAD_PATH }}/deb/"
cp -n artifacts/PG*-trixie-*/* "${{ env.UPLOAD_PATH }}/deb/"
cp -n artifacts/PG*-resolute-*/* "${{ env.UPLOAD_PATH }}/deb/"
fi
- name: Archive final artifact
run: tar -czf ${{ env.pkg_name }}.tar.gz postgresql
- name: Upload final artifact as release artifact
uses: softprops/action-gh-release@v2
with:
draft: true
tag_name: postgresql-${{ matrix.pg_version }}-${{ inputs.distro }} build_id-${{ github.run_number }}
name: postgresql-${{ matrix.pg_version }}-${{ inputs.distro }} build_id-${{ github.run_number }}
files: ${{ env.pkg_name }}.tar.gz
- name: enable tmate debugging
if: inputs.debugging && failure()
uses: mxschmitt/action-tmate@v3
timeout-minutes: 60