Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
Bundled third party notices and source code with executable for relea…
Browse files Browse the repository at this point in the history
…se (#287)

* Bundled third party notices and source code with executable for release

* Updated docs
  • Loading branch information
melinath authored Aug 11, 2021
1 parent f3f95a0 commit e314839
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Binaries
terraform-validator
bin/terraform-validator*
# Builds
bin/
release/

# Sensitive
credentials.json
Expand Down
19 changes: 11 additions & 8 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ for example:
```
$ gsutil ls -r "gs://terraform-validator/releases/v*"
...
gs://terraform-validator/releases/v0.4.0/:
gs://terraform-validator/releases/v0.4.0/terraform-validator-darwin-amd64
gs://terraform-validator/releases/v0.4.0/terraform-validator-linux-amd64
gs://terraform-validator/releases/v0.4.0/terraform-validator-windows-amd64
gs://terraform-validator/releases/v0.6.0/:
gs://terraform-validator/releases/v0.6.0/terraform-validator_darwin_amd64-0.6.0.tar.gz
gs://terraform-validator/releases/v0.6.0/terraform-validator_darwin_arm64-0.6.0.tar.gz
gs://terraform-validator/releases/v0.6.0/terraform-validator_linux_amd64-0.6.0.tar.gz
gs://terraform-validator/releases/v0.6.0/terraform-validator_linux_arm64-0.6.0.tar.gz
gs://terraform-validator/releases/v0.6.0/terraform-validator_windows_amd64-0.6.0.tar.gz
```

To download the binary, you need to
[install](https://cloud.google.com/storage/docs/gsutil_install#install) the
`gsutil` tool first. The following command downloads the Linux version of
Terraform Validator from vX.X.X release to your local directory:
`gsutil` tool first. The following commands download and uncompress the Linux AMD64
version of Terraform Validator from v0.6.0 release to your local directory:

```
gsutil cp gs://terraform-validator/releases/vX.X.X/terraform-validator-linux-amd64 .
chmod 755 terraform-validator-linux-amd64
gsutil cp gs://terraform-validator/releases/v0.6.0/terraform-validator_linux_amd64-0.6.0.tar.gz .
tar -xzvf terraform-validator_linux_amd64-0.6.0.tar.gz
chmod 755 terraform-validator
```

The full list of releases, with release notes, is available [on Github](https://github.com/GoogleCloudPlatform/terraform-validator/releases).
37 changes: 27 additions & 10 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,35 @@ fi

version=$1

if ! echo $version | grep -Eq "^v[0-9]+\.[0-9]+\.[0-9]+$"
if ! echo $version | grep -Eq "^[0-9]+\.[0-9]+\.[0-9]+$"
then
echo "Invalid version: ${version}"
echo "Please specify a semantic version prefixed with a v (e.g. v0.0.0)."
echo "Please specify a semantic version with no prefix (e.g. X.X.X)."
exit 1
fi

release_dir="./release/${version}"
rm -rf $release_dir
mkdir -p $release_dir

echo "Go version: $(go version)"
go get github.com/google/go-licenses
echo "Downloading licenses and source code to bundle..."
# Ignore errors until https://github.com/google/go-licenses/pull/77 is merged
set +e
go-licenses save "github.com/GoogleCloudPlatform/terraform-validator" --save_path="./${release_dir}/THIRD_PARTY_NOTICES"
set -e
echo "Zipping licenses and source code..."
pushd "${release_dir}" > /dev/null
zip -rq9D "THIRD_PARTY_NOTICES.zip" "THIRD_PARTY_NOTICES/"
popd > /dev/null

architectures="amd64 arm64"
platforms="linux windows darwin"
skip_platform_arch_pairs=" windows/arm64 "

build_dir=./bin
name=terraform-validator
ldflags="-X github.com/GoogleCloudPlatform/terraform-validator/tfgcv.buildVersion=${version}"
binary_name=terraform-validator
ldflags="-X github.com/GoogleCloudPlatform/terraform-validator/tfgcv.buildVersion=v${version}"
release_bucket=terraform-validator

# Build release versions
Expand All @@ -34,10 +49,12 @@ for platform in ${platforms}; do
continue
fi


echo "Building version ${version} for platform ${platform} / arch ${arch}..."
GO111MODULE=on GOOS=${platform} GOARCH=${arch} CGO_ENABLED=0 go build -ldflags "${ldflags}" -o "${build_dir}/${name}-${platform}-${arch}" .
echo "Done building version ${version} for platform ${platform} / arch ${arch}"
echo "Building ${binary_name} v${version} for platform ${platform} / arch ${arch}..."
GO111MODULE=on GOOS=${platform} GOARCH=${arch} CGO_ENABLED=0 go build -ldflags "${ldflags}" -o "${release_dir}/${binary_name}" .
echo "Creating ${release_dir}/${binary_name}_${platform}_${arch}-${version}.tar.gz"
pushd "${release_dir}" > /dev/null
tar -czf "${binary_name}_${platform}_${arch}-${version}.tar.gz" "${binary_name}" "THIRD_PARTY_NOTICES.zip"
popd > /dev/null
done
done

Expand All @@ -49,7 +66,7 @@ echo "Github tag ${version} created"
# Publish release versions
echo "Pushing releases to Google Storage"
for arch in ${architectures}; do
gsutil cp ${build_dir}/*-${arch} gs://${release_bucket}/releases/${version}
gsutil cp ${release_dir}/*.tar.gz gs://${release_bucket}/releases/v${version}
done
echo "Releases pushed to Google Storage"

Expand Down

0 comments on commit e314839

Please sign in to comment.