mirror of
https://github.com/hashicorp/packer.git
synced 2026-04-15 22:20:33 -04:00
This change introduces the new actions-set-product-version, a tiny, but mighty, GitHub action that acts as a bridge between the product repo and our new CRT feature: automated version bumping.
tl;dr automated version bumping has a new command (bob update version) in the bob CLI that automatically bumps the version to a new patch. This automation has been introduced to crt-workflows-common as a new workflow (with the new bob command) and handles version bumping at the end of the release pipeline (after being released to production); for example, 1.0.0→1.0.1 and 1.0.0-dev→1.0.0. Bumping the minor version (ie 1.0.x→1.1.0) is only supported manually via bob update version -bump minor, but not supported in CRT (this work is upcoming). This is made possible by adding the new event “bump-version” in the ci.hcl file in this PR.
What this small action does:
Allows for the static version string from the version/VERSION file to be read by the new CRT workflow and automagically be bumped to the next version (whether it be a minor, or patch, or major version bump).
Outputs an error if there’s no VERSION file in the version dir
Outputs an error if there’s no version string in the VERSION file
Is able to parse product_version if it is 1.3.0-alpha1 as 1.3.0 (example: when product_version = 1.3.0-alpha1, base_version = 1.3.0)
Is able to parse prerelease product versions such as alpha1 (example prerelease_product_version = alpha1) in the statement above.
198 lines
7.4 KiB
Makefile
198 lines
7.4 KiB
Makefile
TEST?=$(shell go list ./...)
|
|
COUNT?=1
|
|
VET?=$(shell go list ./...)
|
|
|
|
ACC_TEST_BUILDERS?=all
|
|
ACC_TEST_PROVISIONERS?=all
|
|
# Get the current full sha from git
|
|
GITSHA:=$(shell git rev-parse HEAD)
|
|
# Get the current local branch name from git (if we can, this may be blank)
|
|
GITBRANCH:=$(shell git symbolic-ref --short HEAD 2>/dev/null)
|
|
GOOS=$(shell go env GOOS)
|
|
GOARCH=$(shell go env GOARCH)
|
|
GOPATH=$(shell go env GOPATH)
|
|
|
|
EXECUTABLE_FILES=$(shell find . -type f -executable | egrep -v '^\./(website/[vendor|tmp]|vendor/|\.git|bin/|scripts/|pkg/)' | egrep -v '.*(\.sh|\.bats|\.git)' | egrep -v './provisioner/(ansible|inspec)/test-fixtures/exit1')
|
|
|
|
# Get the git commit
|
|
GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true)
|
|
GIT_COMMIT=$(shell git rev-parse --short HEAD)
|
|
GIT_IMPORT=github.com/hashicorp/packer/version
|
|
UNAME_S := $(shell uname -s)
|
|
LDFLAGS=-s -w
|
|
GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) $(LDFLAGS)
|
|
|
|
export GOLDFLAGS
|
|
|
|
.PHONY: bin checkversion ci ci-lint default install-build-deps install-gen-deps fmt fmt-docs fmt-examples generate install-lint-deps lint \
|
|
releasebin test testacc testrace version
|
|
|
|
default: install-build-deps install-gen-deps generate dev
|
|
|
|
ci: testrace ## Test in continuous integration
|
|
|
|
release: install-build-deps test releasebin package ## Build a release build
|
|
|
|
bin: install-build-deps ## Build debug/test build
|
|
@echo "WARN: 'make bin' is for debug / test builds only. Use 'make release' for release builds."
|
|
@GO111MODULE=auto sh -c "$(CURDIR)/scripts/build.sh"
|
|
|
|
releasebin: install-build-deps
|
|
@grep 'const VersionPrerelease = "dev"' version/version.go > /dev/null ; if [ $$? -eq 0 ]; then \
|
|
echo "ERROR: You must remove prerelease tags from version/version.go prior to release."; \
|
|
exit 1; \
|
|
fi
|
|
@GO111MODULE=auto sh -c "$(CURDIR)/scripts/build.sh"
|
|
|
|
package:
|
|
$(if $(VERSION),,@echo 'VERSION= needed to release; Use make package skip compilation'; exit 1)
|
|
@sh -c "$(CURDIR)/scripts/dist.sh $(VERSION)"
|
|
|
|
install-build-deps: ## Install dependencies for bin build
|
|
@go install github.com/mitchellh/gox@v1.0.1
|
|
|
|
install-gen-deps: ## Install dependencies for code generation
|
|
@GO111MODULE=on go install github.com/alvaroloes/enumer@master
|
|
@go install github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc@latest
|
|
|
|
install-lint-deps: ## Install linter dependencies
|
|
@echo "==> Updating linter dependencies..."
|
|
@curl -sSfL -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.46.0
|
|
|
|
dev: ## Build and install a development build
|
|
@grep 'const VersionPrerelease = ""' version/version.go > /dev/null ; if [ $$? -eq 0 ]; then \
|
|
echo "ERROR: You must add prerelease tags to version/version.go prior to making a dev build."; \
|
|
exit 1; \
|
|
fi
|
|
@mkdir -p pkg/$(GOOS)_$(GOARCH)
|
|
@mkdir -p bin
|
|
@go install -ldflags '$(GOLDFLAGS)'
|
|
@cp $(GOPATH)/bin/packer bin/packer
|
|
@cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH)
|
|
|
|
# Docker build variables and targets
|
|
REGISTRY_NAME?=docker.io/hashicorp
|
|
IMAGE_NAME=packer
|
|
VERSION?=1.7.10
|
|
IMAGE_TAG=$(REGISTRY_NAME)/$(IMAGE_NAME):$(VERSION)
|
|
IMAGE_TAG_DEV=$(REGISTRY_NAME)/$(IMAGE_NAME):latest-$(shell git rev-parse --short HEAD)
|
|
|
|
docker: docker-official
|
|
docker-light: docker-official
|
|
|
|
# Builds from the releases.hashicorp.com official binary
|
|
docker-official:
|
|
docker build \
|
|
--tag $(IMAGE_TAG) \
|
|
--tag hashicorp/packer:latest \
|
|
--target=official \
|
|
--build-arg VERSION=$(VERSION) \
|
|
.
|
|
|
|
# Builds multiarch from the releases.hashicorp.com official binary
|
|
docker-multiarch-official:
|
|
docker buildx build \
|
|
--tag $(IMAGE_TAG) \
|
|
--tag hashicorp/packer:latest \
|
|
--target=official \
|
|
--build-arg VERSION=$(VERSION) \
|
|
--platform linux/amd64,linux/arm64 \
|
|
.
|
|
|
|
# Builds from the locally generated binary in ./bin/
|
|
# To generate the local binary, run `make dev`
|
|
docker-dev: export GOOS=linux
|
|
docker-dev: export GOARCH=amd64
|
|
docker-dev: dev
|
|
@docker build \
|
|
--tag $(IMAGE_TAG_DEV) \
|
|
--target=dev \
|
|
.
|
|
|
|
lint: install-lint-deps ## Lint Go code
|
|
@if [ ! -z $(PKG_NAME) ]; then \
|
|
echo "golangci-lint run ./$(PKG_NAME)/..."; \
|
|
golangci-lint run ./$(PKG_NAME)/...; \
|
|
else \
|
|
echo "golangci-lint run ./..."; \
|
|
golangci-lint run ./...; \
|
|
fi
|
|
|
|
ci-lint: install-lint-deps ## On ci only lint newly added Go source files
|
|
@echo "==> Running linter on newly added Go source files..."
|
|
GO111MODULE=on golangci-lint run --new-from-rev=$(shell git merge-base origin/main HEAD) ./...
|
|
|
|
fmt: ## Format Go code
|
|
@go fmt ./...
|
|
|
|
fmt-check: fmt ## Check go code formatting
|
|
@echo "==> Checking that code complies with go fmt requirements..."
|
|
@git diff --exit-code; if [ $$? -eq 1 ]; then \
|
|
echo "Found files that are not fmt'ed."; \
|
|
echo "You can use the command: \`make fmt\` to reformat code."; \
|
|
exit 1; \
|
|
fi
|
|
|
|
mode-check: ## Check that only certain files are executable
|
|
@echo "==> Checking that only certain files are executable..."
|
|
@if [ ! -z "$(EXECUTABLE_FILES)" ]; then \
|
|
echo "These files should not be executable or they must be white listed in the Makefile:"; \
|
|
echo "$(EXECUTABLE_FILES)" | xargs -n1; \
|
|
exit 1; \
|
|
else \
|
|
echo "Check passed."; \
|
|
fi
|
|
fmt-docs:
|
|
@find ./website/pages/docs -name "*.md" -exec pandoc --wrap auto --columns 79 --atx-headers -s -f "markdown_github+yaml_metadata_block" -t "markdown_github+yaml_metadata_block" {} -o {} \;
|
|
|
|
# Install js-beautify with npm install -g js-beautify
|
|
fmt-examples:
|
|
find examples -name *.json | xargs js-beautify -r -s 2 -n -eol "\n"
|
|
|
|
# generate runs `go generate` to build the dynamically generated
|
|
# source files.
|
|
generate: install-gen-deps ## Generate dynamically generated code
|
|
@echo "==> removing autogenerated markdown..." # but don't remove partials generated in the SDK and copied over.
|
|
@find website/pages -path website/pages/partials/packer-plugin-sdk -prune -o -type f | xargs grep -l '^<!-- Code generated' | xargs rm -f
|
|
@echo "==> removing autogenerated code..."
|
|
@find post-processor helper builder provisioner -type f | xargs grep -l '^// Code generated' | xargs rm -f
|
|
PROJECT_ROOT="$(shell pwd)" go generate $(shell go list ./... | grep -v packer-plugin-sdk)
|
|
|
|
generate-check: generate ## Check go code generation is on par
|
|
@echo "==> Checking that auto-generated code is not changed..."
|
|
@git diff --exit-code; if [ $$? -eq 1 ]; then \
|
|
echo "Found diffs in go generated code."; \
|
|
echo "You can use the command: \`make generate\` to reformat code."; \
|
|
exit 1; \
|
|
fi
|
|
|
|
test: mode-check vet ## Run unit tests
|
|
@go test -count $(COUNT) $(TEST) $(TESTARGS) -timeout=3m
|
|
|
|
# acctest runs provisioners acceptance tests
|
|
provisioners-acctest: #install-build-deps generate
|
|
ACC_TEST_BUILDERS=$(ACC_TEST_BUILDERS) go test $(TEST) $(TESTARGS) -timeout=1h
|
|
|
|
# testacc runs acceptance tests
|
|
testacc: # install-build-deps generate ## Run acceptance tests
|
|
@echo "WARN: Acceptance tests will take a long time to run and may cost money. Ctrl-C if you want to cancel."
|
|
PACKER_ACC=1 go test -count $(COUNT) -v $(TEST) $(TESTARGS) -timeout=120m
|
|
|
|
testrace: mode-check vet ## Test with race detection enabled
|
|
@go test -count $(COUNT) -race $(TEST) $(TESTARGS) -timeout=3m -p=8
|
|
|
|
# Runs code coverage and open a html page with report
|
|
cover:
|
|
go test -count $(COUNT) $(TEST) $(TESTARGS) -timeout=3m -coverprofile=coverage.out
|
|
go tool cover -html=coverage.out
|
|
rm coverage.out
|
|
|
|
vet: ## Vet Go code
|
|
@go vet $(VET) ; if [ $$? -eq 1 ]; then \
|
|
echo "ERROR: Vet found problems in the code."; \
|
|
exit 1; \
|
|
fi
|
|
|
|
help:
|
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
|
|