From cf134e88f55cfde446129ab0b43273d2535192c0 Mon Sep 17 00:00:00 2001 From: Sam Salisbury Date: Mon, 9 Sep 2019 15:11:37 +0100 Subject: [PATCH] ci: 'atomically' update .circleci/config.yml (#7449) - Updates .circleci/Makefile to match https://github.com/samsalisbury/circleci-multi-file-config/commit/7cd733a000cb23956517aa3ddb736da372783b7f --- .circleci/Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.circleci/Makefile b/.circleci/Makefile index 4bf067a3df..15f29e52a4 100644 --- a/.circleci/Makefile +++ b/.circleci/Makefile @@ -60,10 +60,14 @@ define GENERATED_FILE_HEADER endef export GENERATED_FILE_HEADER +# GEN_CONFIG writes the config to a temporary file. If the whole process succeeds, +# it then moves that file to $@. This makes is an atomic operation, so if it fails +# make doesn't consider a half-baked file up to date. define GEN_CONFIG @$(CIRCLECI) config pack $(SOURCE_DIR) > $(CONFIG_PACKED) - @echo "$$GENERATED_FILE_HEADER" > $@ - @$(CIRCLECI) config process $(CONFIG_PACKED) >> $@ + @echo "$$GENERATED_FILE_HEADER" > $@.tmp || { rm -f $@; exit 1; } + @$(CIRCLECI) config process $(CONFIG_PACKED) >> $@.tmp || { rm -f $@.tmp; exit 1; } + @mv -f $@.tmp $@ endef $(OUT): $(CONFIG_SOURCE)