From 152da2e08a88c5e02cb752a50d93ebeb2c41673d Mon Sep 17 00:00:00 2001 From: sndsgd Date: Sat, 9 Jan 2021 12:24:15 -0500 Subject: [PATCH] move version fetch into target --- Makefile | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index c61fb10..5535ddf 100644 --- a/Makefile +++ b/Makefile @@ -3,14 +3,7 @@ CWD := $(shell pwd) NODE_VERSION ?= 12.20.1-r0 LESS_VERSION ?= -VERSION_URL ?= https://www.npmjs.com/package/less -VERSION_PATTERN ?= '(?<="latest":")[^"]+(?=")' -ifndef (LESS_VERSION) - LESS_VERSION = $(shell curl -s $(VERSION_URL) | grep -Po $(VERSION_PATTERN)) -endif - IMAGE_NAME ?= sndsgd/less -IMAGE := $(IMAGE_NAME):$(LESS_VERSION) .PHONY: help help: @@ -18,10 +11,21 @@ help: | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%s\033[0m~%s\n", $$1, $$2}' \ | column -s "~" -t +VERSION_URL ?= https://www.npmjs.com/package/less +VERSION_PATTERN ?= '(?<="latest":")[^"]+(?=")' +.PHONY: ensure-version +ensure-version: +ifeq ($(LESS_VERSION),) + $(info fetching latest version...) + @$(eval LESS_VERSION = $(shell curl -s $(VERSION_URL) | grep -Po $(VERSION_PATTERN))) +endif + @$(eval IMAGE := $(IMAGE_NAME):$(LESS_VERSION)) + IMAGE_ARGS ?= --quiet .PHONY: image image: ## Build the docker image - @echo "building image for less v$(LESS_VERSION)..." +image: ensure-version + $(info building image for less v$(LESS_VERSION)...) @docker build \ $(IMAGE_ARGS) \ --build-arg NODE_VERSION=$(NODE_VERSION) \ @@ -34,14 +38,15 @@ image: ## Build the docker image test: ## Test the docker image test: image @make --no-print-directory execute-test \ + LESS_VERSION=$(LESS_VERSION) \ TEST_NAME=one TEST_ARGS ?= TEST_INPUT ?= source.less TEST_NAME ?= .PHONY: execute-test -execute-test: - @echo "testing '$(TEST_NAME)'..." +execute-test: ensure-version + $(info testing '$(TEST_NAME)'...) @docker run --rm -t \ -v $(CWD):$(CWD) \ -w $(CWD) $(IMAGE) \