Skip to content

Commit

Permalink
fix: unnecessary template repackaging (#449)
Browse files Browse the repository at this point in the history
Removes python caches on template test.  This appears to be the original
cause of unnecessary rebuilds.

Adds pkger.go as an explict entry in the CODE prerequisite var.  This
ensures pkged.go is generated if it doesn't exist, and removes the need
to explicitly enumerate it as a prerequisite to other targets.

Adds pkger.go to the clean target.  This allows a 'make clean && make' to
work as one might expect.  For example ensuring a rebuild if a template
files is removed.

The notable conceptual change here is that this does not induce a build of
pkged.go by explicitly enumarating it as a prerequisite (a difficult
thing to get right, and prone to errors in the future), but rather
directly enumerates ./templates as its prerequisite.

Additional minor modifications include:
- regenerated pkged.go such that this takes effect for main on merge
- adds an explicit target for the 'func' binary and aliases 'build'
- Makefile help text cleanup and consolidation
  • Loading branch information
lkingland committed Jul 30, 2021
1 parent 72aa925 commit 435d1ac
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 34 deletions.
60 changes: 28 additions & 32 deletions Makefile
Expand Up @@ -22,30 +22,33 @@ LDFLAGS := "-X main.date=$(DATE) -X main.vers=$(VERS) -X main.hash=$(HASH)"

# Templates
# Built into the binary are the contents of ./templates. This is done by
# running 'pkger' which generates pkged.go, containing a go-encoded version of
# the templates directory.
PKGER ?= pkger
# running 'pkger' which generates pkged.go containing templates encoded
# as Go objects and exposed at runtime as a filesystem.
PKGER ?= pkger

# Code is all go source files, used for build target freshness checks
CODE := $(shell find . -name '*.go')
# Target prerequisites for the two stages of encoding and building.
CODE := $(shell find . -name '*.go') pkged.go go.mod
TEMPLATES := $(shell find templates -name '*' -type f)

# Default Targets
all: build
# Run 'make help' for make target documentation.

# Print Help Text
# Help Text
# Headings: lines with `##$` comment prefix
# Targets: printed if their line includes a `##` comment
help:
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@echo 'Available targets are:'
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

###############
# Development #
##@ Development
###############

##@ Development
build: $(BIN) ## (default) Build binary for current OS

build: $(CODE) ## (default) Build binary for current OS
$(BIN): $(CODE)
env CGO_ENABLED=0 go build -ldflags $(LDFLAGS) ./cmd/$(BIN)

test: $(CODE) ## Run core unit tests
Expand All @@ -58,12 +61,7 @@ check: bin/golangci-lint ## Check code quality (lint)
bin/golangci-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./bin v1.40.1

clean: ## Remove generated artifacts such as binaries
rm -f $(BIN) $(BIN_WINDOWS) $(BIN_LINUX) $(BIN_DARWIN)
-rm -f coverage.out

clean-templates:
# Clearing caches in ./templates
pkged.go: $(TEMPLATES)
@rm -rf templates/node/events/node_modules
@rm -rf templates/node/http/node_modules
@rm -rf templates/python/events/__pycache__
Expand All @@ -72,18 +70,20 @@ clean-templates:
@rm -rf templates/typescript/http/node_modules
@rm -rf templates/rust/events/target
@rm -rf templates/rust/http/target
# Generating pkged.go using pkger
# to insstall pkger: 'go get github.com/markbates/pkger/cmd/pkger'
$(PKGER)

################
# Templates #
################
clean: ## Remove generated artifacts such as binaries
rm -f $(BIN) $(BIN_WINDOWS) $(BIN_LINUX) $(BIN_DARWIN)
rm -f coverage.out
rm -f pkged.go

##@ Builtin Language Packs

templates: test-templates pkged.go ## Run template unit tests and update pkged.go
#############
##@ Templates
#############

pkged.go: clean-templates
# Encoding ./templates as pkged.go (requires 'pkger': go get github.com/markbates/pkger/cmd/pkger)
$(PKGER)

test-templates: test-go test-node test-python test-quarkus test-rust test-typescript ## Run all template tests

Expand All @@ -96,8 +96,8 @@ test-node: ## Test Node templates
cd templates/node/http && npm ci && npm test && rm -rf node_modules

test-python: ## Test Python templates
cd templates/python/events && pip3 install -r requirements.txt && python3 test_func.py
cd templates/python/http && python3 test_func.py
cd templates/python/events && pip3 install -r requirements.txt && python3 test_func.py && rm -rf __pycache__
cd templates/python/http && python3 test_func.py && rm -rf __pycache__

test-quarkus: ## Test Quarkus templates
cd templates/quarkus/events && mvn test && mvn clean
Expand All @@ -111,12 +111,10 @@ test-typescript: ## Test Typescript templates
cd templates/typescript/events && npm ci && npm test && rm -rf node_modules build
cd templates/typescript/http && npm ci && npm test && rm -rf node_modules build


###################
# Release Testing #
##@ Extended Testing (cluster required)
###################

##@ Extended Testing (cluster required)

test-integration: ## Run integration tests using an available cluster.
go test -tags integration ./... -v
Expand All @@ -126,10 +124,8 @@ test-e2e: ## Run end-to-end tests using an available cluster.


######################
# Release Artifacts #
######################

##@ Release Artifacts
######################

cross-platform: darwin linux windows ## Build all distributable (cross-platform) binaries

Expand Down
1 change: 0 additions & 1 deletion client.go
Expand Up @@ -15,7 +15,6 @@ import (
const (
DefaultRegistry = "docker.io"
DefaultRuntime = "node"

// DefautlTemplate is the default Function signature / environmental context
// of the resultant function. All runtimes are expected to have at least
// one implementation of each supported funciton sinagure. Currently that
Expand Down
2 changes: 1 addition & 1 deletion pkged.go

Large diffs are not rendered by default.

0 comments on commit 435d1ac

Please sign in to comment.