-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
111 lines (79 loc) · 3.27 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
AWS_ACCOUNT_NAME ?= michael
AWS_DEFAULT_REGION ?= us-east-2
PYTHON ?= python3
BEHAVE ?= behave
KEYFILE ?=.anslk_random_testkey
export AWS_DEFAULT_REGION
# these variables cannot be immediate since running the prepare target
# may change the values.
ifneq ($(wildcard $(KEYFILE)),)
RANDOM_KEY = $(shell cat $(KEYFILE))
endif
S3_TEST_BUCKET = test-backup-$(RANDOM_KEY)
export RANDOM_KEY
export S3_TEST_BUCKET
LIBFILES := $(shell find backup_cloud -name '*.py')
# we want to automate all the setup but we don't want to do it by surprise so we default
# to aborting with a message to correct things
abort:
@echo "***************************************************************************"
@echo "* please run 'make all' to install library and programs locally then test *"
@echo "***************************************************************************"
@echo
exit 2
all: develop prepare lint build test
test: develop build pytest behave doctest
behave: behave-mocked behave-aws
behave-mocked: develop checkvars
$(BEHAVE) --stage=mocked --tags=-future --tags=mocked
behave-aws: develop checkvars
$(BEHAVE) --stage=aws --tags=-future --tags=-mocked
# develop is needed to install scripts that are called during testing
develop: .develop.makestamp
.develop.makestamp: setup.py backup_cloud/shell_start.py $(LIBFILES)
$(PYTHON) setup.py install --force
$(PYTHON) setup.py develop
touch $@
checkvars:
if [ '!' -f $${KEYFILE} ] ; then \
echo "file: $(KEYFILE) missing - run make prepare first" ; exit 5 ; fi
if [ -z $${RANDOM_KEY} ] ; then \
echo 'no RANDOM_KEY found - N.B. be sure you are using a recent gmake!!! run *make prepare* to build test environment.' ; exit 5 ; fi
pytest:
$(PYTHON) -m pytest -vv tests
doctest:
$(PYTHON) -m doctest -v README.md
pip_install:
$(PYTHON) -m pip install -r requirements.txt
prepare: encrypted_build_files.tjz.enc
ENC_DIR=encrypted_build_files
ENC_FILENAMES=aws_credentials.demo.env aws_credentials.env aws_credentials_travis.yml deploy_key
ENC_FILES := $(addprefix $(ENC_DIR)/,$(ENC_FILENAMES))
encrypted_build_files.tjz: .prepare-account.makestamp .prepare-test.makestamp $(ENC_FILES)
tar cvvjf $@ -C $(ENC_DIR) $(ENC_FILENAMES)
encrypted_build_files.tjz.enc: encrypted_build_files.tjz
travis encrypt-file --force --no-interactive --org $<
prepare-account: .prepare-account.makestamp
.prepare-account.makestamp: prepare-account.yml $(wildcard aws_credentials_*_iam_admin.yml) $(wildcard roles/test_account/*/*.yml)
ansible-playbook -vvv prepare-account.yml --extra-vars=aws_account_name=$(AWS_ACCOUNT_NAME)
touch $@
prep_test: .prepare-test.makestamp
.prepare-test.makestamp:
ansible-playbook -vvv prepare-test-enc-backup.yml --extra-vars=aws_account_name=$(AWS_ACCOUNT_NAME)
touch $@
wip: wip-mocked wip-aws
wip-aws: develop build
$(BEHAVE) --stage=aws --tags=~mocked --wip
wip-mocked: develop build
$(BEHAVE) --stage=mocked --tags=mocked --wip
build:
lint:
pre-commit install --install-hooks
pre-commit run -a
testfix:
find . -name '*.py' | xargs black --line-length=100 --diff
clean:
rm *.makestamp
fix:
find . -name '*.py' | xargs black --line-length=100
.PHONY: all develop test behave behave-aws behave-mocked checkvars pytest doctest pip_install prepare prep_test prepare_account wip wip-aws wip-mocked build lint testfix fix clean