Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Get region in code, not CI
  • Loading branch information
kyleconroy committed Sep 20, 2023
commit d72ac19a89f8f37855d39380069937a89e5b5ac3
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ jobs:
with:
go-version: '1.21.1'

- name: set sqlc region
run: |
curl -I -s -o foo.txt -w 'SQLC_REGION=%header{fly-region}' https://debug.fly.dev >> "$GITHUB_ENV"

- name: install gotestsum
run: go install gotest.tools/gotestsum@latest

Expand Down
4 changes: 2 additions & 2 deletions internal/endtoend/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestValidSchema(t *testing.T) {
projectID := os.Getenv("CI_SQLC_PROJECT_ID")
authToken := os.Getenv("CI_SQLC_AUTH_TOKEN")

fmt.Println("region", os.Getenv("SQLC_REGION"))
fmt.Println("region", quickdb.GetClosestRegion())

if projectID == "" || authToken == "" {
if os.Getenv("CI") == "" {
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestValidSchema(t *testing.T) {

resp, err := client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{
Engine: "postgresql",
Region: os.Getenv("SQLC_REGION"),
Region: quickdb.GetClosestRegion(),
Migrations: sqls,
})
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions internal/quickdb/region.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package quickdb

import (
"net/http"
"sync"
)

var region string
var once sync.Once

func GetClosestRegion() string {
once.Do(func() {
resp, err := http.Get("https://debug.fly.dev")
if err == nil {
region = resp.Header.Get("Fly-Region")
}
})
return region
}
4 changes: 2 additions & 2 deletions internal/sqltest/hosted/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func PostgreSQL(t *testing.T, migrations []string) string {
seed = append(seed, string(blob))
}

fmt.Println("region", os.Getenv("SQLC_REGION"))
fmt.Println("region", quickdb.GetClosestRegion())
resp, err := client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{
Engine: "postgresql",
Region: os.Getenv("SQLC_REGION"),
Region: quickdb.GetClosestRegion(),
Migrations: seed,
})
if err != nil {
Expand Down