Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
78 lines (69 loc) · 2.25 KB
/
Copy pathMakefile
File metadata and controls
78 lines (69 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
SHELL := /bin/bash
.DEFAULT_GOAL := help
HOST_UID := $(shell id -u)
HOST_GID := $(shell id -g)
.PHONY: help lint-fix ci test lint docs
help: ## Display help
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
test: ## Run unit tests
@set -eu; \
for manifest in $(wildcard actions/*/*/package.json); do \
npm --prefix "$${manifest%/package.json}" ci --ignore-scripts --no-audit --no-fund; \
npm --prefix "$${manifest%/package.json}" test; \
done
lint: ## Execute linting
$(call run_linter,)
lint-fix: ## Execute linting and fix
$(call run_linter, \
-e FIX_BIOME_FORMAT=true \
-e FIX_BIOME_LINT=true \
-e FIX_SPELL_CODESPELL=true \
-e FIX_MARKDOWN=true \
-e FIX_MARKDOWN_PRETTIER=true \
-e FIX_YAML_PRETTIER=true \
-e FIX_NATURAL_LANGUAGE=true \
-e FIX_SHELL_SHFMT=true \
)
ci: ## Execute local CI tasks
$(MAKE) lint-fix
$(MAKE) test
docs: ## Generate action and public workflow documentation
@set -eu; \
GITHUB_TOKEN="$$(gh auth token)"; \
export GITHUB_TOKEN; \
docker run --rm \
-v "$(CURDIR):/workspace" \
-u "$(HOST_UID):$(HOST_GID)" \
-e GITHUB_TOKEN \
ghcr.io/hoverkraft-tech/ci-dokumentor/cli:0.6.0 \
generate --source "actions/**/action.{yml,yaml}" ".github/workflows/!(__*).{yml,yaml}"
#############################
# Helpers
#############################
define run_linter
@set -eu; \
DEFAULT_WORKSPACE="$(CURDIR)"; \
LINTER_IMAGE="ci-github-iac-linter:latest"; \
VOLUME="$$DEFAULT_WORKSPACE:$$DEFAULT_WORKSPACE"; \
DEFAULT_BRANCH="$$(git -C "$$DEFAULT_WORKSPACE" rev-parse --abbrev-ref HEAD)"; \
docker build --platform=linux/amd64 \
--build-arg UID=$(HOST_UID) --build-arg GID=$(HOST_GID) \
--tag "$$LINTER_IMAGE" .; \
docker run --platform=linux/amd64 \
-v "$$VOLUME" --rm \
-e RUN_LOCAL=true \
-e DEFAULT_WORKSPACE="$$DEFAULT_WORKSPACE" \
-e DEFAULT_BRANCH="$$DEFAULT_BRANCH" \
-e USE_FIND_ALGORITHM=false \
-e FILTER_REGEX_INCLUDE="$(filter-out $@,$(MAKECMDGOALS))" \
-e 'FILTER_REGEX_EXCLUDE=/(\.cache|\.reports)/' \
$(1) \
"$$LINTER_IMAGE"
endef
#############################
# Positional filters for lint commands only
#############################
ifneq ($(filter lint lint-fix,$(firstword $(MAKECMDGOALS))),)
%:
@:
endif