-
Notifications
You must be signed in to change notification settings - Fork 1.1k
205 lines (173 loc) · 7.8 KB
/
Copy pathtests-fail-on-old-code.yaml
File metadata and controls
205 lines (173 loc) · 7.8 KB
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
# This workflow verifies that new tests fail when run against old code.
# It helps ensure tests are actually testing the new functionality.
name: Tests should fail on old code
"on":
pull_request:
jobs:
verify-tests-fail:
name: Verify tests fail on old code
runs-on: timescaledb-runner-arm64
env:
PG_SRC_DIR: pgbuild
PG_INSTALL_DIR: postgresql
CODE_PATHS: src/ tsl/src/ test/src tsl/test/src sql/
steps:
- name: Checkout TimescaleDB
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Set PostgreSQL version
id: pg
run: |
MAJOR=17
echo "major=$MAJOR" >> $GITHUB_OUTPUT
# Choose the latest version from config that matches our major version.
# This weird quote handling in sed is to remove the quotes around the
# value that the config reader produces, i.e. version="17.7".
GITHUB_OUTPUT=/dev/stdout .github/gh_config_reader.py \
| sed -n "s/PG${MAJOR}_LATEST=\"\([^\"]*\)\"/version=\1/p" \
>> $GITHUB_OUTPUT
- name: Check for code and test changes
id: check
run: |
set -euo pipefail
git fetch origin ${{ github.base_ref }}:base
# Use merge-base to only see changes introduced by the PR.
# Main can advance after the PR merge ref was created, so
# diffing against the fetched main directly would pick up
# unrelated changes.
MERGE_BASE=$(git merge-base base HEAD)
echo "Looking at PR event ref $(git rev-parse @), base $(git rev-parse base), merge base ${MERGE_BASE}"
# Code changes: anything under src/ directories
readarray -t CODE_CHANGES < <(git diff --name-only "$MERGE_BASE" HEAD -- $CODE_PATHS)
if ! ((${#CODE_CHANGES[@]}))
then
echo "No code changes found, skipping"
echo "should_run=false" >> $GITHUB_OUTPUT
exit 0
fi
# Test changes: changed .out files under test/expected directories.
# For versioned test outputs, we should only check the version that
# matches the Postgers version we build.
readarray -t CHANGED_TESTS < <( \
git diff --name-only "$MERGE_BASE" HEAD -- test/expected test/isolation/expected \
tsl/test/expected tsl/test/isolation/expected tsl/test/shared/expected \
| sed -n 's!^.*expected/\([^/ -]\+\(-${{ steps.pg.outputs.major }}\)\?\)\.out$!\1!gp')
if ! ((${#CHANGED_TESTS[@]}))
then
echo "No test output changes found, skipping"
echo "should_run=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "Changed tests: ${CHANGED_TESTS[*]}"
echo "should_run=true" >> $GITHUB_OUTPUT
echo "changed_tests=${CHANGED_TESTS[*]}" >> $GITHUB_OUTPUT
- name: Install Linux Dependencies
if: steps.check.outputs.should_run == 'true'
timeout-minutes: 15
run: |
sudo apt-get update
sudo apt-get install flex bison cmake
# We are going to rebuild Postgres weekly, so that it doesn't suddenly break
# ages after the original problem.
- name: Get date for build caching
if: steps.check.outputs.should_run == 'true'
id: get-date
run: |
echo "date=$(date +"%V")" >> $GITHUB_OUTPUT
# we cache the build directory instead of the install directory here
# because extension installation will write files to install directory
# leading to a tainted cache
- name: Cache PostgreSQL ${{ steps.pg.outputs.version }}
if: steps.check.outputs.should_run == 'true'
id: cache-postgresql
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: ~/${{ env.PG_SRC_DIR }}
key: "pg-${{ steps.pg.outputs.version }}-${{ runner.os }}-${{ runner.arch }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('.github/**') }}"
- name: Build PostgreSQL ${{ steps.pg.outputs.version }}
if: steps.check.outputs.should_run == 'true' && steps.cache-postgresql.outputs.cache-hit != 'true'
run: |
wget -q -O postgresql.tar.bz2 \
https://ftp.postgresql.org/pub/source/v${{ steps.pg.outputs.version }}/postgresql-${{ steps.pg.outputs.version }}.tar.bz2
mkdir -p ~/$PG_SRC_DIR
tar --extract --file postgresql.tar.bz2 --directory ~/$PG_SRC_DIR --strip-components 1
cd ~/$PG_SRC_DIR
./configure --prefix=$HOME/$PG_INSTALL_DIR --with-openssl \
--without-readline --without-zlib --without-libxml --enable-debug \
--enable-cassert
make -j $(getconf _NPROCESSORS_ONLN)
- name: Install PostgreSQL ${{ steps.pg.outputs.version }}
if: steps.check.outputs.should_run == 'true'
run: |
cd ~/$PG_SRC_DIR
make install
echo "$HOME/$PG_INSTALL_DIR/bin" >> $GITHUB_PATH
- name: Revert code changes
if: steps.check.outputs.should_run == 'true'
run: |
git checkout base -- $CODE_PATHS
git status
- name: Build TimescaleDB
if: steps.check.outputs.should_run == 'true'
run: |
cmake -B build -S . \
-DCMAKE_BUILD_TYPE=Debug \
-DPG_SOURCE_DIR=$HOME/$PG_SRC_DIR \
-DPG_PATH=$HOME/$PG_INSTALL_DIR
make -j $(getconf _NPROCESSORS_ONLN) -C build
make -C build install
- name: make installcheck
if: steps.check.outputs.should_run == 'true'
run: |
TESTS="${{ steps.check.outputs.changed_tests }}"
echo "Running tests: $TESTS"
# Run all changed tests together, allow failure
make -C build -k installcheck TESTS="$TESTS" 2>&1 | tee installcheck.log || true
- name: Show regression diffs
if: always() && steps.check.outputs.should_run == 'true'
id: collectlogs
run: |
find . -name regression.diffs -exec cat {} + > regression.log
if [[ -s regression.log ]]; then echo "regression_diff=true" >> $GITHUB_OUTPUT; fi
grep -e 'FAILED' -e 'failed (ignored)' -e 'not ok' installcheck.log || true
cat regression.log
- name: Save regression diffs
if: always() && steps.collectlogs.outputs.regression_diff == 'true'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: Regression diff PG${{ steps.pg.outputs.version }}
path: |
regression.log
installcheck.log
- name: Save PostgreSQL log
if: always() && steps.check.outputs.should_run == 'true'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: PostgreSQL log ${{ steps.pg.outputs.version }}
path: postmaster.*
- name: Verify tests failed on old code
if: steps.check.outputs.should_run == 'true'
run: |
TESTS="${{ steps.check.outputs.changed_tests }}"
# Here we switch on results because there can be variant expected files
# using a _NNN suffix (pg_regress feature).
readarray -t FAILED_TESTS < <( \
sed -n 's!^\+\+\+.*results/\([^/ -]\+\(-${{ steps.pg.outputs.major }}\)\?\)\.out[[:space:]].*$!\1!gp' regression.log)
echo "Tests failing with the old code: ${FAILED_TESTS[*]}"
# Check which changed tests did NOT fail
PASSED_TESTS=""
for TEST in $TESTS; do
if ! echo "${FAILED_TESTS[@]}" | grep -qw "$TEST"; then
PASSED_TESTS="$PASSED_TESTS $TEST"
fi
done
if [[ -n "$PASSED_TESTS" ]]; then
echo "WARNING: The following changed tests PASSED when they should have FAILED:"
echo " $PASSED_TESTS"
echo ""
echo "This suggests these tests may not be testing the new code changes."
echo "Please verify that your tests actually exercise the new functionality."
exit 1
fi
echo "All changed tests failed as expected."