Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: automate the creation of a release #776

Merged
merged 34 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a7da93c
chore: automate the creation of tags for all modules
mdelapenya Jan 25, 2023
a17984a
chore: release the entire library with the same script
mdelapenya Jan 25, 2023
dbc4c7d
Merge branch 'main' into automate-tag-creation
mdelapenya Feb 10, 2023
2832898
chore: support pushing the new module versions to pkg.go.dev
mdelapenya Feb 10, 2023
6649003
chore: consistency in variable names
mdelapenya Feb 10, 2023
df0afcf
chore: extract tagging to a function
mdelapenya Feb 10, 2023
eac8d48
chore: extract curl to a function
mdelapenya Feb 10, 2023
3146288
chore: extract git push to a function
mdelapenya Feb 10, 2023
987d35a
chore: extract to main function
mdelapenya Feb 10, 2023
97d04cc
chore: support running the script in DRY_RUN mode
mdelapenya Feb 10, 2023
f998da0
fix: loop through all modules
mdelapenya Feb 10, 2023
cee171d
fix: remove extra slash in URL
mdelapenya Feb 10, 2023
0b0fe9f
docs: document the script
mdelapenya Feb 10, 2023
b26775b
chore: extract version from version file
mdelapenya Feb 10, 2023
1bf469b
docs: link to pkg.go.dev for info
mdelapenya Feb 10, 2023
06a8738
docs: document the release script
mdelapenya Feb 10, 2023
ca03cb7
fix: do not POST
mdelapenya Feb 10, 2023
0124e6b
Merge branch 'main' into automate-tag-creation
mdelapenya Feb 14, 2023
95d2ee3
feat: add localstack module (#800)
mdelapenya Feb 14, 2023
a909e4f
chore(deps): bump go.mongodb.org/mongo-driver in /examples/mongodb (#…
dependabot[bot] Feb 14, 2023
05fbd46
chore(deps): bump google.golang.org/api from 0.109.0 to 0.110.0 in /e…
mdelapenya Feb 14, 2023
55faa4a
feat: support generating Go modules or example modules (#826)
mdelapenya Feb 14, 2023
6ca0a38
chore(deps): bump github.com/imdario/mergo in /modules/localstack (#828)
dependabot[bot] Feb 14, 2023
057c4f0
chore(deps): bump github.com/aws/aws-sdk-go in /modules/localstack (#…
dependabot[bot] Feb 14, 2023
1fea3ed
fix: always absolute paths when tarring files to a Docker container (…
mdelapenya Feb 15, 2023
ef75f84
chore(deps): bump github.com/docker/compose/v2 from 2.15.1 to 2.16.0 …
dependabot[bot] Feb 15, 2023
b75454d
chore: run in dry-run mode by default
mdelapenya Feb 15, 2023
ef24793
chore: bump the version file to the next minor
mdelapenya Feb 16, 2023
6d2f078
chore: support for setting the bump type (major, minor, patch)
mdelapenya Feb 16, 2023
0bcb383
chore: update mkdocs.yml file
mdelapenya Feb 16, 2023
092d0eb
chore: reduce post-script instructions
mdelapenya Feb 16, 2023
b2dcc71
chore: restore git state
mdelapenya Feb 16, 2023
f9d1c5f
chore: extract git to a function
mdelapenya Feb 16, 2023
ef265a0
Merge branch 'main' into automate-tag-creation
mdelapenya Feb 16, 2023
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
82 changes: 82 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Releasing Testcontainers for Go

In order to create a release, we have added a shell script that performs all the tasks for you, allowing a dry-run mode for checking it before creating the release. We are going to explain how to use it in this document.

First, it's really important that you first check that the [version.go](./internal/version.go) file is up-to-date, containing the right version you want to create. That file will be used by the automation to perform the release.
Once the version file is correct in the repository:

- Run the [release.sh](./scripts/release.sh) shell script.
- You can run the script in dry-run mode setting `DRY_RUN=true` in the environment:

DRY_RUN="true" ./scripts/release.sh

- The script will create a git tag with the current value of the [version.go](./internal/version.go) file, starting with `v`: e.g. `v0.18.0`, for the following Go modules:
- the root module, representing the Testcontainers for Go library.
- all the Go modules living in both the `examples` and `modules` directory. The git tag value for these Go modules will be created using this name convention:

"${directory}/${module_name}/${version}", e.g. "examples/mysql/v0.18.0", "modules/compose/v0.18.0"

- The script will push the git tags to the upstream repository, https://github.com/testcontainers/testcontainers-go

An example execution, with dry-run mode enabled:

```
$ DRY_RUN=true ./scripts/release.sh
git tag -d v0.18.0 | true
git tag v0.18.0
git tag -d examples/bigtable/v0.18.0 | true
git tag examples/bigtable/v0.18.0
git tag -d examples/cockroachdb/v0.18.0 | true
git tag examples/cockroachdb/v0.18.0
git tag -d examples/consul/v0.18.0 | true
git tag examples/consul/v0.18.0
git tag -d examples/datastore/v0.18.0 | true
git tag examples/datastore/v0.18.0
git tag -d examples/firestore/v0.18.0 | true
git tag examples/firestore/v0.18.0
git tag -d examples/localstack/v0.18.0 | true
git tag examples/localstack/v0.18.0
git tag -d examples/mongodb/v0.18.0 | true
git tag examples/mongodb/v0.18.0
git tag -d examples/mysql/v0.18.0 | true
git tag examples/mysql/v0.18.0
git tag -d examples/nginx/v0.18.0 | true
git tag examples/nginx/v0.18.0
git tag -d examples/postgres/v0.18.0 | true
git tag examples/postgres/v0.18.0
git tag -d examples/pubsub/v0.18.0 | true
git tag examples/pubsub/v0.18.0
git tag -d examples/pulsar/v0.18.0 | true
git tag examples/pulsar/v0.18.0
git tag -d examples/redis/v0.18.0 | true
git tag examples/redis/v0.18.0
git tag -d examples/spanner/v0.18.0 | true
git tag examples/spanner/v0.18.0
git tag -d examples/toxiproxy/v0.18.0 | true
git tag examples/toxiproxy/v0.18.0
git tag -d modules/compose/v0.18.0 | true
git tag modules/compose/v0.18.0
git push --tags
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/bigtable/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/cockroachdb/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/consul/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/datastore/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/firestore/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/localstack/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/mongodb/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/mysql/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/nginx/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/postgres/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/pubsub/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/pulsar/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/redis/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/spanner/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/examples/toxiproxy/@v/v0.18.0
curl https://proxy.golang.org/github.com/testcontainers/testcontainers-go/modules/compose/@v/v0.18.0
```

Right after that, you have to:
- Bump the version in the [version.go](./internal/version.go) file to the next development version, following [Semantic Versioning](https://semver.org). e.g. `v0.19.0`
- Update the [mkdocs.yml](./mkdocs.yml) file with the next development version.
- Commit those files and submit a pull request, using `chore` as Github label.
102 changes: 102 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env bash

# This script is used to release a new version of the Testcontainers for Go library.
# It creates a tag for the root module and for each module in the modules directory,
# and then triggers the Go proxy to fetch the module.
#
# Usage: ./scripts/release.sh "v0.0.1"
# where v0.0.1 is the tag to be created.
#
# It's possible to run the script in dry-run mode, which will print the commands that
# would be executed, without actually executing them.
#
# Usage: DRY_RUN="true" ./scripts/release.sh "v0.0.1"

readonly DRY_RUN="${DRY_RUN:-false}"
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
readonly CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
readonly ROOT_DIR="$(dirname "$CURRENT_DIR")"
readonly VERSION_FILE="${ROOT_DIR}/internal/version.go"

readonly REPOSITORY="github.com/testcontainers/testcontainers-go"

function main() {
readonly version="v$(extractCurrentVersion)"

tagModule "${version}"

readonly DIRECTORIES=(examples modules)

for directory in "${DIRECTORIES[@]}"
do
cd "${ROOT_DIR}/${directory}"

ls -d */ | grep -v "_template" | while read -r module; do
module="${module%?}" # remove trailing slash
module_tag="${directory}/${module}/${version}" # e.g. modules/mongodb/v0.0.1
tagModule "${module_tag}"
done
done

gitPushTags

curlGolangProxy "${REPOSITORY}" "${version}" # e.g. github.com/testcontainers/testcontainers-go/@v/v0.0.1

for directory in "${DIRECTORIES[@]}"
do
cd "${ROOT_DIR}/${directory}"

ls -d */ | grep -v "_template" | while read -r module; do
module="${module%?}" # remove trailing slash
module_path="${REPOSITORY}/${directory}/${module}"
curlGolangProxy "${module_path}" "${version}" # e.g. github.com/testcontainers/testcontainers-go/modules/mongodb/@v/v0.0.1
done
done
}

# This function is used to trigger the Go proxy to fetch the module.
# See https://pkg.go.dev/about#adding-a-package for more details.
function curlGolangProxy() {
local module_path="${1}"
local module_version="${2}"

if [[ "${DRY_RUN}" == "true" ]]; then
echo "curl https://proxy.golang.org/${module_path}/@v/${module_version}"
return
fi

# e.g.:
# github.com/testcontainers/testcontainers-go/v0.0.1
# github.com/testcontainers/testcontainers-go/modules/mongodb/v0.0.1
curl "https://proxy.golang.org/${module_path}/@v/${module_version}"
}

# This function reads the version.go file and extracts the current version.
function extractCurrentVersion() {
cat "${VERSION_FILE}" | grep 'const Version = ' | cut -d '"' -f 2
}

# This function is used to push the tags to the remote repository.
function gitPushTags() {
if [[ "${DRY_RUN}" == "true" ]]; then
echo "git push --tags"
return
fi

git push --tags
}

# This function is used to create a tag for the module.
function tagModule() {
local module_tag="${1}"

if [[ "${DRY_RUN}" == "true" ]]; then
echo "git tag -d ${module_tag} | true"
echo "git tag ${module_tag}"
return
fi

git tag -d "${module_tag}" | true # do not fail if tag does not exist
git tag "${module_tag}"
}

main "$@"