diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f86701a5f0..7d8824ce16 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ // README at: https://github.com/devcontainers/templates/tree/main/src/go { "name": "Go", - "image": "mcr.microsoft.com/devcontainers/go:0-1.19-bullseye", + "image": "mcr.microsoft.com/devcontainers/go:0-1.20-bullseye", // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index 6372448e43..cc491a9280 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -36,7 +36,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.x + go-version-file: go.mod id: go - name: modVerify diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e70e499418..c3adf6cc31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: test: strategy: matrix: - go-version: [1.19.x, 1.x] + go-version: [1.20.x, 1.x] platform: [ubuntu-latest, macos-latest] uses: ./.github/workflows/ci-test-go.yml with: @@ -38,7 +38,7 @@ jobs: needs: test strategy: matrix: - go-version: [1.19.x, 1.x] + go-version: [1.20.x, 1.x] uses: ./.github/workflows/ci-test-go.yml with: go-version: ${{ matrix.go-version }} @@ -55,7 +55,7 @@ jobs: needs: test strategy: matrix: - go-version: [1.19.x, 1.x] + go-version: [1.20.x, 1.x] platform: [ubuntu-latest] uses: ./.github/workflows/ci-test-go.yml with: @@ -69,7 +69,7 @@ jobs: test-module-generator: strategy: matrix: - go-version: [1.19.x, 1.x] + go-version: [1.20.x, 1.x] platform: [ubuntu-latest, macos-latest, windows-latest] uses: ./.github/workflows/ci-test-go.yml with: @@ -84,12 +84,9 @@ jobs: needs: test strategy: matrix: - go-version: [1.19.x, 1.x] + go-version: [1.20.x, 1.x] platform: [ubuntu-latest, macos-latest] module: [artemis, clickhouse, compose, couchbase, k3s, localstack, mongodb, mysql, neo4j, postgres, pulsar, redis, redpanda, vault] - exclude: - - module: compose - go-version: 1.19.x uses: ./.github/workflows/ci-test-go.yml with: go-version: ${{ matrix.go-version }} @@ -103,7 +100,7 @@ jobs: needs: test-modules strategy: matrix: - go-version: [1.19.x, 1.x] + go-version: [1.20.x, 1.x] platform: [ubuntu-latest, macos-latest] module: [bigtable, cockroachdb, consul, datastore, firestore, nats, nginx, pubsub, spanner, toxiproxy] uses: ./.github/workflows/ci-test-go.yml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 1be8959ded..813df6f282 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -20,15 +20,15 @@ jobs: static-analysis: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: 1.19 - - uses: actions/checkout@v3 + go-version-file: go.mod - name: golangci-lint - uses: golangci/golangci-lint-action@639cd343e1d3b897ff35927a75193d57cfcba299 + uses: golangci/golangci-lint-action@v3 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.50 + version: v1.54.1 # Optional: working directory, useful for monorepos # working-directory: somedir diff --git a/.golangci.yml b/.golangci.yml index 89bf14cc43..6d4d77a746 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -13,4 +13,4 @@ linters-settings: - prefix(github.com/testcontainters) run: - timeout: 3m + timeout: 5m diff --git a/docker_test.go b/docker_test.go index e0858496d9..b3a05af2aa 100644 --- a/docker_test.go +++ b/docker_test.go @@ -2244,7 +2244,7 @@ func terminateContainerOnEnd(tb testing.TB, ctx context.Context, ctr Container) } func randomString() string { - rand.Seed(time.Now().UnixNano()) + rand.New(rand.NewSource(time.Now().UnixNano())) chars := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789") diff --git a/docs/system_requirements/ci/bitbucket_pipelines.md b/docs/system_requirements/ci/bitbucket_pipelines.md index cbbc705ee3..9e0e2f50a0 100644 --- a/docs/system_requirements/ci/bitbucket_pipelines.md +++ b/docs/system_requirements/ci/bitbucket_pipelines.md @@ -9,7 +9,7 @@ In some cases the memory available to Docker needs to be increased. Here is a sample Bitbucket Pipeline configuration that does a checkout of a project and runs Go tests: ```yml -image: golang:1.19 +image: golang:1.x pipelines: default: diff --git a/docs/system_requirements/ci/circle_ci.md b/docs/system_requirements/ci/circle_ci.md index 0c1fe107ae..1abdec0462 100644 --- a/docs/system_requirements/ci/circle_ci.md +++ b/docs/system_requirements/ci/circle_ci.md @@ -15,7 +15,7 @@ jobs: machine: true image: ubuntu-2204:2023.04.2 steps: - # install Go 1.19 + # install Go 1.x # checkout the project - run: go test./... ``` diff --git a/docs/system_requirements/ci/concourse_ci.md b/docs/system_requirements/ci/concourse_ci.md index 5861c13138..8f61f37b58 100644 --- a/docs/system_requirements/ci/concourse_ci.md +++ b/docs/system_requirements/ci/concourse_ci.md @@ -36,7 +36,7 @@ jobs: start_docker cd repo - docker run -it --rm -v "$PWD:$PWD" -w "$PWD" -v /var/run/docker.sock:/var/run/docker.sock golang:1.19 go test ./... + docker run -it --rm -v "$PWD:$PWD" -w "$PWD" -v /var/run/docker.sock:/var/run/docker.sock golang:1.20 go test ./... ``` Finally, you can use Concourse's [fly CLI](https://concourse-ci.org/fly.html) to set the pipeline and trigger the job: diff --git a/docs/system_requirements/ci/dind_patterns.md b/docs/system_requirements/ci/dind_patterns.md index 681dddb0d5..6475040737 100644 --- a/docs/system_requirements/ci/dind_patterns.md +++ b/docs/system_requirements/ci/dind_patterns.md @@ -24,7 +24,7 @@ $ tree . └── platform └── integration_test.go -$ docker run -it --rm -v $PWD:$PWD -w $PWD -v /var/run/docker.sock:/var/run/docker.sock golang:1.19 go test ./... -v +$ docker run -it --rm -v $PWD:$PWD -w $PWD -v /var/run/docker.sock:/var/run/docker.sock golang:1.20 go test ./... -v ``` Where: @@ -45,7 +45,7 @@ The same can be achieved with Docker Compose: ```yaml tests: - image: golang:1.19 + image: golang:1.20 stop_signal: SIGKILL stdin_open: true tty: true diff --git a/docs/system_requirements/ci/gitlab_ci.md b/docs/system_requirements/ci/gitlab_ci.md index c3ae6cf030..0604a695a7 100644 --- a/docs/system_requirements/ci/gitlab_ci.md +++ b/docs/system_requirements/ci/gitlab_ci.md @@ -57,7 +57,7 @@ variables: DOCKER_DRIVER: overlay2 test: - image: golang:1.19 + image: golang:1.20 stage: test script: go test ./... -v ``` diff --git a/docs/system_requirements/ci/tekton.md b/docs/system_requirements/ci/tekton.md index b53161038a..fb5c16a8a6 100644 --- a/docs/system_requirements/ci/tekton.md +++ b/docs/system_requirements/ci/tekton.md @@ -16,7 +16,7 @@ spec: - name: source steps: - name: read - image: golang:1.19 + image: golang:1.20 workingDir: $(workspaces.source.path) script: go test ./... -v volumeMounts: diff --git a/docs/system_requirements/ci/travis.md b/docs/system_requirements/ci/travis.md index b07d023fc2..7534c86fc9 100644 --- a/docs/system_requirements/ci/travis.md +++ b/docs/system_requirements/ci/travis.md @@ -7,7 +7,7 @@ is the minimal required config. language: go go: - 1.x -- "1.19" +- "1.20" services: - docker diff --git a/docs/system_requirements/index.md b/docs/system_requirements/index.md index ae733af39f..dbcfea0bce 100644 --- a/docs/system_requirements/index.md +++ b/docs/system_requirements/index.md @@ -5,3 +5,18 @@ From the [Go Release Policy](https://go.dev/doc/devel/release#policy): > Each major Go release is supported until there are two newer major releases. For example, Go 1.5 was supported until the Go 1.7 release, and Go 1.6 was supported until the Go 1.8 release. We fix critical problems, including critical security problems, in supported releases as needed by issuing minor revisions (for example, Go 1.6.1, Go 1.6.2, and so on). _Testcontainers for Go_ is tested against those two latest Go releases, therefore we recommend using any of them. You could check what versions are actually supported by looking at the [GitHub Action](https://github.com/testcontainers/testcontainers-go/blob/main/.github/workflows/ci.yml) configuration, under the `test.strategy.matrix.go-version` key. + +## Updating the Go version + +The project has a script to update the Go version used in the project. To update the Go version across all files, please run the following command: + +```bash +DRY_RUN=false ./scripts/bump-go.sh 1.21 +``` + +It will update: +- all `go.mod` files. +- all Github Actions workflows, and their matrices using the `go-version` strategy. +- the templates for the module generator. +- the Devcontainer configuration. +- the tag of the Go Docker image in the markdown documentation. diff --git a/examples/bigtable/go.mod b/examples/bigtable/go.mod index 96110e86fc..4805cd57ca 100644 --- a/examples/bigtable/go.mod +++ b/examples/bigtable/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/examples/bigtable -go 1.19 +go 1.20 require ( cloud.google.com/go/bigtable v1.19.0 diff --git a/examples/cockroachdb/go.mod b/examples/cockroachdb/go.mod index 921f9fa7a8..56d23a92d0 100644 --- a/examples/cockroachdb/go.mod +++ b/examples/cockroachdb/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/examples/cockroachdb -go 1.19 +go 1.20 require ( github.com/google/uuid v1.3.0 diff --git a/examples/consul/go.mod b/examples/consul/go.mod index 6d10d3ce26..4368dc66af 100644 --- a/examples/consul/go.mod +++ b/examples/consul/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/examples/consul -go 1.19 +go 1.20 require ( github.com/hashicorp/consul/api v1.24.0 diff --git a/examples/datastore/go.mod b/examples/datastore/go.mod index d53d296ed9..f3e1465cc1 100644 --- a/examples/datastore/go.mod +++ b/examples/datastore/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/examples/datastore -go 1.19 +go 1.20 require ( cloud.google.com/go/datastore v1.13.0 diff --git a/examples/firestore/go.mod b/examples/firestore/go.mod index 28f259d402..a9384cfff8 100644 --- a/examples/firestore/go.mod +++ b/examples/firestore/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/examples/firestore -go 1.19 +go 1.20 require ( cloud.google.com/go/firestore v1.12.0 diff --git a/examples/nats/go.mod b/examples/nats/go.mod index ebdba8fbeb..8c9ed8098c 100644 --- a/examples/nats/go.mod +++ b/examples/nats/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/examples/nats -go 1.19 +go 1.20 require ( github.com/nats-io/nats.go v1.28.0 diff --git a/examples/nginx/go.mod b/examples/nginx/go.mod index f9fa0e9706..c73e19cb43 100644 --- a/examples/nginx/go.mod +++ b/examples/nginx/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/examples/nginx -go 1.19 +go 1.20 require github.com/testcontainers/testcontainers-go v0.22.0 diff --git a/examples/pubsub/go.mod b/examples/pubsub/go.mod index 1bf5dd921b..4d04bf786b 100644 --- a/examples/pubsub/go.mod +++ b/examples/pubsub/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/examples/pubsub -go 1.19 +go 1.20 require ( cloud.google.com/go/pubsub v1.33.0 diff --git a/examples/spanner/go.mod b/examples/spanner/go.mod index 4786c56265..a516de6e26 100644 --- a/examples/spanner/go.mod +++ b/examples/spanner/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/examples/spanner -go 1.19 +go 1.20 require ( cloud.google.com/go/spanner v1.47.0 diff --git a/examples/toxiproxy/go.mod b/examples/toxiproxy/go.mod index 2f675f07d0..d6bbbdd174 100644 --- a/examples/toxiproxy/go.mod +++ b/examples/toxiproxy/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/examples/toxiproxy -go 1.19 +go 1.20 require ( github.com/Shopify/toxiproxy/v2 v2.5.0 diff --git a/go.mod b/go.mod index 49d4fac304..2c70f9e267 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go -go 1.19 +go 1.20 require ( dario.cat/mergo v1.0.0 diff --git a/modulegen/_template/ci.yml.tmpl b/modulegen/_template/ci.yml.tmpl index 272dd9b18d..388d891bfc 100644 --- a/modulegen/_template/ci.yml.tmpl +++ b/modulegen/_template/ci.yml.tmpl @@ -20,7 +20,7 @@ jobs: test: strategy: matrix: - go-version: [1.19.x, 1.x] + go-version: [1.20.x, 1.x] platform: [ubuntu-latest, macos-latest] uses: ./.github/workflows/ci-test-go.yml with: @@ -28,6 +28,7 @@ jobs: platform: {{ "${{ matrix.platform }}" }} project-directory: "." rootless-docker: false + run-tests: {{ "${{ matrix.platform == 'ubuntu-latest' }}" }} ryuk-disabled: false # The job below is a copy of the job above, but with ryuk disabled. @@ -37,13 +38,14 @@ jobs: needs: test strategy: matrix: - go-version: [1.19.x, 1.x] + go-version: [1.20.x, 1.x] uses: ./.github/workflows/ci-test-go.yml with: go-version: {{ "${{ matrix.go-version }}" }} platform: "ubuntu-latest" project-directory: "." rootless-docker: false + run-tests: true ryuk-disabled: true # The job below is a copy of the job above, but with Docker rootless. @@ -53,7 +55,7 @@ jobs: needs: test strategy: matrix: - go-version: [1.19.x, 1.x] + go-version: [1.20.x, 1.x] platform: [ubuntu-latest] uses: ./.github/workflows/ci-test-go.yml with: @@ -61,12 +63,13 @@ jobs: platform: "ubuntu-latest" project-directory: "." rootless-docker: true + run-tests: true ryuk-disabled: false test-module-generator: strategy: matrix: - go-version: [1.19.x, 1.x] + go-version: [1.20.x, 1.x] platform: [ubuntu-latest, macos-latest] uses: ./.github/workflows/ci-test-go.yml with: @@ -74,31 +77,30 @@ jobs: platform: {{ "${{ matrix.platform }}" }} project-directory: "modulegen" rootless-docker: false + run-tests: true ryuk-disabled: false test-modules: needs: test strategy: matrix: - go-version: [1.19.x, 1.x] + go-version: [1.20.x, 1.x] platform: [ubuntu-latest, macos-latest] module: [{{ .Modules }}] - exclude: - - module: compose - go-version: 1.19.x uses: ./.github/workflows/ci-test-go.yml with: go-version: {{ "${{ matrix.go-version }}" }} platform: {{ "${{ matrix.platform }}" }} project-directory: {{ "modules/${{ matrix.module }}" }} rootless-docker: false + run-tests: {{ "${{ matrix.platform == 'ubuntu-latest' }}" }} ryuk-disabled: false test-examples: needs: test-modules strategy: matrix: - go-version: [1.19.x, 1.x] + go-version: [1.20.x, 1.x] platform: [ubuntu-latest, macos-latest] module: [{{ .Examples }}] uses: ./.github/workflows/ci-test-go.yml @@ -107,4 +109,5 @@ jobs: platform: {{ "${{ matrix.platform }}" }} project-directory: {{ "examples/${{ matrix.module }}" }} rootless-docker: false + run-tests: {{ "${{ matrix.platform == 'ubuntu-latest' }}" }} ryuk-disabled: false diff --git a/modulegen/_template/go.mod.tmpl b/modulegen/_template/go.mod.tmpl index 5b3e823b52..06d90bb26e 100644 --- a/modulegen/_template/go.mod.tmpl +++ b/modulegen/_template/go.mod.tmpl @@ -1,6 +1,6 @@ {{ $lower := ToLower }}module github.com/testcontainers/testcontainers-go/{{ ParentDir }}/{{ $lower }} -go 1.19 +go 1.20 require ( github.com/testcontainers/testcontainers-go {{ .TCVersion }} diff --git a/modulegen/go.mod b/modulegen/go.mod index d95904ed65..df75acc582 100644 --- a/modulegen/go.mod +++ b/modulegen/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/modulegen -go 1.19 +go 1.20 require ( github.com/stretchr/testify v1.8.4 diff --git a/modulegen/main_test.go b/modulegen/main_test.go index e8ac4dd81f..43d3300bae 100644 --- a/modulegen/main_test.go +++ b/modulegen/main_test.go @@ -477,11 +477,11 @@ func assertExampleGithubWorkflowContent(t *testing.T, example Example, exampleWo modulesList, err := getModulesOrExamplesAsString(true) assert.Nil(t, err) - assert.Equal(t, " module: ["+modulesList+"]", data[84]) + assert.Equal(t, " module: ["+modulesList+"]", data[88]) examplesList, err := getModulesOrExamplesAsString(false) assert.Nil(t, err) - assert.Equal(t, " module: ["+examplesList+"]", data[102]) + assert.Equal(t, " module: ["+examplesList+"]", data[104]) } // assert content go.mod diff --git a/modules/clickhouse/go.mod b/modules/clickhouse/go.mod index bac21ac916..e641f5c96f 100644 --- a/modules/clickhouse/go.mod +++ b/modules/clickhouse/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/modules/clickhouse -go 1.19 +go 1.20 require ( github.com/ClickHouse/clickhouse-go/v2 v2.13.0 diff --git a/modules/compose/go.mod b/modules/compose/go.mod index 2bb27cb8c0..fa285e6ead 100644 --- a/modules/compose/go.mod +++ b/modules/compose/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/modules/compose -go 1.19 +go 1.20 replace ( github.com/cucumber/godog => github.com/laurazard/godog v0.0.0-20220922095256-4c4b17abdae7 diff --git a/modules/k3s/go.mod b/modules/k3s/go.mod index dbe8edd322..65d19ba860 100644 --- a/modules/k3s/go.mod +++ b/modules/k3s/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/modules/k3s -go 1.19 +go 1.20 require ( github.com/docker/docker v24.0.5+incompatible diff --git a/modules/localstack/go.mod b/modules/localstack/go.mod index f89177c442..964f40a08d 100644 --- a/modules/localstack/go.mod +++ b/modules/localstack/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/modules/localstack -go 1.19 +go 1.20 require ( github.com/aws/aws-sdk-go v1.44.320 diff --git a/modules/mongodb/go.mod b/modules/mongodb/go.mod index 15c5742b6f..4dde00bd26 100644 --- a/modules/mongodb/go.mod +++ b/modules/mongodb/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/modules/mongodb -go 1.19 +go 1.20 require ( github.com/testcontainers/testcontainers-go v0.22.0 diff --git a/modules/mysql/go.mod b/modules/mysql/go.mod index 9528777ed5..562f453a48 100644 --- a/modules/mysql/go.mod +++ b/modules/mysql/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/modules/mysql -go 1.19 +go 1.20 require ( github.com/go-sql-driver/mysql v1.7.1 diff --git a/modules/neo4j/go.mod b/modules/neo4j/go.mod index 5be0ab2220..a486727c8d 100644 --- a/modules/neo4j/go.mod +++ b/modules/neo4j/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/modules/neo4j -go 1.19 +go 1.20 require ( github.com/docker/go-connections v0.4.0 diff --git a/modules/postgres/go.mod b/modules/postgres/go.mod index 0bc9b93d80..7e6b717c37 100644 --- a/modules/postgres/go.mod +++ b/modules/postgres/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/modules/postgres -go 1.19 +go 1.20 require ( github.com/docker/go-connections v0.4.0 diff --git a/modules/pulsar/go.mod b/modules/pulsar/go.mod index 61f38fae69..4c6679a292 100644 --- a/modules/pulsar/go.mod +++ b/modules/pulsar/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/modules/pulsar -go 1.19 +go 1.20 require ( github.com/apache/pulsar-client-go v0.10.0 diff --git a/modules/redis/go.mod b/modules/redis/go.mod index c6867f1312..67fbf8f8fc 100644 --- a/modules/redis/go.mod +++ b/modules/redis/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/modules/redis -go 1.19 +go 1.20 require ( github.com/go-redis/redis/v8 v8.11.5 diff --git a/modules/redpanda/go.mod b/modules/redpanda/go.mod index 5897bede00..ad2188c4fb 100644 --- a/modules/redpanda/go.mod +++ b/modules/redpanda/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/modules/redpanda -go 1.19 +go 1.20 require ( github.com/docker/go-connections v0.4.0 diff --git a/modules/vault/go.mod b/modules/vault/go.mod index e981e0bdbb..0eb6cdaa09 100644 --- a/modules/vault/go.mod +++ b/modules/vault/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/testcontainers-go/modules/vault -go 1.19 +go 1.20 require ( github.com/docker/docker v24.0.5+incompatible diff --git a/scripts/bump-go.sh b/scripts/bump-go.sh new file mode 100755 index 0000000000..c2684b8752 --- /dev/null +++ b/scripts/bump-go.sh @@ -0,0 +1,123 @@ +#!/usr/bin/env bash + +# This script is used to bump the version of Go in Testcontainers for Go, +# modifying the following files: +# - go.mod in the core module and submodules. +# - Markdown files explaining how to use Testcontainers for Go in the different CI systems. +# - Github action workflows using a test matrix to test Testcontainers for Go in different versions of Go. +# - Templates for the module generator. +# - Devcontainer file for VSCode. +# +# By default, it will be run in dry-run mode, which will print the commands that would be executed, without actually +# executing them. +# +# Usage: ./scripts/bump-go.sh "1.20" +# +# It's possible to run the script without dry-run mode actually executing the commands. +# +# Usage: DRY_RUN="false" ./scripts/go.sh "1.20" + +readonly CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +readonly DRY_RUN="${DRY_RUN:-true}" +readonly ROOT_DIR="$(dirname "$CURRENT_DIR")" +readonly GO_MOD_FILE="${ROOT_DIR}/go.mod" +readonly DEVCONTAINER_IMAGE_PREFIX="go:0-" + +function main() { + echo "Updating Go version:" + + local currentGoVersion="$(extractCurrentVersion)" + echo " - Current: ${currentGoVersion}" + local escapedCurrentGoVersion="$(echo "${currentGoVersion}" | sed 's/\./\\./g')" + + local goVersion="${1}" + local escapedGoVersion="$(echo "${goVersion}" | sed 's/\./\\./g')" + echo " - New: ${goVersion}" + + # bump mod files in all the modules + for modFile in $(find "${ROOT_DIR}" -name "go.mod" -not -path "${ROOT_DIR}/vendor/*" -not -path "${ROOT_DIR}/.git/*"); do + bumpModFile "${modFile}" "${escapedCurrentGoVersion}" "${escapedGoVersion}" + done + bumpModFile "${ROOT_DIR}/modulegen/_template/go.mod.tmpl" "${escapedCurrentGoVersion}" "${escapedGoVersion}" + + # bump markdown files + for f in $(find "${ROOT_DIR}" -name "*.md"); do + bumpGolangDockerImages "${f}" "${escapedCurrentGoVersion}" "${escapedGoVersion}" + done + + # bump github action workflows + for f in $(find "${ROOT_DIR}/.github/workflows" -name "*.yml"); do + bumpCIMatrix "${f}" "${escapedCurrentGoVersion}" "${escapedGoVersion}" + done + bumpCIMatrix "${ROOT_DIR}/modulegen/_template/ci.yml.tmpl" "${escapedCurrentGoVersion}" "${escapedGoVersion}" + + # bump devcontainer file + bumpDevcontainer "${ROOT_DIR}/.devcontainer/devcontainer.json" "${escapedCurrentGoVersion}" "${escapedGoVersion}" +} + +# it will replace the 'go-version: [${oldGoVersion}, 1.x]' with 'go-version: [${newGoVersion}, 1.x]' in the given file +function bumpCIMatrix() { + local file="${1}" + local oldGoVersion="${2}" + local newGoVersion="${3}" + + if [[ "${DRY_RUN}" == "true" ]]; then + echo "sed \"s/go-version: \[${oldGoVersion}/go-version: \[${newGoVersion}/g\" ${file} > ${file}.tmp" + echo "mv ${file}.tmp ${file}" + else + sed "s/go-version: \[${oldGoVersion}/go-version: \[${newGoVersion}/g" ${file} > ${file}.tmp + mv ${file}.tmp ${file} + fi +} + +# it will replace the 'go:0-${oldGoVersion}-bullseye' with 'go:0-${newGoVersion}-bullseye' in the given file +function bumpDevcontainer() { + local file="${1}" + local oldGoVersion="${2}" + local newGoVersion="${3}" + + if [[ "${DRY_RUN}" == "true" ]]; then + echo "sed \"s/${DEVCONTAINER_IMAGE_PREFIX}${oldGoVersion}/${DEVCONTAINER_IMAGE_PREFIX}${newGoVersion}/g\" ${file} > ${file}.tmp" + echo "mv ${file}.tmp ${file}" + else + sed "s/${DEVCONTAINER_IMAGE_PREFIX}${oldGoVersion}/${DEVCONTAINER_IMAGE_PREFIX}${newGoVersion}/g" ${file} > ${file}.tmp + mv ${file}.tmp ${file} + fi +} + +# it will replace the 'golang:${oldGoVersion}' with 'golang:${newGoVersion}' in the given file +function bumpGolangDockerImages() { + local file="${1}" + local oldGoVersion="${2}" + local newGoVersion="${3}" + + if [[ "${DRY_RUN}" == "true" ]]; then + echo "sed \"s/golang:${oldGoVersion}/golang:${newGoVersion}/g\" ${file} > ${file}.tmp" + echo "mv ${file}.tmp ${file}" + else + sed "s/golang:${oldGoVersion}/golang:${newGoVersion}/g" ${file} > ${file}.tmp + mv ${file}.tmp ${file} + fi +} + +# it will replace the 'go ${oldGoVersion}' with 'go ${newGoVersion}' in the given go.mod file +function bumpModFile() { + local goModFile="${1}" + local oldGoVersion="${2}" + local newGoVersion="${3}" + + if [[ "${DRY_RUN}" == "true" ]]; then + echo "sed \"s/^go ${oldGoVersion}/go ${newGoVersion}/g\" ${goModFile} > ${goModFile}.tmp" + echo "mv ${goModFile}.tmp ${goModFile}" + else + sed "s/^go ${oldGoVersion}/go ${newGoVersion}/g" ${goModFile} > ${goModFile}.tmp + mv ${goModFile}.tmp ${goModFile} + fi +} + +# This function reads the reaper.go file and extracts the current version. +function extractCurrentVersion() { + cat "${GO_MOD_FILE}" | grep '^go .*' | sed 's/^go //g' | head -n 1 +} + +main "$@" diff --git a/wait/testdata/go.mod b/wait/testdata/go.mod index 45ce6b64f8..e1a0955de6 100644 --- a/wait/testdata/go.mod +++ b/wait/testdata/go.mod @@ -1,3 +1,3 @@ module httptest -go 1.19 +go 1.20