-
Notifications
You must be signed in to change notification settings - Fork 7
210 lines (150 loc) · 7.73 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: Test extension
# Run this workflow every time a new commit pushed to your repository
on:
push:
branches: ['*']
#branches-ignore: 'master'
pull_request:
branches: ['*']
#branches-ignore: 'master'
workflow_dispatch:
defaults:
run:
shell: bash
jobs:
pr-test:
name: Test the extension
runs-on: ${{ matrix.os }}
env:
EXTENSION_NAME: pgtelemetry
EXTENSION_DB: ajtest
EXTENSION_BRANCH: master
EXTENSION_SUBDIRECTORY: ""
EXTENSION_TEST_QUERY: ""
strategy:
matrix:
# also test 'latest', eventually this will be upgraded to a newer version and might fail early
#os: [ubuntu-18.04, ubuntu-20.04, ubuntu-latest]
os: [ubuntu-latest]
#postgresql: [9.6, 10, 11, 12, 13, 14, 15]
postgresql: [11, 12, 14, 15]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Versions
run: echo "${{ matrix.os }} - ${{ matrix.postgresql }}"
- name: Calculate working directory
run: echo "PWD=$(realpath ./$EXTENSION_SUBDIRECTORY)" >> $GITHUB_OUTPUT
id: pwd
- name: Working directory
run: echo "${{ steps.pwd.outputs.PWD }}"
# GitHub does only checkout the current branch
# in case this is a PR the check also needs $EXTENSION_BRANCH for the .control file
- name: get branch
run: git fetch --depth=5 origin $EXTENSION_BRANCH
- name: See the .control file
run: git show origin/$EXTENSION_BRANCH:$EXTENSION_SUBDIRECTORY$EXTENSION_NAME.control
# there might be PostgreSQL packages pre-installed, remove them
- name: Installed PostgreSQL packages
run: dpkg --list | grep postgresql
- name: Get list of PostgreSQL packages
run: echo "Packages=$(dpkg-query -f '${Package}\n' -W | grep ^postgresql | xargs)" >> $GITHUB_OUTPUT
id: preinstalled_packages
- name: Remove preinstalled PostgreSQL packages
run: sudo dpkg --purge ${{ steps.preinstalled_packages.outputs.Packages }}
# verify result
- name: Installed PostgreSQL packages
run: dpkg --list | grep postgresql
continue-on-error: true
# install build tools
- name: Install build-essential and other tools
run: sudo apt-get install -y build-essential ruby curl ca-certificates gnupg
# enable PostgreSQL APT repository
- name: Install GPG Key for PostgreSQL repository
run: curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
- name: Install repository
run: sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
- name: Update repository
run: sudo apt-get update
# install the requested version
- name: Install PostgreSQL
run: sudo apt-get install -y postgresql-${{ matrix.postgresql }} postgresql-server-dev-${{ matrix.postgresql }} postgresql-client-${{ matrix.postgresql }}
# debug output
- name: Path of pg_config
run: which pg_config
- name: pg_config output
run: pg_config
- name: Update pg_hba.conf
run: sudo bash -c "echo 'local all all trust' > /etc/postgresql/${{ matrix.postgresql }}/main/pg_hba.conf"
- name: Update pg_hba.conf
run: sudo bash -c "echo 'host all all 0/0 trust' >> /etc/postgresql/${{ matrix.postgresql }}/main/pg_hba.conf"
- name: Restart PostgreSQL
run: sudo service postgresql reload
# do the actual compilation
- name: Compile the extension
run: cd ${{ steps.pwd.outputs.PWD }} && make
- name: Test the extension
run: cd ${{ steps.pwd.outputs.PWD }} && make check
# install extension
- name: Install the extension
run: cd ${{ steps.pwd.outputs.PWD }} && sudo make install
- name: Update postgresql.auto.conf
run: sudo bash -c "echo 'shared_preload_libraries = ''pg_stat_statements''' >> /etc/postgresql/${{ matrix.postgresql }}/main/postgresql.auto.conf"
- name: Restart PostgreSQL
run: sudo service postgresql restart
- name: Test the extension
run: cd ${{ steps.pwd.outputs.PWD }} && make PGUSER=postgres installcheck
- name: Show regression.out
run: cat ${{ steps.pwd.outputs.PWD }}/regression.out
if: ${{ failure() }}
- name: Show regression.diffs
run: cat ${{ steps.pwd.outputs.PWD }}/regression.diffs
if: ${{ failure() }}
# start testing
- name: Get current branch name
run: echo "Packages=$(git branch --show-current)" >> $GITHUB_OUTPUT
id: current_branch
# in a PR this version might be different
- name: Get current extension version
run: echo "Version=$(cat $EXTENSION_SUBDIRECTORY$EXTENSION_NAME.control | grep default_version | sed 's/[^0-9\.]*//g')" >> $GITHUB_OUTPUT
id: current_extension_version
# the version from the branch in $EXTENSION_BRANCH
- name: Get installed extension version
run: echo "Version=$(git show origin/$EXTENSION_BRANCH:$EXTENSION_SUBDIRECTORY$EXTENSION_NAME.control | grep default_version | sed 's/[^0-9\.]*//g')" >> $GITHUB_OUTPUT
id: installed_extension_version
- name: Show versions
run: echo "${{ steps.installed_extension_version.outputs.Version }} - ${{ steps.current_extension_version.outputs.Version }}"
- name: Test current version string
run: exit 1
if: steps.current_extension_version.outputs.Version == ''
- name: Test installed version string
run: exit 1
if: steps.installed_extension_version.outputs.Version == ''
- name: Create test database
run: createdb -U postgres $EXTENSION_DB
# install the version from $EXTENSION_BRANCH
- name: Install pg_stat_statements extension in database
run: psql -U postgres -c "CREATE EXTENSION pg_stat_statements" $EXTENSION_DB
- name: Install extension in database
run: psql -U postgres -c "CREATE EXTENSION $EXTENSION_NAME VERSION '${{ steps.installed_extension_version.outputs.Version }}'" $EXTENSION_DB
- name: Get extension version installed in the database - Step 1
run: psql -U postgres -A -q -t -o /tmp/installed_version_step_1.txt -c "SELECT extversion FROM pg_catalog.pg_extension WHERE extname='$EXTENSION_NAME'" $EXTENSION_DB
- name: Get extension version installed in the database - Step 2
run: echo "Version=$(cat /tmp/installed_version_step_1.txt)" >> $GITHUB_OUTPUT
id: installed_version_step_1
- name: Show installed version - after extension install
run: echo "${{ steps.installed_version_step_1.outputs.Version }}"
# if this is a PR, the version might be different - try an extension upgrade in this case
- name: Upgrade extension in database
run: psql -U postgres -c "ALTER EXTENSION $EXTENSION_NAME UPDATE TO '${{ steps.current_extension_version.outputs.Version }}'" $EXTENSION_DB
if: steps.installed_extension_version.outputs.Version != steps.current_extension_version.outputs.Version
- name: Get extension version installed in the database - Step 1
run: psql -U postgres -A -q -t -o /tmp/installed_version_step_2.txt -c "SELECT extversion FROM pg_catalog.pg_extension WHERE extname='$EXTENSION_NAME'" $EXTENSION_DB
- name: Get extension version installed in the database - Step 2
run: echo "Version=$(cat /tmp/installed_version_step_2.txt)" >> $GITHUB_OUTPUT
id: installed_version_step_2
- name: Show installed version - after extension update
run: echo "${{ steps.installed_version_step_2.outputs.Version }}"
- name: Run test query
run: psql -U postgres -c "$EXTENSION_TEST_QUERY" $EXTENSION_DB
if: env.EXTENSION_TEST_QUERY != ''