-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
188 lines (161 loc) · 4.55 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
MAKEFLAGS += --warn-undefined-variables -j1
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := all
.DELETE_ON_ERROR:
.SUFFIXES:
.PHONY:
# Environment switches
MAKE_ENV ?= docker
COMPOSE_RUN_SHELL_FLAGS ?= --rm
BASH_RUN_SHELL_FLAGS ?=
# Directories
VENDOR_DIR ?= vendor/bundle
GEMFILES_DIR ?= gemfiles
# Host binaries
AWK ?= awk
BASH ?= bash
COMPOSE ?= docker-compose
CP ?= cp
DOCKER ?= docker
FIND ?= find
GREP ?= grep
HEAD ?= head
ID ?= id
MKDIR ?= mkdir
RM ?= rm
SORT ?= sort
TEST ?= test
XARGS ?= xargs
# Container binaries
APPRAISAL ?= appraisal
BUNDLE ?= bundle
GEM ?= gem
GUARD ?= guard
RAKE ?= rake
RSPEC ?= rspec
RUBOCOP ?= rubocop
YARD ?= yard
RUBY_VERSION := ruby-version
# Files
GEMFILES ?= $(subst _,-,$(patsubst $(GEMFILES_DIR)/%.gemfile,%,\
$(wildcard $(GEMFILES_DIR)/*.gemfile)))
TEST_GEMFILES := $(GEMFILES:%=test-%)
all:
# jabber_admin
#
# install Install the dependencies
# update Update the local Gemset dependencies
# clean Clean the dependencies
#
# test Run the whole test suite
# test-style Test the code styles
# watch Watch for code changes and rerun the test suite
#
# docs Generate the Ruby documentation of the library
# stats Print the code statistics (library and test suite)
# notes Print all the notes from the code
# release Release a new Gem version (maintainers only)
#
# shell Run an interactive shell on the container
# shell-irb Run an interactive IRB shell on the container
#
# supported-commands-list Generate the supported commands list
# Define a generic shell run wrapper
# $1 - The command to run
ifeq ($(MAKE_ENV),docker)
define run-shell
$(COMPOSE) run $(COMPOSE_RUN_SHELL_FLAGS) \
-e LANG=en_US.UTF-8 -e LANGUAGE=en_US.UTF-8 -e LC_ALL=en_US.UTF-8 \
-e HOME=/home/web -e BUNDLE_APP_CONFIG=/app/.bundle \
-u `$(ID) -u` test \
bash $(BASH_RUN_SHELL_FLAGS) -c 'sleep 0.1; echo; $(1)'
endef
else ifeq ($(MAKE_ENV),baremetal)
define run-shell
$(1)
endef
endif
.interactive:
@$(eval BASH_RUN_SHELL_FLAGS = --login)
install:
# Install the dependencies
@$(MKDIR) -p $(VENDOR_DIR)
@$(call run-shell,$(BUNDLE) check || $(BUNDLE) install --path $(VENDOR_DIR))
@$(call run-shell,$(BUNDLE) exec $(APPRAISAL) install)
update:
# Install the dependencies
@$(MKDIR) -p $(VENDOR_DIR)
@$(call run-shell,$(BUNDLE) update)
@$(call run-shell,$(BUNDLE) exec $(APPRAISAL) update)
watch: install .interactive
# Watch for code changes and rerun the test suite
@$(call run-shell,$(BUNDLE) exec $(GUARD))
test: \
test-specs \
test-style
test-specs:
# Run the whole test suite
@$(call run-shell,$(BUNDLE) exec $(RAKE) stats spec)
$(TEST_GEMFILES): GEMFILE=$(@:test-%=%)
$(TEST_GEMFILES):
# Run the whole test suite ($(GEMFILE))
@$(call run-shell,$(BUNDLE) exec $(APPRAISAL) $(GEMFILE) $(RSPEC))
test-style: test-style-ruby
test-style-ruby:
# Run the static code analyzer (rubocop)
@$(call run-shell,$(BUNDLE) exec $(RUBOCOP) -a \
|| ($(TEST) $$($(RUBY_VERSION)) != '2.7' && true))
clean:
# Clean the dependencies
@$(RM) -rf $(VENDOR_DIR)
@$(RM) -rf .bundle .yardoc coverage pkg Gemfile.lock doc/api \
.rspec_status
clean-containers:
# Clean running containers
ifeq ($(MAKE_ENV),docker)
@$(COMPOSE) down
endif
clean-images:
# Clean build images
ifeq ($(MAKE_ENV),docker)
@-$(DOCKER) images | $(GREP) $(shell basename "`pwd`") \
| $(AWK) '{ print $$3 }' \
| $(XARGS) -rn1 $(DOCKER) rmi -f
endif
distclean: clean clean-containers clean-images
shell:
# Run an interactive shell on the container
@$(call run-shell,$(BASH) -i)
shell-irb:
# Run an interactive IRB shell on the container
@$(call run-shell,bin/console)
docs:
# Build the API documentation
@$(RM) -rf doc/api
@$(call run-shell,$(BUNDLE) exec $(YARD) -q && \
$(BUNDLE) exec $(YARD) stats --list-undoc --compact)
@$(MKDIR) -p doc/api/doc doc/api/assets
@$(CP) -ar doc/assets doc/api/doc
@$(CP) -ar doc/assets/* doc/api/assets
#
# Docs: file://$(abspath doc/api)/index.html
notes:
# Print the code statistics (library and test suite)
@$(call run-shell,$(BUNDLE) exec $(RAKE) notes)
stats:
# Print all the notes from the code
@$(call run-shell,$(BUNDLE) exec $(RAKE) stats)
release:
# Release a new gem version
@$(BUNDLE) exec $(RAKE) release
supported-commands-list:
# Generate the supported commands list
@$(ECHO)
@$(GREP) -oP '@see https?://.*' -R lib/jabber_admin/commands/ \
| $(SED) \
-e 's/@see //g' \
-e 's/.rb:/](/g' \
-e 's/$$/)/g' \
-e 's#^lib/jabber_admin/commands/#- [#g' \
| $(SORT)