diff options
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 53 |
1 files changed, 43 insertions, 10 deletions
| @@ -1,15 +1,48 @@ | |||
| 1 | .PHONY: clean deps tests | 1 | .PHONY: clean rebuild update-deps tests help docker docker-tests docker-publish |
| 2 | 2 | ||
| 3 | all: php-malware-finder/phpmalwarefinder | 3 | NAME := php-malware-finder |
| 4 | TAG_COMMIT := $(shell git rev-list --abbrev-commit --all --max-count=1) | ||
| 5 | VERSION := $(shell git describe --abbrev=0 --tags --exact-match $(TAG_COMMIT) 2>/dev/null || true) | ||
| 6 | IMAGE_VERSION := $(VERSION) | ||
| 7 | DATE := $(shell git log -1 --format=%cd --date=format:"%Y%m%d%H%M") | ||
| 8 | ifeq ($(VERSION),) | ||
| 9 | VERSION := $(DATE) | ||
| 10 | IMAGE_VERSION := latest | ||
| 11 | endif | ||
| 12 | LDFLAGS := "-X main.version=$(VERSION)" | ||
| 13 | GO_FLAGS := -o $(NAME) -ldflags $(LDFLAGS) | ||
| 14 | IMAGE_REGISTRY := ghcr.io | ||
| 15 | IMAGE_REGISTRY_USER := jvoisin | ||
| 16 | IMAGE_NAME := $(IMAGE_REGISTRY)/$(IMAGE_REGISTRY_USER)/$(NAME) | ||
| 4 | 17 | ||
| 5 | php-malware-finder/phpmalwarefinder: | 18 | all: php-malware-finder |
| 6 | go build -o php-malware-finder/phpmalwarefinder php-malware-finder/phpmalwarefinder.go | ||
| 7 | 19 | ||
| 8 | clean: | 20 | php-malware-finder: ## Build application |
| 9 | rm -f php-malware-finder/phpmalwarefinder | 21 | @go build $(GO_FLAGS) . |
| 10 | 22 | ||
| 11 | deps: | 23 | clean: ## Delete build artifacts |
| 12 | go mod tidy -v | 24 | @rm -f $(NAME) |
| 13 | 25 | ||
| 14 | tests: php-malware-finder/phpmalwarefinder | 26 | rebuild: clean all ## Delete build artifacts and rebuild |
| 15 | @cd ./php-malware-finder && bash ./tests.sh | 27 | |
| 28 | update-deps: ## Update dependencies | ||
| 29 | @go get -u . | ||
| 30 | @go mod tidy -v | ||
| 31 | |||
| 32 | tests: php-malware-finder ## Run test suite | ||
| 33 | @bash ./tests.sh | ||
| 34 | |||
| 35 | docker: ## Build docker image | ||
| 36 | docker pull $(IMAGE_NAME):latest || true | ||
| 37 | docker build --pull -t $(IMAGE_NAME):latest . | ||
| 38 | docker tag $(IMAGE_NAME):latest $(IMAGE_NAME):$(IMAGE_VERSION) | ||
| 39 | |||
| 40 | docker-tests: ## Run docker image against the samples folder | ||
| 41 | @docker run --rm -v $(shell pwd)/data/samples:/data $(IMAGE_NAME):latest | ||
| 42 | |||
| 43 | docker-publish: ## Push docker image to the container registry | ||
| 44 | @docker push $(IMAGE_NAME):latest | ||
| 45 | @(test "$(IMAGE_VERSION)" != "latest" && docker push $(IMAGE_NAME):$(IMAGE_VERSION)) || true | ||
| 46 | |||
| 47 | help: ## Show this help | ||
| 48 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' | ||
