Skip to content

Commit 8ff3b25

Browse files
authored
Port the latest build and CI process to release/1.11 (#1285)
1 parent b2afacb commit 8ff3b25

File tree

14 files changed

+313
-135
lines changed

14 files changed

+313
-135
lines changed

.evergreen/config.yml

Lines changed: 70 additions & 98 deletions
Large diffs are not rendered by default.

.evergreen/run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ MONGO_GO_DRIVER_PKCS8_UNENCRYPTED_KEY_FILE=${MONGO_GO_DRIVER_PKCS8_UNENCRYPTED_K
117117
MONGODB_URI="${MONGODB_URI}" \
118118
TOPOLOGY=${TOPOLOGY} \
119119
MONGO_GO_DRIVER_COMPRESSOR=${MONGO_GO_DRIVER_COMPRESSOR} \
120-
BUILD_TAGS="-tags ${GO_BUILD_TAGS}" \
120+
BUILD_TAGS="${RACE} -tags=${GO_BUILD_TAGS}" \
121121
AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \
122122
AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \
123123
AWS_DEFAULT_REGION="us-east-1" \

Makefile

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ TEST_TIMEOUT = 1800
33

44
### Utility targets. ###
55
.PHONY: default
6-
default: add-license build check-fmt check-modules lint test-short
6+
default: build check-license check-fmt check-modules lint test-short
77

8-
# Find all .go files not in the vendor directory and try to write a license notice. Then check for
9-
# any changes made with -G. to ignore permissions changes. Exit with a non-zero exit code if there
10-
# is a diff.
118
.PHONY: add-license
129
add-license:
13-
find . -path ./vendor -prune -o -type f -name "*.go" -print | xargs ./etc/add_license.sh
14-
git diff -G. --quiet
10+
etc/check_license.sh -a
11+
12+
.PHONY: check-license
13+
check-license:
14+
etc/check_license.sh
1515

1616
.PHONY: build
17-
build: build-tests
17+
build: cross-compile build-tests build-compile-check
18+
go build ./...
1819
go build $(BUILD_TAGS) ./...
1920

2021
# Use ^$ to match no tests so that no tests are actually run but all tests are
@@ -24,6 +25,22 @@ build: build-tests
2425
build-tests:
2526
go test -short $(BUILD_TAGS) -run ^$$ ./...
2627

28+
.PHONY: build-compile-check
29+
build-compile-check:
30+
etc/compile_check.sh
31+
32+
# Cross-compiling on Linux for architectures 386, arm, arm64, amd64, ppc64le, and s390x.
33+
# Omit any build tags because we don't expect our build environment to support compiling the C
34+
# libraries for other architectures.
35+
.PHONY: cross-compile
36+
cross-compile:
37+
GOOS=linux GOARCH=386 go build ./...
38+
GOOS=linux GOARCH=arm go build ./...
39+
GOOS=linux GOARCH=arm64 go build ./...
40+
GOOS=linux GOARCH=amd64 go build ./...
41+
GOOS=linux GOARCH=ppc64le go build ./...
42+
GOOS=linux GOARCH=s390x go build ./...
43+
2744
.PHONY: install-lll
2845
install-lll:
2946
go install github.com/walle/lll/...@latest
@@ -64,10 +81,11 @@ install-golangci-lint:
6481
# https://staticcheck.io/docs/checks#SA1027)
6582
.PHONY: lint
6683
lint: install-golangci-lint
67-
GOOS=linux GOARCH=amd64 golangci-lint run --config .golangci.yml ./...
6884
GOOS=linux GOARCH=386 golangci-lint run --config .golangci.yml ./...
69-
GOOS=linux GOARCH=arm64 golangci-lint run --config .golangci.yml ./...
7085
GOOS=linux GOARCH=arm golangci-lint run --config .golangci.yml ./...
86+
GOOS=linux GOARCH=arm64 golangci-lint run --config .golangci.yml ./...
87+
GOOS=linux GOARCH=amd64 golangci-lint run --config .golangci.yml ./...
88+
GOOS=linux GOARCH=ppc64le golangci-lint run --config .golangci.yml ./...
7189
GOOS=linux GOARCH=s390x golangci-lint run --config .golangci.yml ./...
7290

7391
.PHONY: update-notices

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The MongoDB supported driver for Go.
2323
## Requirements
2424

2525
- Go 1.13 or higher. We aim to support the latest versions of Go.
26-
- Go 1.18 or higher is required to run the driver test suite.
26+
- Go 1.20 or higher is required to run the driver test suite.
2727
- MongoDB 3.6 and higher.
2828

2929
-------------------------

bson/fuzz_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright (C) MongoDB, Inc. 2023-present.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
17
package bson
28

39
import (

docs/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Before starting to write code, look for existing [tickets](https://jira.mongodb.
1313
The Go Driver team uses GitHub to manage and review all code changes. Patches should generally be made against the master (default) branch and include relevant tests, if
1414
applicable.
1515

16-
Code should compile and tests should pass under all Go versions which the driver currently supports. Currently the Go Driver supports a minimum version of Go 1.13 and requires Go 1.18 for development. Please run the following Make targets to validate your changes:
16+
Code should compile and tests should pass under all Go versions which the driver currently supports. Currently the Go Driver supports a minimum version of Go 1.13 and requires Go 1.20 for development. Please run the following Make targets to validate your changes:
1717
- `make fmt`
1818
- `make lint` (requires [golangci-lint](https://github.com/golangci/golangci-lint) and [lll](https://github.com/walle/lll) to be installed and available in the `PATH`)
1919
- `make test`

etc/add_license.sh

Lines changed: 0 additions & 25 deletions
This file was deleted.

etc/check_license.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
3+
year=$(date +"%Y")
4+
copyright=$"// Copyright (C) MongoDB, Inc. $year-present.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the \"License\"); you may
7+
// not use this file except in compliance with the License. You may obtain
8+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
9+
"
10+
11+
add_copyright() {
12+
file=$1
13+
14+
# Check if first 24 bytes match first 24 bytes of copyright notice.
15+
local line=$(head -c 24 $file)
16+
if [ "$line" == "// Copyright (C) MongoDB" ]; then
17+
if [ ! -z "$verbose" ]; then
18+
echo "$file already has copyright notice" >&2
19+
fi
20+
return
21+
fi
22+
23+
# Check if first 14 bytes matches the prefix "// Copied from"
24+
local line=$(head -c 14 $file)
25+
if [ "$line" == "// Copied from" ]; then
26+
if [ ! -z "$verbose" ]; then
27+
echo "$file has a third-party copyright notice" >&2
28+
fi
29+
return
30+
fi
31+
32+
if [ ! -z "$add" ]; then
33+
echo "$copyright" | cat - $file > temp && mv temp $file
34+
return
35+
fi
36+
37+
echo "Missing copyright notice in \"$file\". Run \"make add-license\" to add missing licenses."
38+
exit 1
39+
}
40+
41+
# Options are:
42+
# -a : Add licenses that are missing.
43+
# -v : Verbose. Print all files as they're checked.
44+
while getopts at:vt: flag
45+
do
46+
case "${flag}" in
47+
a) add=1;;
48+
v) verbose=1;;
49+
esac
50+
done
51+
52+
# Find all .go files not in the vendor directory and try to write a license notice.
53+
GO_FILES=$(find . -path ./vendor -prune -o -type f -name "*.go" -print)
54+
55+
for file in $GO_FILES
56+
do
57+
add_copyright "$file"
58+
done

etc/compile_check.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
set -e # exit when any command fails
3+
set -x # show all commands being run
4+
5+
GC=go
6+
COMPILE_CHECK_DIR="internal/test/compilecheck"
7+
DEV_MIN_VERSION=1.19
8+
9+
# version will flatten a version string of upto 4 components for inequality
10+
# comparison.
11+
function version {
12+
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
13+
}
14+
15+
# compile_check will attempt to build the the internal/test/compilecheck project
16+
# using the provided Go version. This is to simulate an end-to-end use case.
17+
# This check will only run on environments where the Go version is greater than
18+
# or equal to the given version.
19+
function compile_check {
20+
# Change the directory to the compilecheck test directory.
21+
cd ${COMPILE_CHECK_DIR}
22+
23+
MACHINE_VERSION=`${GC} version | { read _ _ v _; echo ${v#go}; }`
24+
25+
# If the version is not 1.13, then run "go mod tidy"
26+
if [ $(version $MACHINE_VERSION) -ge $(version 1.15) ]; then
27+
go mod tidy
28+
fi
29+
30+
# Check simple build.
31+
${GC} build ./...
32+
33+
# Check build with dynamic linking.
34+
${GC} build -buildmode=plugin
35+
36+
# Check build with tags.
37+
go build $BUILD_TAGS ./...
38+
39+
# Check build with various architectures.
40+
GOOS=linux GOARCH=386 ${GC} build ./...
41+
GOOS=linux GOARCH=arm ${GC} build ./...
42+
GOOS=linux GOARCH=arm64 ${GC} build ./...
43+
GOOS=linux GOARCH=amd64 ${GC} build ./...
44+
GOOS=linux GOARCH=ppc64le ${GC} build ./...
45+
GOOS=linux GOARCH=s390x ${GC} build ./...
46+
47+
# Remove the binaries.
48+
rm compilecheck
49+
rm compilecheck.so
50+
51+
# Change the directory back to the working directory.
52+
cd -
53+
}
54+
55+
compile_check

internal/test/compilecheck/go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module go.mongodb.go/mongo-driver/internal/test/compilecheck
2+
3+
go 1.13
4+
5+
replace go.mongodb.org/mongo-driver => ../../../
6+
7+
require go.mongodb.org/mongo-driver v1.11.6

0 commit comments

Comments
 (0)