Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite4664f9

Browse files
committed
run pg tests on macos and windows in CI
1 parent6b1fafb commite4664f9

File tree

2 files changed

+96
-8
lines changed

2 files changed

+96
-8
lines changed

‎.github/workflows/ci.yaml‎

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,17 @@ jobs:
370370
api-key:${{ secrets.DATADOG_API_KEY }}
371371

372372
test-go-pg:
373-
runs-on:${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
374-
needs:
375-
-changes
373+
runs-on:${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'depot-ubuntu-22.04-4' || matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'macos-latest-xlarge' || matrix.os == 'windows-2022' && github.repository_owner == 'coder' && 'windows-latest-16-cores' || matrix.os }}
374+
needs:changes
376375
if:needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
377-
# This timeout must be greater than the timeout set by `go test` in
378-
# `make test-postgres` to ensure we receive a trace of running
379-
# goroutines. Setting this to the timeout +5m should work quite well
380-
# even if some of the preceding steps are slow.
381376
timeout-minutes:25
377+
strategy:
378+
fail-fast:false
379+
matrix:
380+
os:
381+
-ubuntu-latest
382+
-macos-latest
383+
-windows-2022
382384
steps:
383385
-name:Harden Runner
384386
uses:step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7# v2.10.1
@@ -400,8 +402,31 @@ jobs:
400402
env:
401403
POSTGRES_VERSION:"13"
402404
TS_DEBUG_DISCO:"true"
405+
shell:bash
403406
run:|
404-
make test-postgres
407+
# if macOS, install google-chrome for scaletests
408+
# As another concern, should we really have this kind of external dependency
409+
# requirement on standard CI?
410+
if [ "${{ matrix.os }}" == "macos-latest" ]; then
411+
brew install google-chrome
412+
fi
413+
414+
# By default Go will use the number of logical CPUs, which
415+
# is a fine default.
416+
PARALLEL_FLAG=""
417+
418+
# macOS will output "The default interactive shell is now zsh"
419+
# intermittently in CI...
420+
if [ "${{ matrix.os }}" == "macos-latest" ]; then
421+
touch ~/.bash_profile && echo "export BASH_SILENCE_DEPRECATION_WARNING=1" >> ~/.bash_profile
422+
fi
423+
424+
if [ "${{ runner.os }}" == "Linux" ]; then
425+
make test-postgres
426+
else
427+
go run scripts/embedded-pg/main.go
428+
DB=ci gotestsum --format standard-quiet -- -v -short -count=1 ./...
429+
fi
405430
406431
-name:Upload test stats to Datadog
407432
timeout-minutes:1

‎scripts/embedded-pg/main.go‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Start an embedded postgres database on port 5432. Used in CI on macOS and Windows.
2+
package main
3+
4+
import (
5+
"database/sql"
6+
"os"
7+
"path/filepath"
8+
9+
embeddedpostgres"github.com/fergusstrange/embedded-postgres"
10+
)
11+
12+
funcmain() {
13+
postgresPath:=filepath.Join(os.TempDir(),"coder-test-postgres")
14+
ep:=embeddedpostgres.NewDatabase(
15+
embeddedpostgres.DefaultConfig().
16+
Version(embeddedpostgres.V16).
17+
BinariesPath(filepath.Join(postgresPath,"bin")).
18+
DataPath(filepath.Join(postgresPath,"data")).
19+
RuntimePath(filepath.Join(postgresPath,"runtime")).
20+
CachePath(filepath.Join(postgresPath,"cache")).
21+
Username("postgres").
22+
Password("postgres").
23+
Database("postgres").
24+
Port(uint32(5432)).
25+
Logger(os.Stdout),
26+
)
27+
err:=ep.Start()
28+
iferr!=nil {
29+
panic(err)
30+
}
31+
// We execute these queries instead of using the embeddedpostgres
32+
// StartParams because it doesn't work on Windows. The library
33+
// seems to have a bug where it sends malformed parameters to
34+
// pg_ctl. It encloses each parameter in single quotes, which
35+
// Windows can't handle.
36+
paramQueries:= []string{
37+
`ALTER SYSTEM SET effective_cache_size = '1GB';`,
38+
`ALTER SYSTEM SET fsync = 'off';`,
39+
`ALTER SYSTEM SET full_page_writes = 'off';`,
40+
`ALTER SYSTEM SET max_connections = '1000';`,
41+
`ALTER SYSTEM SET shared_buffers = '1GB';`,
42+
`ALTER SYSTEM SET synchronous_commit = 'off';`,
43+
}
44+
db,err:=sql.Open("postgres","postgres://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable")
45+
iferr!=nil {
46+
panic(err)
47+
}
48+
for_,query:=rangeparamQueries {
49+
if_,err:=db.Exec(query);err!=nil {
50+
panic(err)
51+
}
52+
}
53+
iferr:=db.Close();err!=nil {
54+
panic(err)
55+
}
56+
// We restart the database to apply all the parameters.
57+
iferr:=ep.Stop();err!=nil {
58+
panic(err)
59+
}
60+
iferr:=ep.Start();err!=nil {
61+
panic(err)
62+
}
63+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp