forked from slsa-framework/slsa-github-generator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
87 lines (77 loc) · 3.03 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
SHELL := /bin/bash
OUTPUT_FORMAT = $(shell if [ "${GITHUB_ACTIONS}" == "true" ]; then echo "github"; else echo ""; fi)
.PHONY: help
help: ## Shows all targets and help from the Makefile (this message).
@echo "slsa-github-generator Makefile"
@echo "Usage: make [COMMAND]"
@echo ""
@grep --no-filename -E '^([/a-z.A-Z0-9_%-]+:.*?|)##' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = "(:.*?|)## ?"}; { \
if (length($$1) > 0) { \
printf " \033[36m%-20s\033[0m %s\n", $$1, $$2; \
} else { \
if (length($$2) > 0) { \
printf "%s\n", $$2; \
} \
} \
}'
## Testing
#####################################################################
.PHONY: unit-test
unit-test: ## Runs all unit tests.
# Run unit tests for the detect-workflow action.
make -C .github/actions/detect-workflow/ unit-test
go mod vendor
go test -mod=vendor -v ./...
## Linters
#####################################################################
.PHONY: lint
lint: golangci-lint shellcheck eslint yamllint ## Run all linters.
.PHONY: golangci-lint
golangci-lint: ## Runs the golangci-lint linter.
@set -e;\
extraargs=""; \
if [ "$(OUTPUT_FORMAT)" == "github" ]; then \
extraargs="--out-format github-actions"; \
fi; \
golangci-lint run -c .golangci.yml ./... $$extraargs
.PHONY: shellcheck
shellcheck: ## Runs the shellcheck linter.
@set -e;\
FILES=$$(find . -type f -not -iwholename '*/.git/*' -not -iwholename '*/vendor/*' -not -iwholename '*/node_modules/*' -exec bash -c 'file "$$1" | cut -d':' -f2 | grep --quiet shell' _ {} \; -print); \
if [ "$(OUTPUT_FORMAT)" == "github" ]; then \
echo -n $$FILES | xargs shellcheck -f json --external-sources | jq -c '.[]' | while IFS="" read -r p || [ -n "$$p" ]; do \
LEVEL=$$(echo "$$p" | jq -c '.level // empty' | tr -d '"'); \
FILE=$$(echo "$$p" | jq -c '.file // empty' | tr -d '"'); \
LINE=$$(echo "$$p" | jq -c '.line // empty' | tr -d '"'); \
ENDLINE=$$(echo "$$p" | jq -c '.endLine // empty' | tr -d '"'); \
COL=$$(echo "$$p" | jq -c '.column // empty' | tr -d '"'); \
ENDCOL=$$(echo "$$p" | jq -c '.endColumn // empty' | tr -d '"'); \
MESSAGE=$$(echo "$$p" | jq -c '.message // empty' | tr -d '"'); \
case $$LEVEL in \
"info") \
echo "::notice file=$${FILE},line=$${LINE},endLine=$${ENDLINE},col=$${COL},endColumn=$${ENDCOL}::$${MESSAGE}"; \
;; \
"warning") \
echo "::warning file=$${FILE},line=$${LINE},endLine=$${ENDLINE},col=$${COL},endColumn=$${ENDCOL}::$${MESSAGE}"; \
;; \
"error") \
echo "::error file=$${FILE},line=$${LINE},endLine=$${ENDLINE},col=$${COL},endColumn=$${ENDCOL}::$${MESSAGE}"; \
;; \
esac; \
done; \
else \
echo -n $$FILES | xargs shellcheck --external-sources; \
fi
.PHONY: eslint
eslint: ## Runs the eslint linter.
make -C .github/actions/compute-sha256 lint
make -C .github/actions/privacy-check lint
.PHONY: yamllint
yamllint: ## Runs the yamllint linter.
@set -e;\
extraargs=""; \
if [ "$(OUTPUT_FORMAT)" == "github" ]; then \
extraargs="-f github"; \
fi; \
yamllint -c .yamllint.yaml . $$extraargs