-
Notifications
You must be signed in to change notification settings - Fork 3
162 lines (142 loc) · 6.26 KB
/
tests.yml
File metadata and controls
162 lines (142 loc) · 6.26 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
name: Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
any_changed: ${{ steps.set-matrix.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
git diff --name-only origin/${{ github.base_ref }}..HEAD >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
git diff --name-only HEAD~1..HEAD >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Set matrix for changed parsers
id: set-matrix
run: |
# List of all available parsers
ALL_PARSERS="redshift postgresql cql snowflake tsql doris starrocks trino plsql googlesql mysql partiql tidb mariadb cosmosdb mongodb"
# Add more parsers here as they are added to the repository
# ALL_PARSERS="redshift mysql postgresql"
CHANGED_FILES="${{ steps.changed-files.outputs.changed_files }}"
CHANGED_PARSERS=""
for parser in $ALL_PARSERS; do
if echo "$CHANGED_FILES" | grep -q "^$parser/"; then
if [ -z "$CHANGED_PARSERS" ]; then
CHANGED_PARSERS="\"$parser\""
else
CHANGED_PARSERS="$CHANGED_PARSERS,\"$parser\""
fi
fi
done
if [ -n "$CHANGED_PARSERS" ]; then
echo "matrix={\"parser\":[$CHANGED_PARSERS]}" >> $GITHUB_OUTPUT
echo "any_changed=true" >> $GITHUB_OUTPUT
echo "Changed parsers: $CHANGED_PARSERS"
else
echo "matrix={\"parser\":[]}" >> $GITHUB_OUTPUT
echo "any_changed=false" >> $GITHUB_OUTPUT
echo "No parser changes detected"
fi
go-mod-tidy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Verify go mod tidy
run: |
go mod tidy
git diff --exit-code -- go.mod go.sum
go-tests:
needs: detect-changes
if: needs.detect-changes.outputs.any_changed == 'true'
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJSON(needs.detect-changes.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Run all tests
working-directory: ${{ matrix.parser }}
run: go test -p=8 -timeout 30m -ldflags "-w -s" -v ./... | tee test.log; exit ${PIPESTATUS[0]}
- name: Pretty print tests running time
working-directory: ${{ matrix.parser }}
# grep: filter out lines like "--- PASS: Test (15.04s)"
# sed: remove unnecessary characters
# awk: re-format lines to "PASS: Test (15.04s)"
# sort: cut into columns by delimiter ' ' (single space) and sort by column 3 (test time in seconds) as numeric type in reverse order (largest comes first)
# awk: accumulate sum by test time in seconds
run: grep --color=never -e '--- PASS:' -e '--- FAIL:' test.log | sed 's/[:()]//g' | awk '{print $2,$3,$4}' | sort -t' ' -nk3 -r | awk '{sum += $3; print $1,$2,$3,sum"s"}'
antlr-grammar-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for grammar file changes
id: check-grammar-changes
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD)
else
CHANGED_FILES=$(git diff --name-only HEAD~1..HEAD)
fi
# Check if any .g4 files or tools/grammar/ files changed (Go target only)
if echo "$CHANGED_FILES" | grep -E '\.(g4)$|^tools/grammar/'; then
echo "grammar_changed=true" >> $GITHUB_OUTPUT
echo "Grammar files or tools/grammar/ changed, running Go ANTLR tests"
else
echo "grammar_changed=false" >> $GITHUB_OUTPUT
echo "No grammar file changes detected, skipping ANTLR tests"
fi
- uses: actions/setup-go@v5
if: steps.check-grammar-changes.outputs.grammar_changed == 'true'
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Run Go ANTLR grammar tests
if: steps.check-grammar-changes.outputs.grammar_changed == 'true'
working-directory: tools/grammar
run: go test -p=8 -timeout 30m -ldflags "-w -s" -v ./... | tee test.log; exit ${PIPESTATUS[0]}
- name: Pretty print grammar tests running time
if: steps.check-grammar-changes.outputs.grammar_changed == 'true'
working-directory: tools/grammar
# grep: filter out lines like "--- PASS: Test (15.04s)"
# sed: remove unnecessary characters
# awk: re-format lines to "PASS: Test (15.04s)"
# sort: cut into columns by delimiter ' ' (single space) and sort by column 3 (test time in seconds) as numeric type in reverse order (largest comes first)
# awk: accumulate sum by test time in seconds
run: grep --color=never -e '--- PASS:' -e '--- FAIL:' test.log | sed 's/[:()]//g' | awk '{print $2,$3,$4}' | sort -t' ' -nk3 -r | awk '{sum += $3; print $1,$2,$3,sum"s"}'
all-tests-passed:
runs-on: ubuntu-latest
# This job needs detect-changes, go-tests, and antlr-grammar-tests
needs: [detect-changes, go-tests, antlr-grammar-tests]
# This condition is key:
# - Run if no files were changed (the 'go-tests' job was skipped).
# - Or run if the 'go-tests' job (the whole matrix) succeeded.
# - And run if antlr-grammar-tests succeeded or was skipped.
if: success() || needs.detect-changes.outputs.any_changed == 'false'
steps:
- name: Report overall status
run: echo "All required tests passed or no changes were detected."