Skip to content

Commit

Permalink
Adding windows build back and added ability to reproduce goreleaser b…
Browse files Browse the repository at this point in the history
…uilds locally (local-build.sh) in a way 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).
  • Loading branch information
patricknelson committed Oct 29, 2021
1 parent 984a2da commit 760d3a5
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 5 deletions.
26 changes: 22 additions & 4 deletions releasing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
[local-build.sh]: local-build.sh

Install [`cloud-build-local`], then run [localbuild.sh]:
Load the same version of `goreleaser` referenced in `cloudbuild.yaml` via docker and run [local-build.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/local-build.sh
```


### 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.
Expand Down
2 changes: 1 addition & 1 deletion releasing/localbuild.sh → releasing/cloudbuild-local.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
2 changes: 2 additions & 0 deletions releasing/cloudbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ builds:
goos:
- linux
- darwin
- windows
goarch:
- amd64
Expand All @@ -117,6 +118,7 @@ cat $goReleaserConfigFile
date

time /usr/local/bin/goreleaser release \
--debug \
--timeout 10m \
--parallelism 4 \
--config=$goReleaserConfigFile \
Expand Down
124 changes: 124 additions & 0 deletions releasing/local-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/bash
#
# Works exactly like cloudbuild.sh but doesn't perform a release.
#
# Usage (from top of repo):
#
# releasing/local-build.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 <<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 \
--skip-validate $remainingArgs

date

0 comments on commit 760d3a5

Please sign in to comment.