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 ff7ea61
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 142 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -27,3 +27,6 @@ site/public/
site/resources/
site/.hugo_build.lock
**/node_modules/

# goreleaser artifacts
**/dist/
8 changes: 4 additions & 4 deletions releasing/README.md
Expand Up @@ -141,7 +141,7 @@ go mod edit -require=sigs.k8s.io/kustomize/kyaml@$versionKyaml plugin/builtin/pa

Create the PR:
```
createBranch pinToKyaml "Pin to kyaml $versionKyaml"
createBranch pinToKyaml "Update kyaml to $versionKyaml"
```
```
createPr
Expand Down Expand Up @@ -201,7 +201,7 @@ gorepomod pin cmd/config --doIt

Create the PR:
```
createBranch pinToCmdConfig "Pin to cmd/config $versionCmdConfig" &&
createBranch pinToCmdConfig "Update cmd/config to $versionCmdConfig" &&
createPr
```

Expand Down Expand Up @@ -256,7 +256,7 @@ gorepomod pin api --doIt

Create the PR:
```
createBranch pinToApi "Pin to api $versionApi" &&
createBranch pinToApi "Update api to $versionApi" &&
createPr
```

Expand Down 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
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 "$@"
2 changes: 1 addition & 1 deletion releasing/cloudbuild.yaml
Expand Up @@ -36,7 +36,7 @@ steps:

# Run goreleaser indirectly via a shell script
# to configure it properly.
- name: goreleaser/goreleaser:v0.172.1
- name: goreleaser/goreleaser:v0.179.0
timeout: 12m
entrypoint: /bin/sh
dir: myClone
Expand Down
53 changes: 53 additions & 0 deletions releasing/compile-changelog.sh
@@ -0,0 +1,53 @@
#!/bin/bash
#
# Builds a PR-oriented changelog from the git history for the given module.
#
# Usage (from top of repo):
#
# releasing/compile-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") )

# There is a 256 character limit on the query parameter for the GitHub API, so split into batches then deduplicate results
batchSize=5
results=""
for((i=0; i < ${#commits[@]}; i+=batchSize))
do
commitList=$(IFS="+"; echo "${commits[@]:i:batchSize}" | sed 's/ /+/g')
if newResults=$(curl -sSL "https://api.github.com/search/issues?q=$commitList+repo%3Akubernetes-sigs%2Fkustomize" | jq -r '[ .items[] | { number, title } ]'); then
results=$(echo "$results" "$newResults" | jq -s '.[0] + .[1] | unique')
else
echo "Failed to fetch results for commits: $commitList"
exit 1
fi
done

echo "${results}" | jq -r '.[] | select( .title | startswith("Back to development mode") | not) | "#\(.number): \(.title)" ' > "$changeLogFile"
90 changes: 57 additions & 33 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/compile-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,16 +126,26 @@ release:
EOF

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

args=(
--debug
--timeout 10m
--parallelism 7
--config="$goReleaserConfigFile"
--rm-dist
--skip-validate
)
if [[ $mode == "release" ]]; then
args+=(--release-notes="$changeLogFile")
fi

date

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

export PATH="/usr/local/bin:$PATH"
set -x
time goreleaser "$mode" "${args[@]}" $remainingArgs
date

0 comments on commit ff7ea61

Please sign in to comment.