Skip to content

Commit

Permalink
Add make targets to build and install snapshots for testing (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
aschepis authored Oct 7, 2024
1 parent cf2391c commit a58bf3e
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ signs:
- "${artifact}"
release:
disable: true
draft: true
replace_existing_draft: true
replace_existing_artifacts: true
extra_files:
- glob: 'terraform-registry-manifest.json'
name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json'
43 changes: 38 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ GO_GENERATE=PATH=$(TOOLS_BIN):$(PATH) go generate
GO_RELEASER_RELEASE_ARGS ?= --clean
GO_RELEASER_WORKING_DIR := /go/src/github.com/chronosphere/terraform-provider-chronosphere

SNAPSHOT_VERSION=$(shell ./scripts/next_version.sh || echo unknown)
SNAPSHOT_VERSION_NUMBER=$(subst v,,$(SNAPSHOT_VERSION))
LATEST_GIT_COMMIT=$(shell git rev-parse --short HEAD)
SNAPSHOT_BINARY=terraform-provider-chronosphere_${SNAPSHOT_VERSION}-SNAPSHOT-${LATEST_GIT_COMMIT}
LOCAL_SNAPSHOT_VERSION_DIR=${SNAPSHOT_VERSION_NUMBER}-SNAPSHOT-${LATEST_GIT_COMMIT}

INTERNAL_TOOLS := \
chronosphere/generateresources \
chronosphere/pagination/generatepagination \
Expand Down Expand Up @@ -117,6 +123,7 @@ test-ci: install-tools
version:
@echo "git: $(GIT_VERSION)"
@echo "dev: $(DEV_PROVIDER_VERSION)"
@echo "snapshot: $(shell ./scripts/next_version.sh || echo unknown)-SNAPSHOT"

# release publishes release artifacts
.PHONY: release
Expand All @@ -136,13 +143,39 @@ endif
GIT_VERSION=$(GIT_VERSION) \
./scripts/run_goreleaser.sh ${GO_RELEASER_RELEASE_ARGS}

.PHONY: release-snapshot
release-snapshot:
@echo Building binaries with goreleaser
.PHONY: snapshot
.IGNORE: snapshot # ignore build errors to make sure the git tag is removed.
snapshot:
@echo "Building snapshot version ${SNAPSHOT_VERSION}-SNAPSHOT with goreleaser"
git tag ${SNAPSHOT_VERSION}
# --snapshot mode allows building artifacts w/o release tag present and w/ publishing mode disabled
# useful when we want to test whether we can build binaries, but not publish yet.
make release SKIP_RELEASE_BRANCH_VALIDATION=true GO_RELEASER_RELEASE_ARGS="--snapshot --clean --skip=publish --skip=sign"

GO_BUILD_LDFLAGS="$(GO_BUILD_LDFLAGS)" \
INSTRUMENT_PACKAGE=$(INSTRUMENT_PACKAGE) \
GO_RELEASER_DOCKER_IMAGE=$(GO_RELEASER_DOCKER_IMAGE) \
GO_RELEASER_RELEASE_ARGS="$(GO_RELEASER_RELEASE_ARGS)" \
GO_RELEASER_WORKING_DIR=$(GO_RELEASER_WORKING_DIR) \
SSH_AUTH_SOCK=$(SSH_AUTH_SOCK) \
./scripts/run_goreleaser.sh --snapshot --skip=publish --skip=validate ${GO_RELEASER_RELEASE_ARGS}
# remove the tag after building the snapshot
git tag -d ${SNAPSHOT_VERSION}

.PHONY: install-snapshot
install-snapshot: snapshot verify-terraform-arch
@echo "Installing snapshot version: ${SNAPSHOT_VERSION}-SNAPSHOT-${LATEST_GIT_COMMIT}"
@echo "Installing snapshot binary: ${SNAPSHOT_BINARY}"
mkdir -p ~/.terraform.d/plugins/${OS_ARCH}
cp ./dist/terraform-provider-chronosphere_${OS_ARCH}/${SNAPSHOT_BINARY} ~/.terraform.d/plugins/${OS_ARCH}
mkdir -p ~/.terraform.d/plugins/local/chronosphereio/chronosphere/${LOCAL_SNAPSHOT_VERSION_DIR}/${OS_ARCH}/
cp ./dist/terraform-provider-chronosphere_${OS_ARCH}/${SNAPSHOT_BINARY} ~/.terraform.d/plugins/local/chronosphereio/chronosphere/${LOCAL_SNAPSHOT_VERSION_DIR}/${OS_ARCH}
@echo "Installed snapshot version: ${SNAPSHOT_VERSION}-SNAPSHOT-${LATEST_GIT_COMMIT}"
@echo ""
@echo "reference this in your terraform code like so:"
@echo ""
@echo "provider \"chronosphere\" {"
@echo " source = \"local/chronosphereio/chronosphere\""
@echo " version = \"${SNAPSHOT_VERSION_NUMBER}-SNAPSHOT-${LATEST_GIT_COMMIT}\""
@echo "}"
.PHONY: fmt
fmt:
go fmt $(shell go list ./...)
Expand Down
16 changes: 2 additions & 14 deletions scripts/increment_minor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,8 @@ if [ -n "$(git status --porcelain)" ]; then
exit 1
fi

VERSION=$(git describe --abbrev=0 --tags)

# Remove leading "v" from version tag (for details, see the "Substring Extraction" section of
# https://www.tldp.org/LDP/abs/html/string-manipulation.html).
VERSION="${VERSION:1}"

# Replace "." with a space so we can split the version into an array.
read -r -a VERSION_BITS <<<"${VERSION//./ }"

MAJOR_VERSION=${VERSION_BITS[0]}
MINOR_VERSION=${VERSION_BITS[1]}
MINOR_VERSION=$((MINOR_VERSION + 1))

NEW_VERSION="v${MAJOR_VERSION}.${MINOR_VERSION}.0"
NEXT_VERSION_SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/next_version.sh"
NEW_VERSION=$(bash $NEXT_VERSION_SCRIPT)

# Get the current hash and see if it already has a tag. We will only create the new tag if the
# current hash does not already have a tag.
Expand Down
17 changes: 2 additions & 15 deletions scripts/increment_patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,8 @@ if [ -n "$(git status --porcelain)" ]; then
exit 1
fi

VERSION=$(git describe --abbrev=0 --tags)

# Remove leading "v" from version tag (for details, see the "Substring Extraction" section of
# https://www.tldp.org/LDP/abs/html/string-manipulation.html).
VERSION="${VERSION:1}"

# Replace "." with a space so we can split the version into an array.
read -r -a VERSION_BITS <<<"${VERSION//./ }"

MAJOR_VERSION=${VERSION_BITS[0]}
MINOR_VERSION=${VERSION_BITS[1]}
PATCH_VERSION=${VERSION_BITS[2]}
PATCH_VERSION=$((PATCH_VERSION + 1))

NEW_VERSION="v${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}"
NEXT_VERSION_SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/next_version.sh"
NEW_VERSION=$(bash $NEXT_VERSION_SCRIPT --patch)

# Get the current hash and see if it already has a tag. We will only create the new tag if the
# current hash does not already have a tag.
Expand Down
39 changes: 39 additions & 0 deletions scripts/next_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -e

# This script is used to generate a new release tag that is 1 minor or patch version greater than the most
# recent release. Adapted from https://stackoverflow.com/questions/3760086/automatic-tagging-of-releases.
patch_version=false
for arg in "$@"; do
case $arg in
--patch | -p)
patch_version=true
shift # Remove --patch or -p from the arguments
;;
esac
done

VERSION=$(git describe --abbrev=0 --tags)

# Remove leading "v" from version tag (for details, see the "Substring Extraction" section of
# https://www.tldp.org/LDP/abs/html/string-manipulation.html).
VERSION="${VERSION:1}"

# Replace "." with a space so we can split the version into an array.
read -r -a VERSION_BITS <<<"${VERSION//./ }"

MAJOR_VERSION=${VERSION_BITS[0]}
MINOR_VERSION=${VERSION_BITS[1]}
PATCH_VERSION=${VERSION_BITS[2]:0}

# Increment the minor version if --patch is not set
if [ "$patch_version" = false ]; then
MINOR_VERSION=$((MINOR_VERSION + 1))
else
PATCH_VERSION=$((PATCH_VERSION + 1))
fi

NEW_VERSION="v${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}"

echo ${NEW_VERSION}
13 changes: 12 additions & 1 deletion scripts/run_goreleaser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
set -euo pipefail
[[ -z ${DEBUG:-} ]] || set -o xtrace

# allow the script to run goreleaser release or build
command="release"
for arg in "$@"; do
case $arg in
--build)
command="build"
shift # Remove --build from the arguments
;;
esac
done

OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && cd .. && pwd -P)"
GITCONFIG_VOLUME=${GIT_CONFIG:-"${HOME}/.gitconfig"}
Expand Down Expand Up @@ -48,4 +59,4 @@ if [[ "${BUILDKITE:-}" != "true" ]]; then
fi

# N.B. The GO_RELEASER_DOCKER_IMAGE is expected to be set by CI.
docker run "${DOCKER_OPTS[@]}" "${GO_RELEASER_DOCKER_IMAGE}" release "$@"
docker run "${DOCKER_OPTS[@]}" "${GO_RELEASER_DOCKER_IMAGE}" ${command} "$@"

0 comments on commit a58bf3e

Please sign in to comment.