github.com/superfly/nomad@v0.10.5-fly/.circleci/Makefile (about) 1 # Set SHELL to 'strict mode' without using .SHELLFLAGS for max compatibility. 2 # See https://fieldnotes.tech/how-to-shell-for-compatible-makefiles/ 3 SHELL := /usr/bin/env bash -euo pipefail -c 4 5 CIRCLECI := circleci --skip-update-check 6 7 # Set up some documentation/help message variables. 8 # We do not attempt to install the CircleCI CLI from this Makefile. 9 CCI_INSTALL_LINK := https://circleci.com/docs/2.0/local-cli/\#installation 10 CCI_INSTALL_MSG := Please install CircleCI CLI. See $(CCI_INSTALL_LINK) 11 CCI_VERSION := $(shell $(CIRCLECI) version 2> /dev/null) 12 ifeq ($(CCI_VERSION),) 13 # Attempting to use the CLI fails with installation instructions. 14 CIRCLECI := echo '$(CCI_INSTALL_MSG)'; exit 1; \# 15 endif 16 17 SOURCE_DIR := config 18 SOURCE_YML := $(shell [ ! -d $(SOURCE_DIR) ] || find $(SOURCE_DIR) -name '*.yml') 19 CONFIG_SOURCE := Makefile $(SOURCE_YML) | $(SOURCE_DIR) 20 OUT := config.yml 21 TMP := .tmp/config-processed 22 CONFIG_PACKED := .tmp/config-packed 23 24 default: help 25 26 help: 27 @echo "Usage:" 28 @echo " make ci-config: recompile config.yml from $(SOURCE_DIR)/" 29 @echo " make ci-verify: verify that config.yml is a true mapping from $(SOURCE_DIR)/" 30 @echo 31 @echo "Diagnostics:" 32 @[ -z "$(CCI_VERSION)" ] || echo " circleci-cli version $(CCI_VERSION)" 33 @[ -n "$(CCI_VERSION)" ] || echo " $(CCI_INSTALL_MSG)" 34 35 $(SOURCE_DIR): 36 @echo No source directory $(SOURCE_DIR) found.; exit 1 37 38 # Make sure our .tmp dir exists. 39 $(shell [ -d .tmp ] || mkdir .tmp) 40 41 .PHONY: ci-config 42 ci-config: $(OUT) 43 44 .PHONY: ci-verify 45 ci-verify: config-up-to-date 46 @$(CIRCLECI) config validate $(OUT) 47 48 define GENERATED_FILE_HEADER 49 ### *** 50 ### WARNING: DO NOT manually EDIT or MERGE this file, it is generated by 'make ci-config'. 51 ### INSTEAD: Edit or merge the source in $(SOURCE_DIR)/ then run 'make ci-config'. 52 ### *** 53 endef 54 export GENERATED_FILE_HEADER 55 56 # GEN_CONFIG writes the config to a temporary file. If the whole process succeeds, 57 # it then moves that file to $@. This makes is an atomic operation, so if it fails 58 # make doesn't consider a half-baked file up to date. 59 define GEN_CONFIG 60 @$(CIRCLECI) config pack $(SOURCE_DIR) > $(CONFIG_PACKED) 61 @echo "$$GENERATED_FILE_HEADER" > $@.tmp || { rm -f $@; exit 1; } 62 @$(CIRCLECI) config process $(CONFIG_PACKED) >> $@.tmp || { rm -f $@.tmp; exit 1; } 63 @mv -f $@.tmp $@ 64 endef 65 66 $(OUT): $(CONFIG_SOURCE) 67 $(GEN_CONFIG) 68 @echo "$@ updated" 69 70 $(TMP): $(CONFIG_SOURCE) 71 $(GEN_CONFIG) 72 73 .PHONY: config-up-to-date 74 config-up-to-date: $(TMP) # Note this must not depend on $(OUT)! 75 @if diff config.yml $<; then \ 76 echo "Generated $(OUT) is up to date!"; \ 77 else \ 78 echo "Generated $(OUT) is out of date, run make $(CONFIG) to update."; \ 79 exit 1; \ 80 fi