-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.mk
More file actions
157 lines (139 loc) · 5.75 KB
/
init.mk
File metadata and controls
157 lines (139 loc) · 5.75 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# WARNING: Please DO NOT edit this file! It is maintained in the Repository Template (https://github.com/nhs-england-tools/repository-template). Raise a PR instead.
include scripts/docker/docker.mk
include scripts/tests/test.mk
-include scripts/terraform/terraform.mk
# ==============================================================================
runner-act: # Run GitHub Actions locally - mandatory: workflow=[workflow file name], job=[job name] @Development
. ./scripts/docker/docker.lib.sh
act $(shell [[ "${VERBOSE}" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$$ ]] && echo --verbose) \
--container-architecture linux/amd64 \
--platform ubuntu-latest=$$(name="ghcr.io/nhs-england-tools/github-runner-image" docker-get-image-version-and-pull) \
--container-options "--privileged" \
--bind \
--pull=false \
--reuse \
--rm \
--defaultbranch main \
--workflows .github/workflows/${workflow}.yaml \
--job ${job}
version-create-effective-file: # Create effective version file - optional: dir=[path to the VERSION file to use, default is '.'], BUILD_DATETIME=[build date and time in the '%Y-%m-%dT%H:%M:%S%z' format generated by the CI/CD pipeline, default is current date and time] @Development
. ./scripts/docker/docker.lib.sh
version-create-effective-file
shellscript-lint-all: # Lint all shell scripts in this project, do not fail on error, just print the error messages @Quality
for file in $$(find . -type f -name "*.sh"); do
file=$${file} scripts/shellscript-linter.sh ||:
done
githooks-config: # Trigger Git hooks on commit that are defined in this repository @Configuration
make _install-dependency name="pre-commit"
pre-commit install \
--config scripts/config/pre-commit.yaml \
--install-hooks
githooks-run: # Run git hooks configured in this repository @Operations
pre-commit run \
--config scripts/config/pre-commit.yaml \
--all-files
_install-dependency: # Install asdf dependency - mandatory: name=[listed in the '.tool-versions' file]; optional: version=[if not listed]
echo ${name}
asdf plugin add ${name} ||:
asdf install ${name} $(or ${version},)
_install-dependencies: # Install all the dependencies listed in .tool-versions
for plugin in $$(grep ^[a-z] .tool-versions | sed 's/[[:space:]].*//'); do
$(MAKE) _install-dependency name=$${plugin}; \
done
clean:: # Remove all generated and temporary files (common) @Operations
rm -rf \
.scannerwork \
*report*.json \
*report*json.zip \
docs/diagrams/.*.bkp \
docs/diagrams/.*.dtmp \
.version
config:: # Configure development environment (common) @Configuration
make \
githooks-config
help: # Print help @Others
printf "\nUsage: \033[3m\033[93m[arg1=val1] [arg2=val2] \033[0m\033[0m\033[32mmake\033[0m\033[34m <command>\033[0m\n\n"
perl -e '$(HELP_SCRIPT)' $(MAKEFILE_LIST)
list-variables: # List all the variables available to make @Others
$(foreach v, $(sort $(.VARIABLES)),
$(if $(filter-out default automatic, $(origin $v)),
$(if $(and $(patsubst %_PASSWORD,,$v), $(patsubst %_PASS,,$v), $(patsubst %_KEY,,$v), $(patsubst %_SECRET,,$v)),
$(info $v=$($v) ($(value $v)) [$(flavor $v),$(origin $v)]),
$(info $v=****** (******) [$(flavor $v),$(origin $v)])
)
)
)
# ==============================================================================
.DEFAULT_GOAL := help
.EXPORT_ALL_VARIABLES:
.NOTPARALLEL:
.ONESHELL:
.PHONY: * # Please do not change this line! The alternative usage of it introduces unnecessary complexity and is considered an anti-pattern.
MAKEFLAGS := --no-print-director
SHELL := /bin/bash
ifeq (true, $(shell [[ "${VERBOSE}" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$$ ]] && echo true))
.SHELLFLAGS := -cex
else
.SHELLFLAGS := -ce
endif
# This script parses all the make target descriptions and renders the help output.
HELP_SCRIPT = \
\
use Text::Wrap; \
%help_info; \
my $$max_command_length = 0; \
my $$terminal_width = `tput cols` || 120; chomp($$terminal_width); \
\
while(<>){ \
next if /^_/; \
\
if (/^([\w-_]+)\s*:.*\#(.*?)(@(\w+))?\s*$$/) { \
my $$command = $$1; \
my $$description = $$2; \
$$description =~ s/@\w+//; \
my $$category_key = $$4 // 'Others'; \
(my $$category_name = $$category_key) =~ s/(?<=[a-z])([A-Z])/\ $$1/g; \
$$category_name = lc($$category_name); \
$$category_name =~ s/^(.)/\U$$1/; \
\
push @{$$help_info{$$category_name}}, [$$command, $$description]; \
$$max_command_length = (length($$command) > 37) ? 40 : $$max_command_length; \
} \
} \
\
my $$description_width = $$terminal_width - $$max_command_length - 4; \
$$Text::Wrap::columns = $$description_width; \
\
for my $$category (sort { $$a eq 'Others' ? 1 : $$b eq 'Others' ? -1 : $$a cmp $$b } keys %help_info) { \
print "\033[1m$$category\033[0m:\n\n"; \
for my $$item (sort { $$a->[0] cmp $$b->[0] } @{$$help_info{$$category}}) { \
my $$description = $$item->[1]; \
my @desc_lines = split("\n", wrap("", "", $$description)); \
my $$first_line_description = shift @desc_lines; \
\
$$first_line_description =~ s/(\w+)(\|\w+)?=/\033[3m\033[93m$$1$$2\033[0m=/g; \
\
my $$formatted_command = $$item->[0]; \
$$formatted_command = substr($$formatted_command, 0, 37) . "..." if length($$formatted_command) > 37; \
\
print sprintf(" \033[0m\033[34m%-$${max_command_length}s\033[0m%s %s\n", $$formatted_command, $$first_line_description); \
for my $$line (@desc_lines) { \
$$line =~ s/(\w+)(\|\w+)?=/\033[3m\033[93m$$1$$2\033[0m=/g; \
print sprintf(" %-$${max_command_length}s %s\n", " ", $$line); \
} \
print "\n"; \
} \
}
# ==============================================================================
${VERBOSE}.SILENT: \
_install-dependencies \
_install-dependency \
clean \
config \
githooks-config \
githooks-run \
help \
list-variables \
runner-act \
shellscript-lint-all \
version-create-effective-file \