-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile.vagrant
More file actions
89 lines (64 loc) · 3.45 KB
/
Makefile.vagrant
File metadata and controls
89 lines (64 loc) · 3.45 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
#!/usr/bin/env make
override blackbox/:=*
ifeq ($(origin .FEATURES),undefined)
$(error `make` executable version `$(MAKE_VERSION)` is not supported. GNU Make 4.3 or above is required)
endif
ifeq ($(words $(MAKEFILE_LIST)),1)
$(error `Makefile` should be included, direct usage is not allowed)
endif
ifeq ($(shell which docker),)
$(error `docker` executable is required)
endif
override SHELL:=/usr/bin/env bash -e +o pipefail
ifeq ($(shell echo $$BASH),)
$(error current shell executable is not supported. GNU Bash 5.1 or above is required)
endif
ifeq ($(origin .FEATURES),undefined)
$(error `make` executable version "$(MAKE_VERSION)" is not supported. GNU Make 3.82 or above is required)
endif
override SHELL:=/bin/bash
ifneq ($(value SHELL),$(shell echo $$BASH))
$(error current shell executable is not supported. GNU Bash 4.3 or above is required)
endif
override blackbox/host/blackbox/dir:=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))
override blackbox/host/test/dir:=$(abspath $(dir $(firstword $(MAKEFILE_LIST))))
override blackbox/spawn/username:=ubuntu
override blackbox/spawn/test/dir:=/test
export BLACKBOX_HOST_TEST_DIR=$(blackbox/host/test/dir)
export BLACKBOX_FLAG__DEBUG_MODE=no
export VAGRANT_VAGRANTFILE=$(blackbox/host/blackbox/dir)/Vagrantfile
debug: ;@:
$(eval BLACKBOX_FLAG__DEBUG_MODE:=yes)
$(foreach variable,BLACKBOX_FLAG__DEBUG_MODE,$(info $(shell printf "\033[0;37m%s = %s\033[0m" "$(variable)" "$($(variable))")))
$(info $(shell printf "\033[0;37m%s\033[0m" \\))
$(foreach variable,$(filter-out BLACKBOX_FLAG__%,$(filter BLACKBOX_%,$(sort $(.VARIABLES)))),$(info $(shell printf "\033[0;37m%s = %s\033[0m" "$(variable)" "$($(variable))")))
$(if $(and $(filter-out $(words $(MAKECMDGOALS)),0),$(filter-out $(words $(MAKECMDGOALS)),1)),$(info $(shell printf "\033[0;37m%s\033[0m" --)))
all: install setup save check
$(MAKE) restore solve check
install:
vagrant up
setup:
vagrant ssh --command="sudo BLACKBOX_FLAG__DEBUG_MODE=$(BLACKBOX_FLAG__DEBUG_MODE) bash $(blackbox/spawn/test/dir)/setup.sh"
solve:
vagrant ssh --command="sudo -i -u $(blackbox/spawn/username) bash $(blackbox/spawn/test/dir)/solve.sh"
check:
vagrant ssh --command="sudo BLACKBOX_FLAG__DEBUG_MODE=$(BLACKBOX_FLAG__DEBUG_MODE) bash $(blackbox/spawn/test/dir)/check.sh" | tee >(awk '/Partial Credit/ { if (!reset) { reset = 1; next }; total_score += $$3; ok += ($$3 > 0); failed += ($$3 == 0) } END { printf("\nSuccess: %d\nFail: %d\nTotal: %d\n--\nTotal Credit: %d\n", ok, failed, ok + failed, total_score) }')
check\:evaluate:
vagrant ssh --command="sudo BLACKBOX_FLAG__DEBUG_MODE=no BLACKBOX_FLAG__STEP_PROVISION=no BLACKBOX_FLAG__STEP_BUILD=no BLACKBOX_FLAG__STEP_EVALUATE=yes bash $(blackbox/spawn/test/dir)/check.sh" | tee >(awk '/Partial Credit/ { if (!reset) { reset = 1; next }; total_score += $$3; ok += ($$3 > 0); failed += ($$3 == 0) } END { printf("\nSuccess: %d\nFail: %d\nTotal: %d\n--\nTotal Credit: %d\n", ok, failed, ok + failed, total_score) }')
shell:
vagrant ssh --command="sudo su - $(blackbox/spawn/username)"
shell\:spawn:
vagrant ssh --command="sudo docker exec -it -w /home/ubuntu/test blackbox-spawn bash"
save:
vagrant snapshot save current
restore:
vagrant snapshot restore current
prune:
vagrant snapshot delete current
hr:
cat <(xargs -r xdg-open 2>/dev/null < <(grep -o 'https://www.hackerrank.com.*' README.md))
gh:
cat <(xargs -r xdg-open 2>/dev/null < <(grep -o 'https://github.com.*' README.md))
uninstall:
vagrant destroy -f
rm -rf .vagrant