Skip to content

Commit

Permalink
move version fetch into target
Browse files Browse the repository at this point in the history
  • Loading branch information
sndsgd committed Jan 9, 2021
1 parent 165c3bb commit 152da2e
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@ 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:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| 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) \
Expand All @@ -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) \
Expand Down

0 comments on commit 152da2e

Please sign in to comment.