forked from techservicesillinois/splunk-soar-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
132 lines (109 loc) · 3.4 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
# DO NOT EDIT - All project-specific values belong in config.mk!
.PHONY: all build build-test clean lint static python-version
include config.mk
MODULE:=app
TEST_APP_NAME:=Test $(PROD_APP_NAME)
SOAR_PYTHON_VERSION:=$(shell PYTHONPATH=tests python -c 'from test_python_version import SOAR_PYTHON_VERSION as V; print(f"{V[0]}.{V[1]}.{V[2]}")')
PACKAGE:=app
SRCS_DIR:=src/$(MODULE)
TSCS_DIR:=tests
SOAR_SRCS:=$(shell find $(SRCS_DIR) -type f)
DIST_DIR:=dist/$(MODULE)
DIST_SRCS:=$(addprefix $(DIST_DIR)/, $(PACKAGE).json *.py)
SRCS:=$(shell find $(SRCS_DIR) -name '*.py')
TSCS:=$(shell find $(TSCS_DIR) -name '*.py')
BUILD_TIME:=$(shell date -u +%FT%X.%6NZ)
VENV_PYTHON:=venv/bin/python
VENV_REQS:=.requirements.venv
UNAME:=$(shell uname -s)
# BSD `sed` treats the `-i` option differently than Linux and others.
# Check for Mac OS X 'Darwin' and set our `-i` option accordingly.
ifeq ($(UNAME), Darwin)
# macOS (BSD sed)
SED_INPLACE := -i ''
else
# Linux and others (GNU sed)
SED_INPLACE := -i
endif
ifeq (tag, $(GITHUB_REF_TYPE))
TAG?=$(GITHUB_REF_NAME)
else
TAG?=$(shell printf "0.0.%d" 0x$(shell git rev-parse --short=6 HEAD))
endif
GITHUB_SHA?=$(shell git rev-parse HEAD)
all: build
build: export APP_ID=$(PROD_APP_ID)
build: export APP_NAME=$(PROD_APP_NAME)
build: dist $(PACKAGE).tar
build-test: export APP_ID=$(TEST_APP_ID)
build-test: export APP_NAME=$(TEST_APP_NAME)
build-test: dist $(PACKAGE).tar
dist: $(DIST_DIR) $(DIST_SRCS) .appjson version
$(DIST_DIR):
mkdir -p $@
$(DIST_SRCS): $(SOAR_SRCS)
cp -r $^ $(DIST_DIR)
$(PACKAGE).tar: $(DIST_SRCS)
tar cvf $@ -C dist $(MODULE)
version: .tag .commit .deployed
.tag: $(DIST_SRCS)
echo version $(TAG)
sed $(SED_INPLACE) "s/GITHUB_TAG/$(TAG)/" $^
touch $@
.commit: $(DIST_SRCS)
echo commit $(GITHUB_SHA)
sed $(SED_INPLACE) "s/GITHUB_SHA/$(GITHUB_SHA)/" $^
touch $@
.deployed: $(DIST_SRCS)
echo deployed $(BUILD_TIME)
sed $(SED_INPLACE) "s/BUILD_TIME/$(BUILD_TIME)/" $^
touch $@
.appjson: $(DIST_DIR)/$(PACKAGE).json
echo appid: $(APP_ID)
echo name: $(APP_NAME)
sed $(SED_INPLACE) "s/APP_ID/$(APP_ID)/" $^
sed $(SED_INPLACE) "s/APP_NAME/$(APP_NAME)/" $^
sed $(SED_INPLACE) "s/MODULE/$(MODULE)/" $^
touch $@
deploy: $(PACKAGE).tar venv
$(VENV_PYTHON) -m phtoolbox deploy --file $<
python-version:
@echo $(SOAR_PYTHON_VERSION)
.python-version: tests/test_python_version.py
pyenv install -s $(SOAR_PYTHON_VERSION)
pyenv local $(SOAR_PYTHON_VERSION)
venv: requirements-test.txt .python-version
rm -rf $@
python -m venv venv
$(VENV_PYTHON) -m pip install -r $<
requirements-test.txt: export PYTEST_SOAR_REPO=git+https://github.com/splunk/pytest-splunk-soar-connectors.git
requirements-test.txt: requirements-test.in
rm -rf $(VENV_REQS)
python -m venv $(VENV_REQS)
$(VENV_REQS)/bin/python -m pip install -r $^
$(VENV_REQS)/bin/python -m pip freeze -qqq > $@
# REMOVE once pytest-splunk-soar-connectors is on pypi
sed $(SED_INPLACE) "s;^pytest-splunk-soar-connectors==.*;$(PYTEST_SOAR_REPO);" $@
lint: venv .lint
.lint: $(SRCS) $(TSCS)
$(VENV_PYTHON) -m flake8 $?
touch $@
static: venv .static
.static: $(SRCS) $(TSCS)
echo "Code: $(SRCS)"
echo "Test: $(TSCS)"
$(VENV_PYTHON) -m mypy $^
touch $@
unit: venv
$(VENV_PYTHON) -m pytest
autopep8:
autopep8 --in-place $(SRCS)
test: lint static unit
clean:
rm -rf venv $(VENV_REQS)
rm -rf .lint .static
rm -rf .mypy_cache
rm -rf dist
rm -f $(PACKAGE).tar .tag
force-clean: clean
rm -f requirements-test.txt .python-version