Skip to content

Commit

Permalink
go: Tag polyglot go releases with go/vVERSION
Browse files Browse the repository at this point in the history
> https://go.dev/ref/mod#vcs-version
> If a module is defined in a subdirectory within the repository, that is, the
> module subdirectory portion of the module path is not empty, then each tag
> name must be prefixed with the module subdirectory, followed by a slash. For
> example, the module golang.org/x/tools/gopls is defined in the gopls
> subdirectory of the repository with root path golang.org/x/tools. The
> version v0.4.0 of that module must have the tag named gopls/v0.4.0 in that
> repository.

Currently, releases are only tagged with `vVERSION`. So to make go happy we
have to add a `go/vVERSION` tag.

Fixes: #91
  • Loading branch information
mpkorstanje committed Dec 27, 2022
1 parent 0e7cd7b commit 569d480
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased]
### Fixed
- Go: Tag polyglot go releases with go/vVERSION ([#93](https://github.com/cucumber/polyglot-release/pull/93))

## [1.3.1] - 2022-12-17
### Fixed
Expand Down
43 changes: 32 additions & 11 deletions polyglot-release
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ function run() {
eval "$1_$2"
fi
}
# Usage 'decorate "prefix" "suffix" "${TAGS{@}}"'
function decorate() {
local prefix=$1
local suffix=$2
local tags=()

for tag in "${@:3}" ; do
tags+=("${prefix}${tag}${suffix}")
done
echo "${tags[@]}"
}

SUPPORTED_LANGUAGES=()

SUPPORTED_LANGUAGES+=("c")
Expand Down Expand Up @@ -104,6 +116,10 @@ function is_monoglot_go() {
}
function pre_release_go() {
check_for_tools "go" "jq" "sed" "find"
if [[ $PWD == */go ]]; then
# Use an additional tag. See: https://go.dev/ref/mod#vcs-version
TAGS+=("go/v$NEW_VERSION");
fi
}
function release_go() {
local module_with_old_version
Expand Down Expand Up @@ -466,6 +482,7 @@ Created-by: polyglot-release v${POLYGLOT_RELEASE_VERSION:--develop}"

# Initialize global variables
NEW_VERSION=
TAGS=()
NO_GIT_PUSH=
POLYGLOT_RELEASE_VERSION=
POLYGLOT_RELEASE_GIT_REPO=${POLYGLOT_RELEASE_GIT_REPO:-https://github.com/cucumber/polyglot-release}
Expand Down Expand Up @@ -530,6 +547,8 @@ if [[ $# -ne 1 ]]; then
exit 1
fi
NEW_VERSION=$1
NEW_VERSION_TAG="v$NEW_VERSION"
TAGS+=("$NEW_VERSION_TAG")
validate_new_version_argument

commit_before_release="$(git rev-parse HEAD)"
Expand Down Expand Up @@ -557,10 +576,11 @@ log "Package manager manifests and CHANGELOG.md updated for $NEW_VERSION"
log "Here's what changed:"
log "$(git -c color.diff=always diff)"

TAG="v$NEW_VERSION"
git commit --gpg-sign --quiet --all --message="$(format_commit_message "Prepare release $TAG")"
git tag --sign --message "$(format_commit_message "$TAG")" "$TAG"
log "Files committed to to git and tagged '$TAG'"
git commit --gpg-sign --quiet --all --message="$(format_commit_message "Prepare release $NEW_VERSION_TAG")"
for tag in "${TAGS[@]}"; do
git tag --sign --message "$(format_commit_message "$NEW_VERSION_TAG")" "$tag"
done
log "Files committed to to git and tagged $(decorate "'" "'" "${TAGS[@]}")"

###
## post release
Expand All @@ -578,21 +598,22 @@ fi
# push to github
##
local_branch=$(git rev-parse --abbrev-ref HEAD)
release_commit=$(git rev-list --max-count=1 "$TAG")
release_branch="release/$TAG"
release_commit=$(git rev-list --max-count=1 "$NEW_VERSION_TAG")
release_branch="release/$NEW_VERSION_TAG"
if [[ -z $NO_GIT_PUSH ]]; then
git push --quiet --atomic origin "refs/heads/$local_branch" "refs/tags/$TAG" "$release_commit:refs/heads/$release_branch"
log "Tag $TAG pushed to origin"
# shellcheck disable=SC2046
git push --quiet --atomic origin "refs/heads/$local_branch" $(decorate "refs/tags/" "" "${TAGS[@]}") "$release_commit:refs/heads/$release_branch"
log "Tag(s) ${TAGS[*]} pushed to origin"
log "All commit(s) pushed to origin/$local_branch"
log "Release commit (tagged with $TAG) pushed to origin/$release_branch"
log "Release commit (tagged with $(decorate "'" "'" "${TAGS[@]}")) pushed to origin/$release_branch"
if [[ -n $QUIET ]]; then
echo "$release_branch"
fi
else
log "You now need to eyeball these commits, then push manually:"
log
log "# push local commits and tags to $local_branch"
log "git push origin refs/heads/$local_branch refs/tags/$TAG"
log "git push origin refs/heads/$local_branch $(decorate "refs/tags/" "" "${TAGS[@]}")"
log
log "# push to release branch"
log "git push origin $release_commit:refs/heads/$release_branch"
Expand All @@ -604,5 +625,5 @@ else
log "git reset --hard $commit_before_release"
log
log "# delete the git tag that was created"
log "git tag -d $TAG"
log "git tag -d ${TAGS[*]}"
fi
18 changes: 18 additions & 0 deletions tests/fixtures/go-polyglot/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Fixed
- This is a test

## [0.0.1] - 2000-01-01

## [0.0.0] - 2000-01-01

[Unreleased]: https://github.com/cucumber/polyglot-release/compare/v0.0.1...main
[0.0.1]: https://github.com/cucumber/polyglot-release/compare/v0.0.0...v0.0.1
3 changes: 3 additions & 0 deletions tests/fixtures/go-polyglot/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/example/project/v0

go 1.18
2 changes: 2 additions & 0 deletions tests/only-release-go-polyglot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# fixture: go-polyglot
polyglot-release 1.0.0
2 changes: 2 additions & 0 deletions tests/only-release-go-polyglot.sh.expected.git-log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Prepare release v1.0.0 (HEAD -> main, tag: v1.0.0, tag: go/v1.0.0, origin/release/v1.0.0, origin/main)
Initial commit (tag: v0.0.1)
2 changes: 1 addition & 1 deletion tests/release.sh.expected.output
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ Files committed to to git and tagged 'v1.0.0'
Post-release changes committed to to git
Tag v1.0.0 pushed to origin
All commit(s) pushed to origin/main
Release commit (tagged with v1.0.0) pushed to origin/release/v1.0.0
Release commit (tagged with 'v1.0.0') pushed to origin/release/v1.0.0

0 comments on commit 569d480

Please sign in to comment.