@@ -14,21 +14,23 @@ jobs:
14
14
test-go-pg :
15
15
# make sure to adjust NUM_PARALLEL_PACKAGES and NUM_PARALLEL_TESTS below
16
16
# when changing runner sizes
17
- runs-on : ${{ matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'depot-macos-latest' || matrix.os == 'windows-2022' && github.repository_owner == 'coder' && 'depot-windows-2022-16' || matrix.os }}
17
+ runs-on : ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || matrix.os && matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'depot-macos-latest' || matrix.os == 'windows-2022' && github.repository_owner == 'coder' && 'depot-windows-2022-16' || matrix.os }}
18
+ needs : changes
19
+ if : needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
18
20
# This timeout must be greater than the timeout set by `go test` in
19
21
# `make test-postgres` to ensure we receive a trace of running
20
22
# goroutines. Setting this to the timeout +5m should work quite well
21
23
# even if some of the preceding steps are slow.
22
24
timeout-minutes : 25
23
25
strategy :
24
- fail-fast : false
25
26
matrix :
26
27
os :
28
+ - ubuntu-latest
27
29
- macos-latest
28
30
- windows-2022
29
31
steps :
30
32
- name : Harden Runner
31
- uses : step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
33
+ uses : step-security/harden-runner@6c439dc8bdf85cadbbce9ed30d1c7b959517bc49 # v2.12.2
32
34
with :
33
35
egress-policy : audit
34
36
@@ -46,25 +48,63 @@ jobs:
46
48
# a separate repository to allow its use before actions/checkout.
47
49
- name : Setup RAM Disks
48
50
if : runner.os == 'Windows'
49
- uses : coder/setup-ramdisk-action@79dacfe70c47ad6d6c0dd7f45412368802641439
51
+ uses : coder/setup-ramdisk-action@e1100847ab2d7bcd9d14bcda8f2d1b0f07b36f1b
50
52
51
53
- name : Checkout
52
54
uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
53
55
with :
54
56
fetch-depth : 1
55
57
58
+ - name : Setup Go Paths
59
+ id : go-paths
60
+ uses : ./.github/actions/setup-go-paths
61
+
62
+ - name : Download Go Build Cache
63
+ id : download-go-build-cache
64
+ uses : ./.github/actions/test-cache/download
65
+ with :
66
+ key-prefix : test-go-build-${{ runner.os }}-${{ runner.arch }}
67
+ cache-path : ${{ steps.go-paths.outputs.cached-dirs }}
68
+
56
69
- name : Setup Go
57
70
uses : ./.github/actions/setup-go
58
71
with :
59
72
# Runners have Go baked-in and Go will automatically
60
73
# download the toolchain configured in go.mod, so we don't
61
74
# need to reinstall it. It's faster on Windows runners.
62
75
use-preinstalled-go : ${{ runner.os == 'Windows' }}
63
- use-temp-cache-dirs : ${{ runner.os == 'Windows' }}
76
+ # Cache is already downloaded above
77
+ use-cache : false
64
78
65
79
- name : Setup Terraform
66
80
uses : ./.github/actions/setup-tf
67
81
82
+ - name : Download Test Cache
83
+ id : download-cache
84
+ uses : ./.github/actions/test-cache/download
85
+ with :
86
+ key-prefix : test-go-pg-${{ runner.os }}-${{ runner.arch }}
87
+
88
+ - name : Setup Embedded Postgres Cache Paths
89
+ id : embedded-pg-cache
90
+ uses : ./.github/actions/setup-embedded-pg-cache-paths
91
+
92
+ - name : Download Embedded Postgres Cache
93
+ id : download-embedded-pg-cache
94
+ uses : ./.github/actions/embedded-pg-cache/download
95
+ with :
96
+ key-prefix : embedded-pg-${{ runner.os }}-${{ runner.arch }}
97
+ cache-path : ${{ steps.embedded-pg-cache.outputs.cached-dirs }}
98
+
99
+ - name : Normalize File and Directory Timestamps
100
+ shell : bash
101
+ # Normalize file modification timestamps so that go test can use the
102
+ # cache from the previous CI run. See https://github.com/golang/go/issues/58571
103
+ # for more details.
104
+ run : |
105
+ find . -type f ! -path ./.git/\*\* | mtimehash
106
+ find . -type d ! -path ./.git/\*\* -exec touch -t 200601010000 {} +
107
+
68
108
- name : Test with PostgreSQL Database
69
109
env :
70
110
POSTGRES_VERSION : " 13"
@@ -73,17 +113,21 @@ jobs:
73
113
LC_ALL : " en_US.UTF-8"
74
114
shell : bash
75
115
run : |
116
+ set -o errexit
117
+ set -o pipefail
118
+
76
119
if [ "${{ runner.os }}" == "Windows" ]; then
77
120
# Create a temp dir on the R: ramdisk drive for Windows. The default
78
121
# C: drive is extremely slow: https://github.com/actions/runner-images/issues/8755
79
122
mkdir -p "R:/temp/embedded-pg"
80
- go run scripts/embedded-pg/main.go -path "R:/temp/embedded-pg"
81
- fi
82
- if [ "${{ runner.os }}" == "macOS" ]; then
123
+ go run scripts/embedded-pg/main.go -path "R:/temp/embedded-pg" -cache "${EMBEDDED_PG_CACHE_DIR}"
124
+ elif [ "${{ runner.os }}" == "macOS" ]; then
83
125
# Postgres runs faster on a ramdisk on macOS too
84
126
mkdir -p /tmp/tmpfs
85
127
sudo mount_tmpfs -o noowners -s 8g /tmp/tmpfs
86
- go run scripts/embedded-pg/main.go -path /tmp/tmpfs/embedded-pg
128
+ go run scripts/embedded-pg/main.go -path /tmp/tmpfs/embedded-pg -cache "${EMBEDDED_PG_CACHE_DIR}"
129
+ elif [ "${{ runner.os }}" == "Linux" ]; then
130
+ make test-postgres-docker
87
131
fi
88
132
89
133
# if macOS, install google-chrome for scaletests
@@ -93,39 +137,74 @@ jobs:
93
137
brew install google-chrome
94
138
fi
95
139
96
- # By default Go will use the number of logical CPUs, which
97
- # is a fine default.
98
- PARALLEL_FLAG=""
99
-
100
140
# macOS will output "The default interactive shell is now zsh"
101
141
# intermittently in CI...
102
142
if [ "${{ matrix.os }}" == "macos-latest" ]; then
103
143
touch ~/.bash_profile && echo "export BASH_SILENCE_DEPRECATION_WARNING=1" >> ~/.bash_profile
104
144
fi
105
145
106
- # Golang's default for these 2 variables is the number of logical CPUs.
107
- # Our Windows and Linux runners have 16 cores, so they match up there.
108
- NUM_PARALLEL_PACKAGES=16
109
- NUM_PARALLEL_TESTS=16
110
146
if [ "${{ runner.os }}" == "Windows" ]; then
147
+ # Our Windows runners have 16 cores.
111
148
# On Windows Postgres chokes up when we have 16x16=256 tests
112
149
# running in parallel, and dbtestutil.NewDB starts to take more than
113
150
# 10s to complete sometimes causing test timeouts. With 16x8=128 tests
114
151
# Postgres tends not to choke.
115
152
NUM_PARALLEL_PACKAGES=8
116
- fi
117
- if [ "${{ runner.os }}" == "macOS" ]; then
118
- # Our macOS runners have 8 cores. We leave NUM_PARALLEL_TESTS at 16
153
+ NUM_PARALLEL_TESTS=16
154
+ elif [ "${{ runner.os }}" == "macOS" ]; then
155
+ # Our macOS runners have 8 cores. We set NUM_PARALLEL_TESTS to 16
119
156
# because the tests complete faster and Postgres doesn't choke. It seems
120
157
# that macOS's tmpfs is faster than the one on Windows.
121
158
NUM_PARALLEL_PACKAGES=8
159
+ NUM_PARALLEL_TESTS=16
160
+ elif [ "${{ runner.os }}" == "Linux" ]; then
161
+ # Our Linux runners have 8 cores.
162
+ NUM_PARALLEL_PACKAGES=8
163
+ NUM_PARALLEL_TESTS=8
164
+ fi
165
+
166
+ # by default, run tests with cache
167
+ TESTCOUNT=""
168
+ if [ "${{ github.ref }}" == "refs/heads/main" ]; then
169
+ # on main, run tests without cache
170
+ TESTCOUNT="-count=1"
122
171
fi
123
172
124
- # We rerun failing tests to counteract flakiness coming from Postgres
125
- # choking on macOS and Windows sometimes.
126
- DB=ci gotestsum --rerun-fails=2 --rerun-fails-max-failures=1000 \
173
+ TEST_RETRIES="--rerun-fails=2 --rerun-fails-max-failures=50"
174
+ if [ "${{ github.ref }}" == "refs/heads/hugodutka/disable-test-retries-on-main" ]; then
175
+ # on main, run tests without retries
176
+ TEST_RETRIES=""
177
+ fi
178
+
179
+ mkdir -p "$RUNNER_TEMP/sym"
180
+ source scripts/normalize_path.sh
181
+ # terraform gets installed in a random directory, so we need to normalize
182
+ # the path to the terraform binary or a bunch of cached tests will be
183
+ # invalidated. See scripts/normalize_path.sh for more details.
184
+ normalize_path_with_symlinks "$RUNNER_TEMP/sym" "$(dirname $(which terraform))"
185
+
186
+ DB=ci gotestsum $TEST_RETRIES \
127
187
--format standard-quiet --packages "./..." \
128
- -- -v -p $NUM_PARALLEL_PACKAGES -parallel=$NUM_PARALLEL_TESTS -count=1
188
+ -- -timeout=20m -v -p $NUM_PARALLEL_PACKAGES -parallel=$NUM_PARALLEL_TESTS $TESTCOUNT
189
+
190
+ - name : Upload Go Build Cache
191
+ uses : ./.github/actions/test-cache/upload
192
+ with :
193
+ cache-key : ${{ steps.download-go-build-cache.outputs.cache-key }}
194
+ cache-path : ${{ steps.go-paths.outputs.cached-dirs }}
195
+
196
+ - name : Upload Test Cache
197
+ uses : ./.github/actions/test-cache/upload
198
+ with :
199
+ cache-key : ${{ steps.download-cache.outputs.cache-key }}
200
+
201
+ - name : Upload Embedded Postgres Cache
202
+ uses : ./.github/actions/embedded-pg-cache/upload
203
+ # We only use the embedded Postgres cache on macOS and Windows runners.
204
+ if : runner.OS == 'macOS' || runner.OS == 'Windows'
205
+ with :
206
+ cache-key : ${{ steps.download-embedded-pg-cache.outputs.cache-key }}
207
+ cache-path : " ${{ steps.embedded-pg-cache.outputs.embedded-pg-cache }}"
129
208
130
209
- name : Upload test stats to Datadog
131
210
timeout-minutes : 1
0 commit comments