Merge pull request #4262 from patricknelson/fix-windows-build

Fix windows build, add clarity to goreleaser build (due to race conditions).
This commit is contained in:
Kubernetes Prow Robot
2021-11-11 13:32:08 -08:00
committed by GitHub
4 changed files with 186 additions and 41 deletions

View File

@@ -595,14 +595,32 @@ git push upstream :latest_kustomize
git tag -a latest_kustomize
```
### Optionally build a release locally
### Optionally build locally
[localbuild.sh]: localbuild.sh
Install [`cloud-build-local`], then run [localbuild.sh]:
Load the same version of `goreleaser` referenced in `cloudbuild.yaml` via docker and run [localbuild.sh] from the container's command line:
```
./releasing/localbuild.sh $module
# 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
Install [`cloud-build-local`], then run [cloudbuild-local.sh]:
```
./releasing/cloudbuild-local.sh $module
```
This should create release artifacts in a local directory.

54
releasing/cloudbuild-local.sh Executable file
View File

@@ -0,0 +1,54 @@
#!/bin/bash
#
# To test the release process, this script attempts
# to use a Google cloudbuild configuration to create
# release artifacts locally.
#
# See https://cloud.google.com/cloud-build/docs/build-debug-locally
#
# Usage: from the repo root, enter:
#
# ./releasing/cloudbuild-local.sh kustomize/v1.2.3
#
# or some other valid tag value.
#
# IMPORTANT:
# The process clones the repo at the given tag,
# so the repo must have the tag applied upstream.
# Either use an old tag, or disable the cloud build
# trigger so that a new testing tag can be applied
# without setting off a cloud build.
set -e
config=$(mktemp)
cp releasing/cloudbuild.yaml $config
# Add the --snapshot flag to suppress the
# github release and leave the build output
# in the kustomize/dist directory.
sed -i "s|# - '--snapshot|- '--snapshot|" $config
echo "Executing cloud-build-local with config file $config :"
echo "========================="
cat $config
echo "========================="
workspace=~/cloud-build-local-workspace
cloud-build-local \
--config=$config \
--substitutions=TAG_NAME=$1 \
--write-workspace=$workspace \
--dryrun=false \
.
# --bind-mount-source \
echo " "
echo "Result of local build:"
echo "##########################################"
tree ./$module/dist
echo "##########################################"
tree ./$workspace
echo "##########################################"

View File

@@ -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 \

View File

@@ -1,54 +1,125 @@
#!/bin/bash
#
# To test the release process, this script attempts
# to use a Google cloudbuild configuration to create
# release artifacts locally.
# Works exactly like cloudbuild.sh but doesn't perform a release.
#
# See https://cloud.google.com/cloud-build/docs/build-debug-locally
# Usage (from top of repo):
#
# Usage: from the repo root, enter:
# releasing/localbuild.sh TAG [--snapshot]
#
# ./releasing/localbuild.sh kustomize/v1.2.3
# Where TAG is in the form
#
# or some other valid tag value.
# 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.
#
# IMPORTANT:
# The process clones the repo at the given tag,
# so the repo must have the tag applied upstream.
# Either use an old tag, or disable the cloud build
# trigger so that a new testing tag can be applied
# without setting off a cloud build.
set -e
set -x
config=$(mktemp)
cp releasing/cloudbuild.yaml $config
fullTag=$1
shift
echo "fullTag=$fullTag"
# Add the --snapshot flag to suppress the
# github release and leave the build output
# in the kustomize/dist directory.
sed -i "s|# - '--snapshot|- '--snapshot|" $config
remainingArgs="$@"
echo "Remaining args: $remainingArgs"
echo "Executing cloud-build-local with config file $config :"
echo "========================="
cat $config
echo "========================="
# Take everything before the last slash.
# This is expected to match $module.
module=${fullTag%/*}
echo "module=$module"
workspace=~/cloud-build-local-workspace
# Find previous tag that matches the tags module
prevTag=$(git tag -l "$module*" --sort=-version:refname --no-contains=$fullTag | head -n 1)
cloud-build-local \
--config=$config \
--substitutions=TAG_NAME=$1 \
--write-workspace=$workspace \
--dryrun=false \
.
# 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
# --bind-mount-source \
# Take everything after the last slash.
# This should be something like "v1.2.3".
semVer=`echo $fullTag | sed "s|$module/||"`
echo "semVer=$semVer"
echo " "
echo "Result of local build:"
echo "##########################################"
tree ./$module/dist
echo "##########################################"
tree ./$workspace
echo "##########################################"
# 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
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