-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.mk
162 lines (139 loc) · 3.82 KB
/
global.mk
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Aliases for executables
BASENAME ?= basename
BATS ?= bats
CODE ?= code
CP ?= cp
DOTNET ?= dotnet
EXERCISM ?= exercism
GH ?= gh
GIT ?= git
MKDIR ?= mkdir
RM ?= rm
SED ?= sed
# Exercism variables
ifeq (,$(IN))
EXERCISE = $(shell $(BASENAME) $(CURDIR))
else
EXERCISE = $(shell echo $(IN) | $(SED) 's/.*--exercise=\([^ ]*\)/\1/')
endif
EXERCISE_SNAKE_CASE = $(shell echo $(EXERCISE) | $(SED) 's/-/_/g')
EXERCISE_PASCAL_CASE = $(shell echo $(EXERCISE) | $(SED) 's/\(^\|-\)\([a-z]\)/\U\2/g')
SUBMISSIONS =
TRACK =
# Debug the variables
.PHONY: debug
debug::
@echo "EXERCISE: $(EXERCISE)"
@echo "EXERCISE_SNAKE_CASE: $(EXERCISE_SNAKE_CASE)"
@echo "EXERCISE_PASCAL_CASE: $(EXERCISE_PASCAL_CASE)"
@echo "IN: $(IN)"
@echo "SUBMISSIONS: $(SUBMISSIONS)"
@echo "TRACK: $(TRACK)"
# Create the exercise
.PHONY: create
create: guard-EXERCISE guard-TRACK
@echo "Creating exercise..."
$(EXERCISM) download --exercise=$(EXERCISE) --track=$(TRACK)
# Boot track
.PHONY: boot-track
boot-track: guard-TRACK
@echo "Booting track..."
$(GIT) checkout -b feat/setup-$(TRACK)
$(MKDIR) -p $(TRACK)
$(CP) ./child.mk $(TRACK)/Makefile
$(SED) -i 's/@@TRACK@@/$(TRACK)/g' $(TRACK)/Makefile
$(GIT) add $(TRACK)/Makefile
$(GIT) commit -m "Add $(TRACK) Makefile"
# Create the feature branch
.PHONY: boot-feature-branch
boot-feature-branch:: guard-TRACK guard-EXERCISE create
@echo "Creating feature branch..."
$(GIT) checkout -b feat/$(TRACK)/$(EXERCISE)
$(GIT) add $(EXERCISE)
$(GIT) commit -m "Create $(TRACK):$(EXERCISE) exercise"
# Create exercise Makefile
.PHONY: create-makefile
create-makefile: guard-EXERCISE
@echo "Creating Makefile..."
echo "-include ../../global.mk" >> $(EXERCISE)/Makefile
echo "-include ../Makefile" >> $(EXERCISE)/Makefile
# Create exercise Makefile
.PHONY: boot-makefile
boot-makefile: guard-EXERCISE boot-feature-branch create-makefile
@echo "Adding Makefile..."
$(GIT) add $(EXERCISE)/Makefile
$(GIT) commit -m "Add Makefile"
# Create exercise tests
.PHONY: boot-tests
boot-tests::
@echo "Creating tests..."
# Launch VS Code
.PHONY: boot-vscode
boot-vscode::
@echo "Launching VS Code..."
for submission in $(SUBMISSIONS); do \
$(CODE) --reuse-window $(EXERCISE)/$$submission & \
done
# Final boot step for random things
.PHONY: boot-final
boot-final::
@echo "Finalizing boot..."
# Full boot target
.PHONY: boot
boot:: create boot-feature-branch boot-makefile boot-tests boot-vscode boot-final
@echo "Boot complete."
# Convenience target for bats tests
.PHONY: test-bats
test-bats:
BATS_RUN_SKIPPED=true $(BATS) *.bats
# Convenience target for dotnet tests
.PHONY: test-dotnet
test-dotnet:
$(DOTNET) test
# Convenience target for cleaning dotnet
.PHONY: clean-dotnet
clean-dotnet:
$(RM) -rf bin/ obj/
# Run the tests
.PHONY: test
test::
@echo "Running tests..."
# Get code coverage
.PHONY: coverage
coverage::
@echo "Getting code coverage..."
# Remove any built artifacts
.PHONY: clean
clean::
@echo "Cleaning up..."
# Ensure no uncommitted changes
.PHONY: ensure-committed
ensure-committed::
$(GIT) diff-index --quiet HEAD || (echo "Uncommitted changes"; exit 1)
# Submit the solution
.PHONY: submit
submit:: guard-SUBMISSIONS ensure-committed
@echo "Submitting solution..."
$(EXERCISM) submit $(SUBMISSIONS)
# Finish the branch
.PHONY: finish
finish:: guard-TRACK guard-EXERCISE coverage submit clean
@echo "Finishing up..."
$(GIT) push -u origin feat/$(TRACK)/$(EXERCISE)
$(GH) pr create --fill
$(GH) pr merge --merge --delete-branch
# Unconnected finish
.PHONY: finish-unconnected
finish-unconnected: ensure-committed
@echo "Finishing up..."
$(GIT) push -u origin HEAD
$(GH) pr create --fill
$(GH) pr merge --merge --delete-branch
# Guard against missing environment variables
# https://stackoverflow.com/a/7367903
.PHONY: guard-%
guard-%:
@ if [ "${${*}}" = "" ]; then \
echo "Environment variable $* not set"; \
exit 1; \
fi