Repository navigation
151 lines (133 loc) · 7.74 KB
/
Copy pathtest.yml
File metadata and controls
151 lines (133 loc) · 7.74 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
name: test
on:
push:
branches: [main]
pull_request:
permissions:
contents: write # the coverage badge is committed back to main
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
# the run boots real PostgreSQL and MySQL servers and initializes databases by the
# hundred; the stock runner's free disk fills up mid-run (TestMigrateProbe died on
# "No space left on device"), so the preinstalled toolchains this job never uses go
- name: Free disk space
run: |
sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc /usr/local/.ghcup /opt/hostedtoolcache/CodeQL
df -h /
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
# pg_dump for the migration side: its major version must be at least the embedded
# server's (17), which Ubuntu's own packages lag behind
- name: Install PostgreSQL 17 client
run: |
sudo install -d /usr/share/postgresql-common/pgdg
sudo curl -fsSL -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt-get update -q
sudo apt-get install -y -q postgresql-client-17
# /usr/bin/pg_dump is Ubuntu's wrapper and picks the default (older) cluster version
echo /usr/lib/postgresql/17/bin >> "$GITHUB_PATH"
/usr/lib/postgresql/17/bin/pg_dump --version
# the embedded PostgreSQL archive, its extracted binaries + initialized template data
# directory (check/postgres/oracle), and PostgreSQL's regression corpus (TestRegress)
- name: Cache PostgreSQL binaries and regress corpus
uses: actions/cache@v4
with:
path: |
~/.embedded-postgres-go
~/.cache/sqlshape
key: sqlshape-pg-${{ hashFiles('check/postgres/oracle/oracle.go', 'check/postgres/analyze/testdata/tools/fetch-regress.sh') }}
- name: Fetch regress corpus
run: check/postgres/analyze/testdata/tools/fetch-regress.sh
# the MySQL tests boot the mysqld on PATH, and it must be 8.4 (the analyzer's measured
# version; the runner's own 8.0 is also AppArmor-confined and cannot write a data
# directory under $HOME). The official minimal tarball runs unconfined from $HOME.
- name: Cache MySQL 8.4
uses: actions/cache@v4
with:
path: ~/mysql-8.4.11
key: sqlshape-mysql-8.4.11-minimal
- name: Install MySQL 8.4
run: |
sudo apt-get install -y -q libaio1t64 libnuma1
# the tarball's mysqld links libaio.so.1; Ubuntu 24.04 ships it as libaio.so.1t64
sudo ln -sf /usr/lib/x86_64-linux-gnu/libaio.so.1t64 /usr/lib/x86_64-linux-gnu/libaio.so.1
if [ ! -x "$HOME/mysql-8.4.11/bin/mysqld" ]; then
curl -fsSL -o /tmp/mysql.tar.xz https://cdn.mysql.com/Downloads/MySQL-8.4/mysql-8.4.11-linux-glibc2.28-x86_64-minimal.tar.xz
tar -xJf /tmp/mysql.tar.xz -C "$HOME"
mv "$HOME/mysql-8.4.11-linux-glibc2.28-x86_64-minimal" "$HOME/mysql-8.4.11"
rm /tmp/mysql.tar.xz
fi
echo "$HOME/mysql-8.4.11/bin" >> "$GITHUB_PATH"
"$HOME/mysql-8.4.11/bin/mysqld" --version
# the binary as users run it: as a vettool over the examples
- name: Smoke test
run: go build -o sqlshape ./cmd/sqlshape && .github/scripts/smoke.sh ./sqlshape
# coverage counts every package except the generators, which are manual tools run
# against a server or its source (check/postgres/catalog/gen, check/mysql's parsegen)
# and the 5-statement main; generated data tables are dropped from the profile the way
# the protobuf node types (check/postgres/pgparse/pg_query.pb.go, 40k lines of
# accessors) are: mysqlast/views.go, mysqlparse's shapes.go / kinds.go and the
# catalog's functions.go / sysvars.go, all written by parsegen from the server source.
# -count=1: a cached test result replays the profile it recorded, with block positions
# from the sources of that run; after an edit to a package the cached package does not
# depend on, the stale blocks no longer line up and the merged total drops by ten points
- name: Test
# the test servers put their data directories on /dev/shm by default; the runner's
# tmpfs (RAM/2) is too small for the parallel suite ("No space left on device"), so
# both escape hatches point at the disk, which the free-space step cleared
env:
SQLSHAPE_ORACLE_DIR: ${{ runner.temp }}
SQLSHAPE_MYSQLTEST_DIR: ${{ runner.temp }}
run: |
# ./... is the root module; the other modules of the workspace are named one by one
# the exclusions name path segments, not full paths, so the /v2/ in the module
# paths cannot silently defeat them (it did: /check/postgres/catalog/gen matched
# nothing once the paths carried /v2/)
pkgs=$(go list ./... ./postgres/... ./mysql/... ./mysqltest/... ./pgtest/... ./cmd/sqlshape/... ./check/postgres/... ./check/mysql/... | grep -v -e /catalog/gen -e /internal/parsegen | paste -sd,)
go test ./... ./postgres/... ./mysql/... ./mysqltest/... ./pgtest/... ./examples/... ./cmd/sqlshape/... ./check/postgres/... ./check/mysql/... -count=1 -coverpkg="$pkgs" -coverprofile=cover.out -timeout 40m
grep -v -e '/pg_query\.pb\.go:' -e '/mysqlast/views\.go:' -e '/mysqlparse/shapes\.go:' -e '/mysqlparse/kinds\.go:' -e '/internal/catalog/functions\.go:' -e '/internal/catalog/sysvars\.go:' cover.out > cover.filtered && mv cover.filtered cover.out
# coverage badge: statement coverage of the whole module, committed as an SVG so the
# README can show it without a third-party service; --min makes it a regression gate
- name: Coverage badge
run: python3 .github/scripts/coverage_badge.py --min 90 cover.out .github/badges/coverage.svg
- name: Commit coverage badge
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .github/badges
if ! git diff --cached --quiet; then
git commit -m "CI: coverage badge [skip ci]"
# main may move while this job runs (e.g. a release commit lands right
# after); rebase and retry instead of failing on non-fast-forward
git push || { git pull --rebase && git push; }
fi
# The analyzer against PostgreSQL 18: the embedded catalog loads, the oracle boots, and
# the regress probe replays 18's corpus (asserting its baseline once there is one).
pg18:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Cache PostgreSQL 18 binaries and regress corpus
uses: actions/cache@v4
with:
path: ~/.cache/sqlshape
key: sqlshape-pg18-${{ hashFiles('check/postgres/oracle/oracle.go', 'check/postgres/analyze/testdata/tools/fetch-regress.sh') }}
- name: Fetch regress corpus
run: check/postgres/analyze/testdata/tools/fetch-regress.sh REL_18_3
- name: Test
env:
SQLSHAPE_PG: "18"
run: |
go test ./check/postgres/catalog ./check/postgres/oracle -count=1
go test ./check/postgres/analyze -run 'TestRegress$' -count=1 -v -timeout 25m 2>&1 | grep -E 'statements:|hits|PASS|FAIL|ok '