2019-07-26 16:32:13 +00:00
|
|
|
# Set SHELL to 'strict mode' without using .SHELLFLAGS for max compatibility.
|
|
|
|
# See https://fieldnotes.tech/how-to-shell-for-compatible-makefiles/
|
2019-07-24 13:13:41 +00:00
|
|
|
SHELL := /usr/bin/env bash -euo pipefail -c
|
2019-06-26 14:14:23 +00:00
|
|
|
|
|
|
|
# CONFIG is the name of the make target someone
|
|
|
|
# would invoke to update the main config file (config.yml).
|
|
|
|
CONFIG ?= ci-config
|
|
|
|
# VERIFY is the name of the make target someone
|
|
|
|
# would invoke to verify the config file.
|
|
|
|
VERIFY ?= ci-verify
|
|
|
|
|
|
|
|
CIRCLECI := circleci --skip-update-check
|
2021-04-26 12:36:15 +00:00
|
|
|
ifeq ($(DEBUG_CIRCLECI_CLI),YES)
|
|
|
|
CIRCLECI += --debug
|
|
|
|
endif
|
|
|
|
|
|
|
|
# For config processing, always refer to circleci.com not self-hosted circleci,
|
|
|
|
# because self-hosted does not currently support the necessary API.
|
|
|
|
CIRCLECI_CLI_HOST := https://circleci.com
|
|
|
|
export CIRCLECI_CLI_HOST
|
2019-06-26 14:14:23 +00:00
|
|
|
|
2019-07-26 16:32:13 +00:00
|
|
|
# Set up some documentation/help message variables.
|
|
|
|
# We do not attempt to install the CircleCI CLI from this Makefile.
|
2019-06-26 14:14:23 +00:00
|
|
|
CCI_INSTALL_LINK := https://circleci.com/docs/2.0/local-cli/\#installation
|
|
|
|
CCI_INSTALL_MSG := Please install CircleCI CLI. See $(CCI_INSTALL_LINK)
|
|
|
|
CCI_VERSION := $(shell $(CIRCLECI) version 2> /dev/null)
|
|
|
|
ifeq ($(CCI_VERSION),)
|
|
|
|
# Attempting to use the CLI fails with installation instructions.
|
|
|
|
CIRCLECI := echo '$(CCI_INSTALL_MSG)'; exit 1; \#
|
|
|
|
endif
|
|
|
|
|
|
|
|
SOURCE_DIR := config
|
|
|
|
SOURCE_YML := $(shell [ ! -d $(SOURCE_DIR) ] || find $(SOURCE_DIR) -name '*.yml')
|
|
|
|
CONFIG_SOURCE := Makefile $(SOURCE_YML) | $(SOURCE_DIR)
|
|
|
|
OUT := config.yml
|
|
|
|
TMP := .tmp/config-processed
|
|
|
|
CONFIG_PACKED := .tmp/config-packed
|
2022-11-30 13:37:26 +00:00
|
|
|
GO_VERSION_FILE := ../.go-version
|
|
|
|
GO_VERSION := $(shell cat $(GO_VERSION_FILE))
|
2019-06-26 14:14:23 +00:00
|
|
|
|
|
|
|
default: help
|
|
|
|
|
|
|
|
help:
|
|
|
|
@echo "Usage:"
|
|
|
|
@echo " make $(CONFIG): recompile config.yml from $(SOURCE_DIR)/"
|
|
|
|
@echo " make $(VERIFY): verify that config.yml is a true mapping from $(SOURCE_DIR)/"
|
|
|
|
@echo
|
|
|
|
@echo "Diagnostics:"
|
|
|
|
@[ -z "$(CCI_VERSION)" ] || echo " circleci-cli version $(CCI_VERSION)"
|
|
|
|
@[ -n "$(CCI_VERSION)" ] || echo " $(CCI_INSTALL_MSG)"
|
|
|
|
|
|
|
|
$(SOURCE_DIR):
|
2019-07-26 16:32:13 +00:00
|
|
|
@echo No source directory $(SOURCE_DIR) found.; exit 1
|
2019-06-26 14:14:23 +00:00
|
|
|
|
|
|
|
# Make sure our .tmp dir exists.
|
2019-06-11 14:55:53 +00:00
|
|
|
$(shell [ -d .tmp ] || mkdir .tmp)
|
|
|
|
|
2019-06-26 14:14:23 +00:00
|
|
|
.PHONY: $(CONFIG)
|
2022-11-30 13:37:26 +00:00
|
|
|
$(CONFIG): $(OUT) $(GO_VERSION_FILE)
|
2019-06-26 14:14:23 +00:00
|
|
|
|
|
|
|
.PHONY: $(VERIFY)
|
|
|
|
$(VERIFY): config-up-to-date
|
|
|
|
@$(CIRCLECI) config validate $(OUT)
|
|
|
|
|
2019-07-26 16:32:13 +00:00
|
|
|
define GENERATED_FILE_HEADER
|
|
|
|
### ***
|
|
|
|
### WARNING: DO NOT manually EDIT or MERGE this file, it is generated by 'make $(CONFIG)'.
|
|
|
|
### INSTEAD: Edit or merge the source in $(SOURCE_DIR)/ then run 'make $(CONFIG)'.
|
|
|
|
### ***
|
|
|
|
endef
|
|
|
|
export GENERATED_FILE_HEADER
|
|
|
|
|
2019-09-09 14:11:37 +00:00
|
|
|
# GEN_CONFIG writes the config to a temporary file. If the whole process succeeds,
|
2019-11-21 14:46:10 +00:00
|
|
|
# it them moves that file to $@. This makes is an atomic operation, so if it fails
|
2019-09-09 14:11:37 +00:00
|
|
|
# make doesn't consider a half-baked file up to date.
|
2019-06-11 14:55:53 +00:00
|
|
|
define GEN_CONFIG
|
2022-11-30 13:37:26 +00:00
|
|
|
@yq -i ".references.environment.GO_IMAGE = \"docker.mirror.hashicorp.services/cimg/go:$(GO_VERSION)\"" $(SOURCE_DIR)/executors/\@executors.yml
|
|
|
|
|
2019-06-26 14:14:23 +00:00
|
|
|
@$(CIRCLECI) config pack $(SOURCE_DIR) > $(CONFIG_PACKED)
|
2019-09-09 14:11:37 +00:00
|
|
|
@echo "$$GENERATED_FILE_HEADER" > $@.tmp || { rm -f $@; exit 1; }
|
|
|
|
@$(CIRCLECI) config process $(CONFIG_PACKED) >> $@.tmp || { rm -f $@.tmp; exit 1; }
|
|
|
|
@mv -f $@.tmp $@
|
2019-06-11 14:55:53 +00:00
|
|
|
endef
|
|
|
|
|
2022-12-14 21:35:03 +00:00
|
|
|
.PHONY: $(OUT)
|
2019-06-26 14:14:23 +00:00
|
|
|
$(OUT): $(CONFIG_SOURCE)
|
2019-06-11 14:55:53 +00:00
|
|
|
$(GEN_CONFIG)
|
|
|
|
@echo "$@ updated"
|
|
|
|
|
2019-06-26 14:14:23 +00:00
|
|
|
$(TMP): $(CONFIG_SOURCE)
|
2019-06-11 14:55:53 +00:00
|
|
|
$(GEN_CONFIG)
|
|
|
|
|
|
|
|
.PHONY: config-up-to-date
|
|
|
|
config-up-to-date: $(TMP) # Note this must not depend on $(OUT)!
|
2019-11-21 14:46:10 +00:00
|
|
|
@if diff -w $(OUT) $<; then \
|
2019-06-11 14:55:53 +00:00
|
|
|
echo "Generated $(OUT) is up to date!"; \
|
|
|
|
else \
|
2019-06-26 14:14:23 +00:00
|
|
|
echo "Generated $(OUT) is out of date, run make $(CONFIG) to update."; \
|
2019-06-11 14:55:53 +00:00
|
|
|
exit 1; \
|
|
|
|
fi
|