Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 22 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25.0"
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
Expand All @@ -40,8 +44,24 @@ jobs:
build-mode: manual
- name: Install Taskfile support
uses: arduino/setup-task@v2
- shell: bash
run: task build
- name: Build (CodeQL-instrumented)
shell: bash
env:
GOTOOLCHAIN: local
run: |
# TODO(GODRIVER-3723): Run using taskfile targets.
go build ./...
go build ${BUILD_TAGS} ./...
go test -short ${BUILD_TAGS} -run ^$$ ./...

GO_VERSIONS="1.19" go test -v ./internal/test/compilecheck -run '^TestCompileCheck/golang:1.19$'
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compile check test should be run with GOWORK=off to match the configuration in the Taskfile (line 26) and the bash script at etc/run-compile-check-test.sh (line 18). Without this, the test may use workspace settings which could affect the compilation test behavior.

Suggested change
GO_VERSIONS="1.19" go test -v ./internal/test/compilecheck -run '^TestCompileCheck/golang:1.19$'
GOWORK=off GO_VERSIONS="1.19" go test -v ./internal/test/compilecheck -run '^TestCompileCheck/golang:1.19$'

Copilot uses AI. Check for mistakes.

GOOS=linux GOARCH=386 go build ./...
GOOS=linux GOARCH=arm go build ./...
GOOS=linux GOARCH=arm64 go build ./...
GOOS=linux GOARCH=amd64 go build ./...
GOOS=linux GOARCH=ppc64le go build ./...
GOOS=linux GOARCH=s390x go build ./...
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
with:
Expand Down
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ bin
internal/cmd/faas/awslambda/.aws-sam
internal/cmd/faas/awslambda/events/event.json

# Ignore compiled binaries from the compilecheck
internal/cmd/compilecheck/compilecheck
internal/cmd/compilecheck/compilecheck.so

# Ignore api report files
api-report.md
api-report.txt
Expand Down
13 changes: 11 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ tasks:
- go build ./...
- go build ${BUILD_TAGS} ./...
- task: build-tests
- task: build-compile-check
- task: compilecheck-119
- task: cross-compile
build-tests: go test -short ${BUILD_TAGS} -run ^$$ ./...
build-compile-check: bash etc/compile_check.sh
compilecheck-119:
dir: internal/test/compilecheck
env:
GOWORK: off
GOTOOLCHAIN: auto
GO_VERSIONS: "1.19"
COMPILECHECK_USE_DOCKER: "0"
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The environment variable COMPILECHECK_USE_DOCKER is set but never used in the test code. This appears to be dead code that should be removed to avoid confusion.

Suggested change
COMPILECHECK_USE_DOCKER: "0"

Copilot uses AI. Check for mistakes.
cmds:
- go mod download
- go test -v -run '^TestCompileCheck/golang:1\.19$'
build-compile-check-all: bash etc/run-compile-check-test.sh
build-aws-ecs-test: go test -c ./internal/test/aws -o aws.testbin
cross-compile:
Expand Down
48 changes: 0 additions & 48 deletions etc/compile_check.sh

This file was deleted.

11 changes: 10 additions & 1 deletion etc/run-compile-check-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
set -eu
set +x

echo "Running internal/test/compilecheck"
# Use specified GO_VERSIONS or default to all supported versions.
# To run the compile check tests with specific Go versions, set the GO_VERSIONS environment variable before running this script.
# For example, to use a single version: GO_VERSIONS=1.25 ./etc/run-compile-check-test.sh
# Or to use multiple versions: GO_VERSIONS="1.23,1.24,1.25" ./etc/run-compile-check-test.sh
if [ -z "${GO_VERSIONS:-}" ]; then
GO_VERSIONS="1.19,1.20,1.21,1.22,1.23,1.24,1.25"
fi
export GO_VERSIONS

echo "Running internal/test/compilecheck with Go versions: $GO_VERSIONS"
pushd internal/test/compilecheck
GOWORK=off go test -timeout 30m -v ./... >>../../../test.suite
popd
1 change: 0 additions & 1 deletion go.work
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use (
./examples/_logger/zap
./examples/_logger/zerolog
./internal/cmd/benchmark
./internal/cmd/compilecheck
./internal/cmd/faas/awslambda/mongodb
./internal/test/compilecheck
./internal/test/goleak
Expand Down
20 changes: 0 additions & 20 deletions internal/cmd/compilecheck/go.mod

This file was deleted.

42 changes: 0 additions & 42 deletions internal/cmd/compilecheck/go.sum

This file was deleted.

5 changes: 0 additions & 5 deletions internal/cmd/compilecheck/go.work

This file was deleted.

24 changes: 0 additions & 24 deletions internal/cmd/compilecheck/main.go

This file was deleted.

84 changes: 61 additions & 23 deletions internal/test/compilecheck/compile_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,49 @@
package main

import (
"bytes"
"context"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
)

var versions = []string{
"1.19",
"1.20",
"1.21",
"1.22",
"1.23",
"1.24",
"1.25",
const mainGo = `package main

import (
"fmt"

"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
)

func main() {
_, _ = mongo.Connect(options.Client())
fmt.Println(bson.D{{Key: "key", Value: "value"}})
}
`

func getVersions(t *testing.T) []string {
t.Helper()

env := os.Getenv("GO_VERSIONS")
if env == "" {
t.Skip("GO_VERSIONS environment variable not set")
}

return strings.Split(env, ",")
}

func TestCompileCheck(t *testing.T) {
versions := getVersions(t)
cwd, err := os.Getwd()
require.NoError(t, err)

Expand All @@ -43,18 +63,17 @@ func TestCompileCheck(t *testing.T) {
t.Parallel()

req := testcontainers.ContainerRequest{
Image: image,
Cmd: []string{"tail", "-f", "/dev/null"},
Mounts: []testcontainers.ContainerMount{
testcontainers.BindMount(rootDir, "/workspace"),
Image: image,
Cmd: []string{"tail", "-f", "/dev/null"},
WorkingDir: "/app",
HostConfigModifier: func(hostConfig *container.HostConfig) {
hostConfig.Binds = []string{fmt.Sprintf("%s:/driver", rootDir)}
},
WorkingDir: "/workspace",
Env: map[string]string{
"GC": "go",
// Compilation modules are not part of the workspace as testcontainers requires
// a version of klauspost/compress not supported by the Go Driver / other modules
// in the workspace.
"GOWORK": "off",
Files: []testcontainers.ContainerFile{
{
ContainerFilePath: "/app/main.go",
Reader: bytes.NewReader([]byte(mainGo)),
},
},
}

Expand All @@ -71,14 +90,33 @@ func TestCompileCheck(t *testing.T) {
require.NoError(t, err)
}()

exitCode, outputReader, err := container.Exec(context.Background(), []string{"bash", "etc/compile_check.sh"})
// Initialize go module and set up replace directive to use local driver.
setupCmds := [][]string{
{"go", "mod", "init", "app"},
{"go", "mod", "edit", "-replace", "go.mongodb.org/mongo-driver/v2=/driver"},
{"go", "mod", "tidy"},
}

for _, cmd := range setupCmds {
exitCode, outputReader, err := container.Exec(context.Background(), cmd)
require.NoError(t, err)

output, err := io.ReadAll(outputReader)
require.NoError(t, err)

require.Equal(t, 0, exitCode, "command %v failed: %s", cmd, output)
}

// Standard build.
exitCode, outputReader, err := container.Exec(context.Background(), []string{"go", "build", "./..."})
require.NoError(t, err)

output, err := io.ReadAll(outputReader)
require.NoError(t, err)

t.Logf("output: %s", output)
assert.Equal(t, 0, exitCode)
require.Equal(t, 0, exitCode, "standard build failed: %s", output)

t.Logf("compilation checks passed for %s", image)
})
}
}
2 changes: 1 addition & 1 deletion internal/test/compilecheck/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.25.0
toolchain go1.25.3

require (
github.com/docker/docker v28.0.0+incompatible
github.com/stretchr/testify v1.10.0
github.com/testcontainers/testcontainers-go v0.35.0
)
Expand All @@ -20,7 +21,6 @@ require (
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v28.0.0+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
Expand Down
Loading