|
1 |
| -# TODO: Uncomment once we have PG13 support, which is required for pg-schema-diff |
2 |
| -# # workflows/check-pg_analytics-schema-upgrade.yml |
3 |
| -# # |
4 |
| -# # Check pg_analytics Schema Upgrade pg_analytics |
5 |
| -# # Determine if a commit introduces an extension schema change for pg_analytics. |
6 |
| - |
7 |
| -# name: Check pg_analytics Schema Upgrade |
8 |
| - |
9 |
| -# on: |
10 |
| -# pull_request: |
11 |
| -# types: [opened, synchronize, reopened, ready_for_review] |
12 |
| -# branches: |
13 |
| -# - dev |
14 |
| -# - main |
15 |
| -# paths: |
16 |
| -# - ".github/workflows/check-pg_analytics-schema-upgrade.yml" |
17 |
| -# - "pg_analytics/**" |
18 |
| -# - "!pg_analytics/README.md" |
19 |
| -# workflow_dispatch: |
20 |
| - |
21 |
| -# # Required to post a comment to the PR |
22 |
| -# permissions: |
23 |
| -# pull-requests: write |
24 |
| - |
25 |
| -# concurrency: |
26 |
| -# group: check-pg_analytics-schema-upgrade-${{ github.head_ref || github.ref }} |
27 |
| -# cancel-in-progress: true |
28 |
| - |
29 |
| -# jobs: |
30 |
| -# check-pg_analytics-schema-upgrade: |
31 |
| -# name: Post Schema Change to PR |
32 |
| -# runs-on: depot-ubuntu-latest-8 |
33 |
| -# if: github.event.pull_request.draft == false |
34 |
| -# env: |
35 |
| -# pg_version: 13 # Required by pg-schema-diff |
36 |
| - |
37 |
| -# steps: |
38 |
| -# - name: Checkout Git Repository |
39 |
| -# uses: actions/checkout@v4 |
40 |
| -# with: |
41 |
| -# fetch-depth: 0 # Fetch the entire history |
42 |
| - |
43 |
| -# - name: Install Rust |
44 |
| -# uses: dtolnay/rust-toolchain@stable |
45 |
| - |
46 |
| -# # Caches from base branches are available to PRs, but not across unrelated branches, so we only |
47 |
| -# # save the cache on the 'dev' branch, but load it on all branches. |
48 |
| -# - name: Install Rust Cache |
49 |
| -# uses: Swatinem/rust-cache@v2 |
50 |
| -# with: |
51 |
| -# prefix-key: "v1" |
52 |
| -# shared-key: ${{ runner.os }}-rust-cache-pg_analytics-${{ HashFiles('Cargo.lock') }} |
53 |
| -# cache-targets: true |
54 |
| -# cache-on-failure: true |
55 |
| -# cache-all-crates: true |
56 |
| -# save-if: ${{ github.ref == 'refs/heads/dev' }} |
57 |
| - |
58 |
| -# - name: Install & Configure Supported PostgreSQL Version |
59 |
| -# run: | |
60 |
| -# wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - |
61 |
| -# sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' |
62 |
| -# sudo apt-get update && sudo apt-get install -y postgresql-${{ env.pg_version }} postgresql-server-dev-${{ env.pg_version }} |
63 |
| -# sudo chown -R $(whoami) /usr/share/postgresql/${{ env.pg_version }}/ /usr/lib/postgresql/${{ env.pg_version }}/ /var/lib/postgresql/${{ env.pg_version }}/ |
64 |
| -# rustup component add llvm-tools-preview |
65 |
| -# echo "/usr/lib/postgresql/${{ env.pg_version }}/bin" >> $GITHUB_PATH |
66 |
| - |
67 |
| -# - name: Install pg-schema-diff and its Required Dependencies |
68 |
| -# run: | |
69 |
| -# sudo apt install clang llvm diffutils |
70 |
| -# cargo install --git https://github.com/zombodb/pg-schema-diff.git |
71 |
| - |
72 |
| -# - name: Extract pgrx Version & Install cargo-pgrx |
73 |
| -# run: | |
74 |
| -# PGRX_VERSION=$(cargo tree --depth 1 -i pgrx -p pg_analytics | head -n 1 | cut -f2 -dv) |
75 |
| -# cargo install -j $(nproc) --locked cargo-pgrx --version ${PGRX_VERSION} |
76 |
| -# cargo pgrx init "--pg${{ env.pg_version }}=/usr/lib/postgresql/${{ env.pg_version }}/bin/pg_config" |
77 |
| - |
78 |
| -# # Save the pgrx version for comparison later |
79 |
| -# echo "FIRST_PGRX_VERSION=${PGRX_VERSION}" >> $GITHUB_ENV |
80 |
| - |
81 |
| -# - name: Generate Schema from this git rev |
82 |
| -# run: cargo pgrx schema -p pg_analytics pg${{ env.pg_version }} > ~/this.sql |
83 |
| - |
84 |
| -# - name: Switch to Base git rev and Generate Schema Again |
85 |
| -# run: | |
86 |
| -# # Switch to the base git rev |
87 |
| -# git checkout . |
88 |
| -# git checkout ${{ github.event.pull_request.base.ref }} |
89 |
| - |
90 |
| -# # See if we need a different cargo-pgrx and install it if so |
91 |
| -# THIS_PGRX_VERSION=$(cargo tree --depth 1 -i pgrx -p pg_analytics | head -n 1 | cut -f2 -dv) |
92 |
| -# if [[ "${THIS_PGRX_VERSION}" != "${FIRST_PGRX_VERSION}" ]]; then |
93 |
| -# # Install cargo-pgrx |
94 |
| -# cargo install -j $(nproc) --locked cargo-pgrx --version ${THIS_PGRX_VERSION} --force |
95 |
| - |
96 |
| -# # Initialize it (again) -- probably unnecessary, but might as well in case ~/.pgrx/config.toml ever changes |
97 |
| -# cargo pgrx init "--pg${{ env.pg_version }}=/usr/lib/postgresql/${{ env.pg_version }}/bin/pg_config" |
98 |
| -# fi |
99 |
| - |
100 |
| -# # Generate schema |
101 |
| -# cargo pgrx schema -p pg_analytics pg${{ env.pg_version }} > ~/old.sql |
102 |
| - |
103 |
| -# - name: Generate Schema Diffs |
104 |
| -# run: | |
105 |
| -# (pg-schema-diff diff ~/old.sql ~/this.sql | grep -v "^$" > ~/diff.sql) || true |
106 |
| -# (diff ~/old.sql ~/this.sql > ~/diff.patch) || true |
107 |
| - |
108 |
| -# - name: Generate Commit Message |
109 |
| -# id: generate_commit_message |
110 |
| -# run: | |
111 |
| -# if test -s ~/diff.sql; then |
112 |
| -# echo "Generating GitHub comment message" |
113 |
| -# { |
114 |
| -# echo 'DIFF<<EOF' |
115 |
| -# echo 'A schema difference was detected.' |
116 |
| -# echo |
117 |
| -# echo 'A suggested "upgrade.sql" script entry might be:' |
118 |
| -# echo |
119 |
| -# echo '```sql' |
120 |
| -# cat ~/diff.sql |
121 |
| -# echo '```' |
122 |
| - |
123 |
| -# # |
124 |
| -# # cargo-pgrx schema doesn't output its generated schema in a stable format |
125 |
| -# # so including the entire diff is garbage. We still generate it, tho, because |
126 |
| -# # cargo-pgrx will improve someday, and when it does we can uncomment these lines |
127 |
| -# # |
128 |
| - |
129 |
| -# # echo |
130 |
| -# # echo 'The full diff between both schemas is:' |
131 |
| -# # echo |
132 |
| -# # echo '```diff' |
133 |
| -# # cat ~/diff.patch |
134 |
| -# # echo '```' |
135 |
| -# echo EOF |
136 |
| -# } >> "$GITHUB_ENV" |
137 |
| - |
138 |
| -# # Set a flag to indicate a schema difference was detected |
139 |
| -# echo "schema_diff_detected=true" >> $GITHUB_OUTPUT |
140 |
| -# else |
141 |
| -# echo "No schema difference detected" |
142 |
| -# echo "schema_diff_detected=false" >> $GITHUB_OUTPUT |
143 |
| -# fi |
144 |
| - |
145 |
| -# - name: Attach Schema Diff to PR |
146 |
| -# uses: actions/github-script@v6 |
147 |
| -# if: steps.generate_commit_message.outputs.schema_diff_detected == 'true' |
148 |
| -# with: |
149 |
| -# script: | |
150 |
| -# github.rest.issues.createComment({ |
151 |
| -# issue_number: context.issue.number, |
152 |
| -# owner: context.repo.owner, |
153 |
| -# repo: context.repo.repo, |
154 |
| -# body: process.env.DIFF |
155 |
| -# }) |
| 1 | +# workflows/check-pg_analytics-schema-upgrade.yml |
| 2 | +# |
| 3 | +# Check pg_analytics Schema Upgrade pg_analytics |
| 4 | +# Determine if a commit introduces an extension schema change for pg_analytics. |
| 5 | + |
| 6 | +name: Check pg_analytics Schema Upgrade |
| 7 | + |
| 8 | +on: |
| 9 | + pull_request: |
| 10 | + types: [opened, synchronize, reopened, ready_for_review] |
| 11 | + branches: |
| 12 | + - dev |
| 13 | + - main |
| 14 | + paths: |
| 15 | + - ".github/workflows/check-pg_analytics-schema-upgrade.yml" |
| 16 | + - "pg_analytics/**" |
| 17 | + - "!pg_analytics/README.md" |
| 18 | + workflow_dispatch: |
| 19 | + |
| 20 | +# Required to post a comment to the PR |
| 21 | +permissions: |
| 22 | + pull-requests: write |
| 23 | + |
| 24 | +concurrency: |
| 25 | + group: check-pg_analytics-schema-upgrade-${{ github.head_ref || github.ref }} |
| 26 | + cancel-in-progress: true |
| 27 | + |
| 28 | +jobs: |
| 29 | + check-pg_analytics-schema-upgrade: |
| 30 | + name: Post Schema Change to PR |
| 31 | + runs-on: depot-ubuntu-latest-8 |
| 32 | + if: github.event.pull_request.draft == false |
| 33 | + env: |
| 34 | + pg_version: 13 # Required by pg-schema-diff |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout Git Repository |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + fetch-depth: 0 # Fetch the entire history |
| 41 | + |
| 42 | + - name: Install Rust |
| 43 | + uses: dtolnay/rust-toolchain@stable |
| 44 | + |
| 45 | + # Caches from base branches are available to PRs, but not across unrelated branches, so we only |
| 46 | + # save the cache on the 'dev' branch, but load it on all branches. |
| 47 | + - name: Install Rust Cache |
| 48 | + uses: Swatinem/rust-cache@v2 |
| 49 | + with: |
| 50 | + prefix-key: "v1" |
| 51 | + shared-key: ${{ runner.os }}-rust-cache-pg_analytics-${{ HashFiles('Cargo.lock') }} |
| 52 | + cache-targets: true |
| 53 | + cache-on-failure: true |
| 54 | + cache-all-crates: true |
| 55 | + save-if: ${{ github.ref == 'refs/heads/dev' }} |
| 56 | + |
| 57 | + - name: Install & Configure Supported PostgreSQL Version |
| 58 | + run: | |
| 59 | + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - |
| 60 | + sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' |
| 61 | + sudo apt-get update && sudo apt-get install -y postgresql-${{ env.pg_version }} postgresql-server-dev-${{ env.pg_version }} |
| 62 | + sudo chown -R $(whoami) /usr/share/postgresql/${{ env.pg_version }}/ /usr/lib/postgresql/${{ env.pg_version }}/ /var/lib/postgresql/${{ env.pg_version }}/ |
| 63 | + rustup component add llvm-tools-preview |
| 64 | + echo "/usr/lib/postgresql/${{ env.pg_version }}/bin" >> $GITHUB_PATH |
| 65 | +
|
| 66 | + - name: Install pg-schema-diff and its Required Dependencies |
| 67 | + run: | |
| 68 | + sudo apt install clang llvm diffutils |
| 69 | + cargo install --git https://github.com/zombodb/pg-schema-diff.git |
| 70 | +
|
| 71 | + - name: Extract pgrx Version & Install cargo-pgrx |
| 72 | + run: | |
| 73 | + PGRX_VERSION=$(cargo tree --depth 1 -i pgrx -p pg_analytics | head -n 1 | cut -f2 -dv) |
| 74 | + cargo install -j $(nproc) --locked cargo-pgrx --version ${PGRX_VERSION} |
| 75 | + cargo pgrx init "--pg${{ env.pg_version }}=/usr/lib/postgresql/${{ env.pg_version }}/bin/pg_config" |
| 76 | +
|
| 77 | + # Save the pgrx version for comparison later |
| 78 | + echo "FIRST_PGRX_VERSION=${PGRX_VERSION}" >> $GITHUB_ENV |
| 79 | +
|
| 80 | + - name: Generate Schema from this git rev |
| 81 | + run: cargo pgrx schema -p pg_analytics pg${{ env.pg_version }} > ~/this.sql |
| 82 | + |
| 83 | + - name: Switch to Base git rev and Generate Schema Again |
| 84 | + run: | |
| 85 | + # Switch to the base git rev |
| 86 | + git checkout . |
| 87 | + git checkout ${{ github.event.pull_request.base.ref }} |
| 88 | +
|
| 89 | + # See if we need a different cargo-pgrx and install it if so |
| 90 | + THIS_PGRX_VERSION=$(cargo tree --depth 1 -i pgrx -p pg_analytics | head -n 1 | cut -f2 -dv) |
| 91 | + if [[ "${THIS_PGRX_VERSION}" != "${FIRST_PGRX_VERSION}" ]]; then |
| 92 | + # Install cargo-pgrx |
| 93 | + cargo install -j $(nproc) --locked cargo-pgrx --version ${THIS_PGRX_VERSION} --force |
| 94 | +
|
| 95 | + # Initialize it (again) -- probably unnecessary, but might as well in case ~/.pgrx/config.toml ever changes |
| 96 | + cargo pgrx init "--pg${{ env.pg_version }}=/usr/lib/postgresql/${{ env.pg_version }}/bin/pg_config" |
| 97 | + fi |
| 98 | +
|
| 99 | + # Generate schema |
| 100 | + cargo pgrx schema -p pg_analytics pg${{ env.pg_version }} > ~/old.sql |
| 101 | +
|
| 102 | + - name: Generate Schema Diffs |
| 103 | + run: | |
| 104 | + (pg-schema-diff diff ~/old.sql ~/this.sql | grep -v "^$" > ~/diff.sql) || true |
| 105 | + (diff ~/old.sql ~/this.sql > ~/diff.patch) || true |
| 106 | +
|
| 107 | + - name: Generate Commit Message |
| 108 | + id: generate_commit_message |
| 109 | + run: | |
| 110 | + if test -s ~/diff.sql; then |
| 111 | + echo "Generating GitHub comment message" |
| 112 | + { |
| 113 | + echo 'DIFF<<EOF' |
| 114 | + echo 'A schema difference was detected.' |
| 115 | + echo |
| 116 | + echo 'A suggested "upgrade.sql" script entry might be:' |
| 117 | + echo |
| 118 | + echo '```sql' |
| 119 | + cat ~/diff.sql |
| 120 | + echo '```' |
| 121 | +
|
| 122 | + # |
| 123 | + # Include the full schema diff, for informational purposes |
| 124 | + # |
| 125 | +
|
| 126 | + echo |
| 127 | + echo '<details>' |
| 128 | + echo '<summary>The full diff between both schemas is:</summary>' |
| 129 | + echo |
| 130 | + echo '```diff' |
| 131 | + cat ~/diff.patch |
| 132 | + echo '```' |
| 133 | + echo '</details>' |
| 134 | + echo EOF |
| 135 | + } >> "$GITHUB_ENV" |
| 136 | +
|
| 137 | + # Set a flag to indicate a schema difference was detected |
| 138 | + echo "schema_diff_detected=true" >> $GITHUB_OUTPUT |
| 139 | + else |
| 140 | + echo "No schema difference detected" |
| 141 | + echo "schema_diff_detected=false" >> $GITHUB_OUTPUT |
| 142 | + fi |
| 143 | +
|
| 144 | + - name: Attach Schema Diff to PR |
| 145 | + uses: actions/github-script@v6 |
| 146 | + if: steps.generate_commit_message.outputs.schema_diff_detected == 'true' |
| 147 | + with: |
| 148 | + script: | |
| 149 | + github.rest.issues.createComment({ |
| 150 | + issue_number: context.issue.number, |
| 151 | + owner: context.repo.owner, |
| 152 | + repo: context.repo.repo, |
| 153 | + body: process.env.DIFF |
| 154 | + }) |
0 commit comments