From a143688a1d5d6bd5455dbed5a35f9cc7db19ef72 Mon Sep 17 00:00:00 2001 From: Patrick Nelson Date: Wed, 10 Nov 2021 19:03:22 -0800 Subject: [PATCH 1/2] Step 1 of 2: Renaming localbuild.sh to cloudbuild-local.sh (preserve commit history) to make way for new localbuild.sh which will actually be entirely local, since this script is still very specific to Cloud Build. --- releasing/README.md | 8 ++++---- releasing/{localbuild.sh => cloudbuild-local.sh} | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) rename releasing/{localbuild.sh => cloudbuild-local.sh} (96%) mode change 100755 => 100644 diff --git a/releasing/README.md b/releasing/README.md index 45302e059b..4827d83cb2 100644 --- a/releasing/README.md +++ b/releasing/README.md @@ -595,14 +595,14 @@ git push upstream :latest_kustomize git tag -a latest_kustomize ``` -### Optionally build a release locally +### Optionally build and release locally -[localbuild.sh]: localbuild.sh +[cloudbuild-local.sh]: cloudbuild-local.sh -Install [`cloud-build-local`], then run [localbuild.sh]: +Install [`cloud-build-local`], then run [cloudbuild-local.sh]: ``` -./releasing/localbuild.sh $module +./releasing/cloudbuild-local.sh $module ``` This should create release artifacts in a local directory. diff --git a/releasing/localbuild.sh b/releasing/cloudbuild-local.sh old mode 100755 new mode 100644 similarity index 96% rename from releasing/localbuild.sh rename to releasing/cloudbuild-local.sh index 5a61c246cf..9e00c18d85 --- a/releasing/localbuild.sh +++ b/releasing/cloudbuild-local.sh @@ -8,7 +8,7 @@ # # Usage: from the repo root, enter: # -# ./releasing/localbuild.sh kustomize/v1.2.3 +# ./releasing/cloudbuild-local.sh kustomize/v1.2.3 # # or some other valid tag value. # From a5117083ecf97e64928727145723eddca5870c58 Mon Sep 17 00:00:00 2001 From: Patrick Nelson Date: Wed, 10 Nov 2021 19:06:04 -0800 Subject: [PATCH 2/2] Step 2 of 2: Adding windows build back and added ability to reproduce goreleaser builds locally (localbuild.sh) in a way exactly consistent with Cloud Build (cloudbuild.sh) but as a *build* only, without being coupled to Cloud Build or it's dependencies (like Cloud KMS, GitHub, etc). --- releasing/README.md | 18 +++++ releasing/cloudbuild-local.sh | 0 releasing/cloudbuild.sh | 2 + releasing/localbuild.sh | 125 ++++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+) mode change 100644 => 100755 releasing/cloudbuild-local.sh create mode 100755 releasing/localbuild.sh diff --git a/releasing/README.md b/releasing/README.md index 4827d83cb2..4543903232 100644 --- a/releasing/README.md +++ b/releasing/README.md @@ -595,6 +595,24 @@ git push upstream :latest_kustomize git tag -a latest_kustomize ``` +### Optionally build locally + +[localbuild.sh]: localbuild.sh + +Load the same version of `goreleaser` referenced in `cloudbuild.yaml` via docker and run [localbuild.sh] from the container's command line: + +``` +# Get goreleaser image from cloudbuild.yaml +export GORELEASER_IMAGE=goreleaser/goreleaser:v0.172.1 + +# Drop into a shell +docker run -it --entrypoint=/bin/bash -v $(pwd):/go/src/github.com/kubernetes-sigs/kustomize -w /go/src/github.com/kubernetes-sigs/kustomize $GORELEASER_IMAGE + +# Run build +./releasing/localbuild.sh TAG [--snapshot] +``` + + ### Optionally build and release locally [cloudbuild-local.sh]: cloudbuild-local.sh diff --git a/releasing/cloudbuild-local.sh b/releasing/cloudbuild-local.sh old mode 100644 new mode 100755 diff --git a/releasing/cloudbuild.sh b/releasing/cloudbuild.sh index a8590d39dd..d79daf0c59 100755 --- a/releasing/cloudbuild.sh +++ b/releasing/cloudbuild.sh @@ -92,6 +92,7 @@ builds: goos: - linux - darwin + - windows goarch: - amd64 @@ -117,6 +118,7 @@ cat $goReleaserConfigFile date time /usr/local/bin/goreleaser release \ + --debug \ --timeout 10m \ --parallelism 4 \ --config=$goReleaserConfigFile \ diff --git a/releasing/localbuild.sh b/releasing/localbuild.sh new file mode 100755 index 0000000000..1cff6e016c --- /dev/null +++ b/releasing/localbuild.sh @@ -0,0 +1,125 @@ +#!/bin/bash +# +# Works exactly like cloudbuild.sh but doesn't perform a release. +# +# Usage (from top of repo): +# +# releasing/localbuild.sh TAG [--snapshot] +# +# Where TAG is in the form +# +# api/v1.2.3 +# kustomize/v1.2.3 +# cmd/config/v1.2.3 +# ... etc. +# +# This script runs a build through goreleaser (http://goreleaser.com) but nothing else. +# + +set -e +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 <$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 + +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 build \ + --debug \ + --timeout 10m \ + --parallelism 4 \ + --config=$goReleaserConfigFile \ + --rm-dist \ + --skip-validate $remainingArgs + +date