Skip to content
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

feat: support pg13 #134

Merged
merged 13 commits into from
Oct 8, 2024
309 changes: 154 additions & 155 deletions .github/workflows/check-pg_analytics-schema-upgrade.yml
Original file line number Diff line number Diff line change
@@ -1,155 +1,154 @@
# TODO: Uncomment once we have PG13 support, which is required for pg-schema-diff
# # workflows/check-pg_analytics-schema-upgrade.yml
# #
# # Check pg_analytics Schema Upgrade pg_analytics
# # Determine if a commit introduces an extension schema change for pg_analytics.

# name: Check pg_analytics Schema Upgrade

# on:
# pull_request:
# types: [opened, synchronize, reopened, ready_for_review]
# branches:
# - dev
# - main
# paths:
# - ".github/workflows/check-pg_analytics-schema-upgrade.yml"
# - "pg_analytics/**"
# - "!pg_analytics/README.md"
# workflow_dispatch:

# # Required to post a comment to the PR
# permissions:
# pull-requests: write

# concurrency:
# group: check-pg_analytics-schema-upgrade-${{ github.head_ref || github.ref }}
# cancel-in-progress: true

# jobs:
# check-pg_analytics-schema-upgrade:
# name: Post Schema Change to PR
# runs-on: depot-ubuntu-latest-8
# if: github.event.pull_request.draft == false
# env:
# pg_version: 13 # Required by pg-schema-diff

# steps:
# - name: Checkout Git Repository
# uses: actions/checkout@v4
# with:
# fetch-depth: 0 # Fetch the entire history

# - name: Install Rust
# uses: dtolnay/rust-toolchain@stable

# # Caches from base branches are available to PRs, but not across unrelated branches, so we only
# # save the cache on the 'dev' branch, but load it on all branches.
# - name: Install Rust Cache
# uses: Swatinem/rust-cache@v2
# with:
# prefix-key: "v1"
# shared-key: ${{ runner.os }}-rust-cache-pg_analytics-${{ HashFiles('Cargo.lock') }}
# cache-targets: true
# cache-on-failure: true
# cache-all-crates: true
# save-if: ${{ github.ref == 'refs/heads/dev' }}

# - name: Install & Configure Supported PostgreSQL Version
# run: |
# wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# sudo apt-get update && sudo apt-get install -y postgresql-${{ env.pg_version }} postgresql-server-dev-${{ env.pg_version }}
# sudo chown -R $(whoami) /usr/share/postgresql/${{ env.pg_version }}/ /usr/lib/postgresql/${{ env.pg_version }}/ /var/lib/postgresql/${{ env.pg_version }}/
# rustup component add llvm-tools-preview
# echo "/usr/lib/postgresql/${{ env.pg_version }}/bin" >> $GITHUB_PATH

# - name: Install pg-schema-diff and its Required Dependencies
# run: |
# sudo apt install clang llvm diffutils
# cargo install --git https://github.com/zombodb/pg-schema-diff.git

# - name: Extract pgrx Version & Install cargo-pgrx
# run: |
# PGRX_VERSION=$(cargo tree --depth 1 -i pgrx -p pg_analytics | head -n 1 | cut -f2 -dv)
# cargo install -j $(nproc) --locked cargo-pgrx --version ${PGRX_VERSION}
# cargo pgrx init "--pg${{ env.pg_version }}=/usr/lib/postgresql/${{ env.pg_version }}/bin/pg_config"

# # Save the pgrx version for comparison later
# echo "FIRST_PGRX_VERSION=${PGRX_VERSION}" >> $GITHUB_ENV

# - name: Generate Schema from this git rev
# run: cargo pgrx schema -p pg_analytics pg${{ env.pg_version }} > ~/this.sql

# - name: Switch to Base git rev and Generate Schema Again
# run: |
# # Switch to the base git rev
# git checkout .
# git checkout ${{ github.event.pull_request.base.ref }}

# # See if we need a different cargo-pgrx and install it if so
# THIS_PGRX_VERSION=$(cargo tree --depth 1 -i pgrx -p pg_analytics | head -n 1 | cut -f2 -dv)
# if [[ "${THIS_PGRX_VERSION}" != "${FIRST_PGRX_VERSION}" ]]; then
# # Install cargo-pgrx
# cargo install -j $(nproc) --locked cargo-pgrx --version ${THIS_PGRX_VERSION} --force

# # Initialize it (again) -- probably unnecessary, but might as well in case ~/.pgrx/config.toml ever changes
# cargo pgrx init "--pg${{ env.pg_version }}=/usr/lib/postgresql/${{ env.pg_version }}/bin/pg_config"
# fi

# # Generate schema
# cargo pgrx schema -p pg_analytics pg${{ env.pg_version }} > ~/old.sql

# - name: Generate Schema Diffs
# run: |
# (pg-schema-diff diff ~/old.sql ~/this.sql | grep -v "^$" > ~/diff.sql) || true
# (diff ~/old.sql ~/this.sql > ~/diff.patch) || true

# - name: Generate Commit Message
# id: generate_commit_message
# run: |
# if test -s ~/diff.sql; then
# echo "Generating GitHub comment message"
# {
# echo 'DIFF<<EOF'
# echo 'A schema difference was detected.'
# echo
# echo 'A suggested "upgrade.sql" script entry might be:'
# echo
# echo '```sql'
# cat ~/diff.sql
# echo '```'

# #
# # cargo-pgrx schema doesn't output its generated schema in a stable format
# # so including the entire diff is garbage. We still generate it, tho, because
# # cargo-pgrx will improve someday, and when it does we can uncomment these lines
# #

# # echo
# # echo 'The full diff between both schemas is:'
# # echo
# # echo '```diff'
# # cat ~/diff.patch
# # echo '```'
# echo EOF
# } >> "$GITHUB_ENV"

# # Set a flag to indicate a schema difference was detected
# echo "schema_diff_detected=true" >> $GITHUB_OUTPUT
# else
# echo "No schema difference detected"
# echo "schema_diff_detected=false" >> $GITHUB_OUTPUT
# fi

# - name: Attach Schema Diff to PR
# uses: actions/github-script@v6
# if: steps.generate_commit_message.outputs.schema_diff_detected == 'true'
# with:
# script: |
# github.rest.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: process.env.DIFF
# })
# workflows/check-pg_analytics-schema-upgrade.yml
#
# Check pg_analytics Schema Upgrade pg_analytics
# Determine if a commit introduces an extension schema change for pg_analytics.

name: Check pg_analytics Schema Upgrade

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- dev
- main
paths:
- ".github/workflows/check-pg_analytics-schema-upgrade.yml"
- "pg_analytics/**"
- "!pg_analytics/README.md"
workflow_dispatch:

# Required to post a comment to the PR
permissions:
pull-requests: write

concurrency:
group: check-pg_analytics-schema-upgrade-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
check-pg_analytics-schema-upgrade:
name: Post Schema Change to PR
runs-on: depot-ubuntu-latest-8
if: github.event.pull_request.draft == false
env:
pg_version: 13 # Required by pg-schema-diff

steps:
- name: Checkout Git Repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch the entire history

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

# Caches from base branches are available to PRs, but not across unrelated branches, so we only
# save the cache on the 'dev' branch, but load it on all branches.
- name: Install Rust Cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: "v1"
shared-key: ${{ runner.os }}-rust-cache-pg_analytics-${{ HashFiles('Cargo.lock') }}
cache-targets: true
cache-on-failure: true
cache-all-crates: true
save-if: ${{ github.ref == 'refs/heads/dev' }}

- name: Install & Configure Supported PostgreSQL Version
run: |
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update && sudo apt-get install -y postgresql-${{ env.pg_version }} postgresql-server-dev-${{ env.pg_version }}
sudo chown -R $(whoami) /usr/share/postgresql/${{ env.pg_version }}/ /usr/lib/postgresql/${{ env.pg_version }}/ /var/lib/postgresql/${{ env.pg_version }}/
rustup component add llvm-tools-preview
echo "/usr/lib/postgresql/${{ env.pg_version }}/bin" >> $GITHUB_PATH

- name: Install pg-schema-diff and its Required Dependencies
run: |
sudo apt install clang llvm diffutils
cargo install --git https://github.com/zombodb/pg-schema-diff.git

- name: Extract pgrx Version & Install cargo-pgrx
run: |
PGRX_VERSION=$(cargo tree --depth 1 -i pgrx -p pg_analytics | head -n 1 | cut -f2 -dv)
cargo install -j $(nproc) --locked cargo-pgrx --version ${PGRX_VERSION}
cargo pgrx init "--pg${{ env.pg_version }}=/usr/lib/postgresql/${{ env.pg_version }}/bin/pg_config"

# Save the pgrx version for comparison later
echo "FIRST_PGRX_VERSION=${PGRX_VERSION}" >> $GITHUB_ENV

- name: Generate Schema from this git rev
run: cargo pgrx schema -p pg_analytics pg${{ env.pg_version }} > ~/this.sql

- name: Switch to Base git rev and Generate Schema Again
run: |
# Switch to the base git rev
git checkout .
git checkout ${{ github.event.pull_request.base.ref }}

# See if we need a different cargo-pgrx and install it if so
THIS_PGRX_VERSION=$(cargo tree --depth 1 -i pgrx -p pg_analytics | head -n 1 | cut -f2 -dv)
if [[ "${THIS_PGRX_VERSION}" != "${FIRST_PGRX_VERSION}" ]]; then
# Install cargo-pgrx
cargo install -j $(nproc) --locked cargo-pgrx --version ${THIS_PGRX_VERSION} --force

# Initialize it (again) -- probably unnecessary, but might as well in case ~/.pgrx/config.toml ever changes
cargo pgrx init "--pg${{ env.pg_version }}=/usr/lib/postgresql/${{ env.pg_version }}/bin/pg_config"
fi

# Generate schema
cargo pgrx schema -p pg_analytics pg${{ env.pg_version }} > ~/old.sql

- name: Generate Schema Diffs
run: |
(pg-schema-diff diff ~/old.sql ~/this.sql | grep -v "^$" > ~/diff.sql) || true
(diff ~/old.sql ~/this.sql > ~/diff.patch) || true

- name: Generate Commit Message
id: generate_commit_message
run: |
if test -s ~/diff.sql; then
echo "Generating GitHub comment message"
{
echo 'DIFF<<EOF'
echo 'A schema difference was detected.'
echo
echo 'A suggested "upgrade.sql" script entry might be:'
echo
echo '```sql'
cat ~/diff.sql
echo '```'

#
# Include the full schema diff, for informational purposes
#

echo
echo '<details>'
echo '<summary>The full diff between both schemas is:</summary>'
echo
echo '```diff'
cat ~/diff.patch
echo '```'
echo '</details>'
echo EOF
} >> "$GITHUB_ENV"

# Set a flag to indicate a schema difference was detected
echo "schema_diff_detected=true" >> $GITHUB_OUTPUT
else
echo "No schema difference detected"
echo "schema_diff_detected=false" >> $GITHUB_OUTPUT
fi

- name: Attach Schema Diff to PR
uses: actions/github-script@v6
if: steps.generate_commit_message.outputs.schema_diff_detected == 'true'
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.DIFF
})
40 changes: 40 additions & 0 deletions .github/workflows/publish-pg_analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ jobs:
matrix:
include:
# Ubuntu 22.04
- runner: depot-ubuntu-latest-8
image: ubuntu:22.04
pg_version: 13
arch: amd64
- runner: depot-ubuntu-latest-arm-4
image: ubuntu:22.04
pg_version: 13
arch: arm64
- runner: depot-ubuntu-latest-8
image: ubuntu:22.04
pg_version: 14
Expand Down Expand Up @@ -68,6 +76,14 @@ jobs:
pg_version: 17
arch: arm64
# Ubuntu 24.04
- runner: depot-ubuntu-latest-8
image: ubuntu:24.04
pg_version: 13
arch: amd64
- runner: depot-ubuntu-latest-arm-4
image: ubuntu:24.04
pg_version: 13
arch: arm64
- runner: depot-ubuntu-latest-8
image: ubuntu:24.04
pg_version: 14
Expand Down Expand Up @@ -101,6 +117,14 @@ jobs:
pg_version: 17
arch: arm64
# Debian 12
- runner: depot-ubuntu-latest-8
image: debian:12-slim
pg_version: 13
arch: amd64
- runner: depot-ubuntu-latest-arm-4
image: debian:12-slim
pg_version: 13
arch: arm64
- runner: depot-ubuntu-latest-8
image: debian:12-slim
pg_version: 14
Expand Down Expand Up @@ -134,6 +158,14 @@ jobs:
pg_version: 17
arch: arm64
# Red Hat Enterprise Linux 8
- runner: depot-ubuntu-latest-8
image: redhat/ubi8:latest
pg_version: 13
arch: amd64
- runner: depot-ubuntu-latest-arm-4
image: redhat/ubi8:latest
pg_version: 13
arch: arm64
- runner: depot-ubuntu-latest-8
image: redhat/ubi8:latest
pg_version: 14
Expand Down Expand Up @@ -167,6 +199,14 @@ jobs:
pg_version: 17
arch: arm64
# Red Hat Enterprise Linux 9
- runner: depot-ubuntu-latest-8
image: redhat/ubi9:latest
pg_version: 13
arch: amd64
- runner: depot-ubuntu-latest-arm-4
image: redhat/ubi9:latest
pg_version: 13
arch: arm64
- runner: depot-ubuntu-latest-8
image: redhat/ubi9:latest
pg_version: 14
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test-pg_analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
strategy:
matrix:
include:
- runner: depot-ubuntu-latest-16
pg_version: 13
arch: amd64
- runner: depot-ubuntu-latest-16
pg_version: 14
arch: amd64
Expand Down
Loading
Loading