-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
136 lines (115 loc) · 4.57 KB
/
Makefile
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
artifact_name := charges-data-api
version := unversioned
dependency_check_base_suppressions:=common_suppressions_spring_6.xml
# dependency_check_suppressions_repo_branch
# The branch of the dependency-check-suppressions repository to use
# as the source of the suppressions file.
# This should point to "main" branch when being used for release,
# but can point to a different branch for experimentation/development.
dependency_check_suppressions_repo_branch:=feature/suppressions-for-company-accounts-api
dependency_check_minimum_cvss := 4
dependency_check_assembly_analyzer_enabled := false
dependency_check_suppressions_repo_url:=git@github.com:companieshouse/dependency-check-suppressions.git
suppressions_file := target/suppressions.xml
### Create help from comments in Makefile
help:
@printf "%-20s %s\n" "Target" "Description"
@printf "%-20s %s\n" "------" "-----------"
@make -pqR : 2>/dev/null \
| awk -v RS= -F: '{if ($$1 !~ "^[#.]") {print $$1}}' \
| sort \
| egrep -v -e '^[^[:alnum:]]' -e '^$@$$' \
| xargs -I _ sh -c 'printf "%-20s " _; make _ -nB | (grep -i "^# Help:" || echo "") | tail -1 | sed "s/^# Help: //g"'
.PHONY: all
all:
@# Help: Calls methods required to build a locally runnable version, typically the build target
mvn clean install
.PHONY: clean
clean:
@# Help: Reset repo to pre-build state (i.e. a clean checkout state)
mvn clean
rm -f ./$(artifact_name).jar
rm -f ./$(artifact_name)-*.zip
rm -rf ./build-*
rm -rf ./build.log-*
.PHONY: build
build:
@# Help: Pull down any dependencies and compile code into an executable if required
$(info Setting version: $(version))
mvn versions:set -DnewVersion=$(version) -DgenerateBackupPoms=false
$(info Packing version: $(version))
mvn package -Dmaven.test.skip=true
cp ./target/$(artifact_name)-$(version).jar ./$(artifact_name).jar
.PHONY: test
test: test-integration test-unit
@# Help: Run all test-* targets (convenience method for developers)
.PHONY: test-unit
test-unit:
@# Help: Run unit tests
mvn test -Dskip.integration.tests=true
.PHONY: test-integration
test-integration:
@# Help: Run integration tests
mvn integration-test -Dskip.unit.tests=true
.PHONY: run-local
run-local:
@# Help: Run springboot app locally
mvn spring-boot:run
.PHONY: dependency-check
dependency-check:
@ if [ -d "$(DEPENDENCY_CHECK_SUPPRESSIONS_HOME)" ]; then \
suppressions_home="$${DEPENDENCY_CHECK_SUPPRESSIONS_HOME}"; \
fi; \
if [ ! -d "$${suppressions_home}" ]; then \
suppressions_home_target_dir="./target/dependency-check-suppressions"; \
if [ -d "$${suppressions_home_target_dir}" ]; then \
suppressions_home="$${suppressions_home_target_dir}"; \
else \
mkdir -p "./target"; \
git clone $(dependency_check_suppressions_repo_url) "$${suppressions_home_target_dir}" && \
suppressions_home="$${suppressions_home_target_dir}"; \
if [ -d "$${suppressions_home_target_dir}" ] && [ -n "$(dependency_check_suppressions_repo_branch)" ]; then \
cd "$${suppressions_home}"; \
git checkout $(dependency_check_suppressions_repo_branch); \
cd -; \
fi; \
fi; \
fi; \
suppressions_path="$${suppressions_home}/suppressions/$(dependency_check_base_suppressions)"; \
if [ -f "$${suppressions_path}" ]; then \
cp -av "$${suppressions_path}" $(suppressions_file); \
mvn org.owasp:dependency-check-maven:check -DfailBuildOnCVSS=$(dependency_check_minimum_cvss) -DassemblyAnalyzerEnabled=$(dependency_check_assembly_analyzer_enabled) -DsuppressionFiles=$(suppressions_file); \
else \
printf -- "\n ERROR Cannot find suppressions file at '%s'\n" "$${suppressions_path}" >&2; \
exit 1; \
fi
.PHONY: security-check
security-check: dependency-check
.PHONY: package
package:
@# Help: Create a single versioned deployable package (i.e. jar, zip, tar, etc.). May be dependent on the build target being run before package
ifndef version
$(error No version given. Aborting)
endif
mvn versions:set -DnewVersion=$(version) -DgenerateBackupPoms=false
$(info Packaging version: $(version))
@test -s ./$(artifact_name).jar || { echo "ERROR: Service JAR not found"; exit 1; }
$(eval tmpdir:=$(shell mktemp -d build-XXXXXXXXXX))
cp ./start.sh $(tmpdir)
cp ./$(artifact_name).jar $(tmpdir)/$(artifact_name).jar
cd $(tmpdir); zip -r ../$(artifact_name)-$(version).zip *
rm -rf $(tmpdir)
.PHONY: dist
dist: clean build package
.PHONY: sonar-pr-analysis
sonar-pr-analysis:
@# Help: Run sonar scan on a PR
mvn verify sonar:sonar -P sonar-pr-analysis
.PHONY: sonar
sonar:
@# Help: Run sonar scan
mvn verify sonar:sonar
.PHONY: deps
deps:
@# Help: Install dependencies
brew install kafka