Skip to content

Commit

Permalink
Converge local and cloud gorelease scripts, improve release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
KnVerey committed Mar 25, 2022
1 parent c4febc5 commit 2699944
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 131 deletions.
2 changes: 1 addition & 1 deletion releasing/README.md
Expand Up @@ -383,7 +383,7 @@ Image sha256 can be found in the image registry in the GCP
project [k8s-staging-kustomize].

Commit and push your changes. Then create a PR to [k8s.io] to promote
new images. Assign the PR to @monopole and @Shell32-natsu.
the new image.

## Update kustomize-in-kubectl

Expand Down
41 changes: 41 additions & 0 deletions releasing/build-changelog.sh
@@ -0,0 +1,41 @@
#!/bin/bash
#
# Builds a PR-oriented changelog from the git history for the given module.
#
# Usage (from top of repo):
#
# releasing/build-changelog.sh MODULE TAG CHANGE_LOG_FILE
#
# Where TAG is in the form
#
# api/v1.2.3
# kustomize/v1.2.3
# cmd/config/v1.2.3
# ... etc.
#

set -o errexit
set -o nounset
set -o pipefail

if [[ -z "${1-}" ]] || [[ -z "${2-}" ]] || [[ -z "${3-}" ]]; then
echo "Usage: $0 <module> <fullTag> <changeLogFile>"
echo "Example: $0 kyaml kyaml/v0.13.4 changelog.txt"
exit 1
fi

module=$1
fullTag=$2
changeLogFile=$3

# Find previous tag that matches the tags module
prevTag=$(git tag -l "$module*" --sort=-version:refname --no-contains="$fullTag" | head -n 1)

commits=$(git log "$prevTag".."$fullTag" \
--pretty=format:'%h' \
--abbrev-commit --no-decorate --no-color --no-merges \
-- "$module")

commitList=$(echo "$commits" | paste -s -d'+' -)

curl -sL "https://api.github.com/search/issues?q=$commitList+repo%3Akubernetes-sigs%2Fkustomize" | jq -r '.items[] | "#\(.number): \(.title) "' > "$changeLogFile"
105 changes: 1 addition & 104 deletions releasing/cloudbuild.sh
Expand Up @@ -24,108 +24,5 @@ set -x

fullTag=$1
shift
echo "fullTag=$fullTag"

remainingArgs="$@"
echo "Remaining args: $remainingArgs"

# Take everything before the last slash.
# This is expected to match $module.
module=${fullTag%/*}
echo "module=$module"

# Find previous tag that matches the tags module
prevTag=$(git tag -l "$module*" --sort=-version:refname --no-contains=$fullTag | head -n 1)

# Generate the changelog for this release
# using the last two tags for the module
changeLogFile=$(mktemp)
git log $prevTag..$fullTag \
--pretty=oneline \
--abbrev-commit --no-decorate --no-color --no-merges \
-- $module > $changeLogFile
echo "Release notes:"
cat $changeLogFile

# Take everything after the last slash.
# This should be something like "v1.2.3".
semVer=`echo $fullTag | sed "s|$module/||"`
echo "semVer=$semVer"

# This is probably a directory called /workspace
echo "pwd = $PWD"

# Sanity check
echo "### ls -las . ################################"
ls -las .
echo "###################################"


# CD into the module directory.
# This directory expected to contain a main.go, so there's
# no need for extra details in the `build` stanza below.
cd $module

skipBuild=true
if [[ "$module" == "kustomize" || "$module" == "pluginator" ]]; then
# If releasing a main program, don't skip the build.
skipBuild=false
fi

goReleaserConfigFile=$(mktemp)

cat <<EOF >$goReleaserConfigFile
project_name: $module
archives:
- name_template: "${module}_${semVer}_{{ .Os }}_{{ .Arch }}"
builds:
- skip: $skipBuild
ldflags: >
-s
-X sigs.k8s.io/kustomize/api/provenance.version={{.Version}}
-X sigs.k8s.io/kustomize/api/provenance.gitCommit={{.Commit}}
-X sigs.k8s.io/kustomize/api/provenance.buildDate={{.Date}}
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
- s390x
- ppc64le
checksum:
name_template: 'checksums.txt'
env:
- CGO_ENABLED=0
- GO111MODULE=on
release:
github:
owner: kubernetes-sigs
name: kustomize
draft: true
EOF

cat $goReleaserConfigFile

date

time /usr/local/bin/goreleaser release \
--debug \
--timeout 10m \
--parallelism 7 \
--config=$goReleaserConfigFile \
--release-notes=$changeLogFile \
--rm-dist \
--skip-validate $remainingArgs

date
./releasing/run-goreleaser.sh "$fullTag" release "$@"
71 changes: 45 additions & 26 deletions releasing/localbuild.sh → releasing/run-goreleaser.sh
@@ -1,10 +1,10 @@
#!/bin/bash
#
# Works exactly like cloudbuild.sh but doesn't perform a release.
# Builds and optionally releases the specified module
#
# Usage (from top of repo):
#
# releasing/localbuild.sh TAG [--snapshot]
# releasing/localbuild.sh TAG MODE[build|release] [--snapshot]
#
# Where TAG is in the form
#
Expand All @@ -13,56 +13,70 @@
# cmd/config/v1.2.3
# ... etc.
#
# This script runs a build through goreleaser (http://goreleaser.com) but nothing else.
#

set -e
set -x
set -o errexit
set -o nounset
set -o pipefail

if [[ -z "${1-}" || -z "${2-}" ]]; then
echo "Usage: $0 TAG MODE [goreleaser flags]"
echo " TAG: the tag to build or release, e.g. api/v1.2.3"
echo " MODE: build or release"
exit 1
fi

fullTag=$1
shift
echo "fullTag=$fullTag"

if [[ $1 == "release" || $1 == "build" ]]; then
mode=$1
shift
else
echo "Error: mode must be build or release"
exit 1
fi

remainingArgs="$@"
echo "Remaining args: $remainingArgs"
echo "Remaining args: $remainingArgs"

# Take everything before the last slash.
# This is expected to match $module.
module=${fullTag%/*}
echo "module=$module"

# Find previous tag that matches the tags module
prevTag=$(git tag -l "$module*" --sort=-version:refname --no-contains=$fullTag | head -n 1)
# Take everything after the last slash.
# This should be something like "v1.2.3".
semVer=${fullTag#$module/}
echo "semVer=$semVer"

# Generate the changelog for this release
# using the last two tags for the module
changeLogFile=$(mktemp)
git log $prevTag..$fullTag \
--pretty=oneline \
--abbrev-commit --no-decorate --no-color --no-merges \
-- $module > $changeLogFile
echo "Release notes:"
cat $changeLogFile

# Take everything after the last slash.
# This should be something like "v1.2.3".
semVer=`echo $fullTag | sed "s|$module/||"`
echo "semVer=$semVer"
./releasing/build-changelog.sh "$module" "$fullTag" "$changeLogFile"
echo
echo "######### Release notes: ##########"
cat "$changeLogFile"
echo "###################################"
echo

# This is probably a directory called /workspace
echo "pwd = $PWD"

# Sanity check
echo "### ls -las . ################################"
echo
echo "############ DEBUG ##############"
echo "pwd = $PWD"
echo "ls -las ."
ls -las .
echo "###################################"

echo

# CD into the module directory.
# This directory expected to contain a main.go, so there's
# no need for extra details in the `build` stanza below.
cd $module

# This is used in goreleaser.yaml
skipBuild=true
if [[ "$module" == "kustomize" || "$module" == "pluginator" ]]; then
# If releasing a main program, don't skip the build.
Expand Down Expand Up @@ -112,15 +126,20 @@ release:
EOF

cat $goReleaserConfigFile
echo
echo "############# CONFIG ##############"
cat "$goReleaserConfigFile"
echo "###################################"
echo

date

time /usr/local/bin/goreleaser build \
time /usr/local/bin/goreleaser "$mode" \
--debug \
--timeout 10m \
--parallelism 7 \
--config=$goReleaserConfigFile \
--config="$goReleaserConfigFile" \
--release-notes="$changeLogFile" \
--rm-dist \
--skip-validate $remainingArgs

Expand Down

0 comments on commit 2699944

Please sign in to comment.