Makefile 9.18 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# The mode that behat tests are run with.
BEHAT_MODE = rundebugheadless
# Can limit what behat tests are run, e.g `make -e BEHAT_TESTS=change_account_settings.feature behat`
BEHAT_TESTS = null
# ask for test reports to be generated possible values are <empty>, 'html', 'junit'
BEHAT_REPORT =
# The Ubuntu version that the Mahara base image will be based on
DOCKER_UBUNTU_VERSION = bionic
TEST_ADMIN_PASSWD = Kupuh1pa!
TEST_ADMIN_EMAIL  = user@example.org

# Make expects targets to create a file that matches the target name
# unless the target is phony.
# Refer to: https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: css clean-css help imageoptim installcomposer initcomposer cleanssphp ssphp \
		cleanpdfexport pdfexport install phpunit behat minaccept jenkinsaccept securitycheck \
		push security docker-image docker-builder

19
20
all: css

21
production = true
22
23
24
25
26
27
28
29
30
31
32
33
34
35
css:
ifeq (, $(shell which npm))
	$(error ERROR: Can't find the "npm" executable. Try "sudo apt-get install npm")
endif
ifeq (, $(shell which node))
	$(error ERROR: Can't find the "node" executable. Try "sudo apt-get install nodejs-legacy")
endif
ifeq (, $(shell which gulp))
	$(error ERROR: Can't find the "gulp" executable. Try doing "sudo npm install -g gulp")
endif
ifndef npmsetup
	npm install
endif
	@echo "Building CSS..."
36
	@if gulp css --production $(production) ; then echo "Done!"; else npm install; gulp css --production $(production);  fi
37
38

clean-css:
Aaron Wells's avatar
Aaron Wells committed
39
	find ./htdocs/theme/* -maxdepth 1 -name "style" -type d -exec rm -Rf {} \;
40
41
42

help:
	@echo "Run 'make' to do "build" Mahara (currently only CSS)"
Yuliya Bozhko's avatar
Yuliya Bozhko committed
43
44
	@echo "Run 'make initcomposer' to install Composer and phpunit"
	@echo "Run 'make phpunit' to execute phpunit tests"
45
46
	@echo "Run 'make install' runs the Mahara install script"
	@echo "Run 'make behat' to execute behat tests"
47
48
	@echo "Run 'make ssphp' to install SimpleSAMLphp"
	@echo "Run 'make cleanssphp' to remove SimpleSAMLphp"
49
50
	@echo "Run 'make imageoptim' to losslessly optimise all images"
	@echo "Run 'make minaccept' to run the quick pre-commit tests"
51
	@echo "Run 'make checksignoff' to check that your commits are all Signed-off-by"
52
	@echo "Run 'make push' to push your changes to the repo"
53
54
	@echo "Run 'make docker-image' to build a Mahara docker image"
	@echo "Run 'make docker-builder' builds the docker builder image required for docker-build"
55
56
57
58
59
60
61

imageoptim:
	find . -iname '*.png' -exec optipng -o7 -q {} \;
	find . -iname '*.gif' -exec gifsicle -O2 -b {} \;
	find . -iname '*.jpg' -exec jpegoptim -q -p --strip-all {} \;
	find . -iname '*.jpeg' -exec jpegoptim -q -p --strip-all {} \;

Yuliya Bozhko's avatar
Yuliya Bozhko committed
62
63
composer := $(shell ls external/composer.phar 2>/dev/null)

64
installcomposer:
Yuliya Bozhko's avatar
Yuliya Bozhko committed
65
ifdef composer
66
	@echo "Composer already installed..."
Yuliya Bozhko's avatar
Yuliya Bozhko committed
67
68
else
	@echo "Installing Composer..."
69
	@curl -sS https://getcomposer.org/installer | php -- --install-dir=external --version=1.10.16
Yuliya Bozhko's avatar
Yuliya Bozhko committed
70
71
endif

72
73
74
75
76
77
78
79
80
81
initcomposer: installcomposer
	@echo "Updating external dependencies with Composer..."
	@php external/composer.phar --working-dir=external update

simplesamlphp := $(shell ls -d htdocs/auth/saml/extlib/simplesamlphp 2>/dev/null)

cleanssphp:
	@echo "Cleaning out SimpleSAMLphp..."
	rm -rf htdocs/auth/saml/extlib/simplesamlphp

82
ssphp: initcomposer
83
84
85
86
ifdef simplesamlphp
	@echo "SimpleSAMLphp already exists - doing nothing"
else
	@echo "Pulling SimpleSAMLphp from download ..."
87
	@curl -sSL https://github.com/simplesamlphp/simplesamlphp/releases/download/v1.18.7/simplesamlphp-1.18.7.tar.gz | tar  --transform 's/simplesamlphp-[0-9]+\.[0-9]+\.[0-9]+/simplesamlphp/x1' -C htdocs/auth/saml/extlib -xzf - # SimpleSAMLPHP release tarball already has all composer dependencies.
88
	@php external/composer.phar --working-dir=htdocs/auth/saml/extlib/simplesamlphp require predis/predis
89
90
	@echo "Copying www/resources/* files to sp/resources/ ..."
	@cp -R htdocs/auth/saml/extlib/simplesamlphp/www/resources/ htdocs/auth/saml/sp/
91
92
93
94
95
	@echo "Deleting unneeded files ..."
#	Delete composer.json and .lock files to avoid leaking minor version info
	@find htdocs/auth/saml/extlib -type f -name composer.json -delete
	@find htdocs/auth/saml/extlib -type f -name composer.lock -delete
	@echo "Done!"
96
97
endif

98
99
100
101
102
103
104
105
106
107
108
pdfexportfile := $(shell ls -d htdocs/lib/chrome-php/headless-chromium-php-master 2>/dev/null)

cleanpdfexport:
	@echo "Cleaning out PDF export files..."
	rm -rf htdocs/lib/chrome-php

pdfexport: initcomposer
ifdef pdfexportfile
	@echo "PDF export files already exists - doing nothing"
else
	@echo "Pulling Headless-chromium-php from download ..."
109
110
111
112
	@curl -sSL https://github.com/chrome-php/headless-chromium-php/archive/0.10.zip -o pdf_tmp.zip && unzip pdf_tmp.zip -d htdocs/lib/chrome-php && rm pdf_tmp.zip
	@php external/composer.phar --working-dir=htdocs/lib/chrome-php/headless-chromium-php-0.10 install
	@find htdocs/lib/chrome-php/headless-chromium-php-0.10 -type f -name composer.json -delete
	@find htdocs/lib/chrome-php/headless-chromium-php-0.10 -type f -name composer.lock -delete
113
114
115
	@find htdocs/lib/chrome-php -type d -name Tests -exec rm -r {} +
	@echo "Done!"
endif
116

Yuliya Bozhko's avatar
Yuliya Bozhko committed
117
118
vendorphpunit := $(shell external/vendor/bin/phpunit --version 2>/dev/null)

119
120
121
122
install:
	php htdocs/admin/cli/install.php --adminpassword=$(TEST_ADMIN_PASSWD) --adminemail=$(TEST_ADMIN_EMAIL)

phpunit: install
Yuliya Bozhko's avatar
Yuliya Bozhko committed
123
124
125
126
127
128
129
	@echo "Running phpunit tests..."
ifdef vendorphpunit
	@external/vendor/bin/phpunit --log-junit logs/tests/phpunit-results.xml htdocs/
else
	@phpunit --log-junit logs/tests/phpunit-results.xml htdocs/
endif

130
131
behat:
	./test/behat/mahara_behat.sh $(BEHAT_MODE) $(BEHAT_TESTS) $(BEHAT_REPORT)
Yuliya Bozhko's avatar
Yuliya Bozhko committed
132
133
134

revision := $(shell git rev-parse --verify HEAD 2>/dev/null)
whitelist := $(shell grep / test/WHITELIST | xargs -I entry find entry -type f | xargs -I file echo '! -path ' file 2>/dev/null)
135
136
mergebase := $(shell git fetch gerrit >/dev/null 2>&1 && git merge-base HEAD gerrit/master)
breakpoints := $(shell git diff-tree --diff-filter=ACM --no-commit-id -r -z -p $(mergebase) HEAD test/behat/features |  grep "I insert breakpoint")
Yuliya Bozhko's avatar
Yuliya Bozhko committed
137

138
minaccept:
139
	@echo "Running minimum acceptance test..."
140
141
ifdef breakpoints
	@echo "Oops, you left breakpoints in your tests :/"
142
	@git diff-tree --diff-filter=ACM --no-commit-id -r -z -p $(mergebase) HEAD test/behat/features |  grep "I insert breakpoint"
143
144
145
	@echo "Please remove breakpoints, commit and push again"
	exit 1
endif
Yuliya Bozhko's avatar
Yuliya Bozhko committed
146
ifdef revision
147
	@git diff-tree --diff-filter=ACM --no-commit-id --name-only -z -r $(revision) htdocs | grep -z "^htdocs/.*\.php$$" | xargs -0 -n 1 -P 2 --no-run-if-empty php -l
148
	@php test/versioncheck.php
149
150
151
	@git diff-tree --diff-filter=ACM --no-commit-id --name-only -z -r $(revision) htdocs | grep -z '^htdocs/.*/db/install\.xml$$' | xargs -0 -n 1 -P 2 --no-run-if-empty xmllint --schema htdocs/lib/xmldb/xmldb.xsd --noout
	@git diff-tree --diff-filter=ACM --no-commit-id --name-only -r $(revision) | xargs -I {} find {} $(whitelist) | xargs -I list git show $(revision) -- list | test/coding-standard-check.pl
	@echo "Acceptance test passed. :)"
Yuliya Bozhko's avatar
Yuliya Bozhko committed
152
153
154
else
	@echo "No revision found!"
endif
155

156
jenkinsaccept: minaccept
Yuliya Bozhko's avatar
Yuliya Bozhko committed
157
	@find ./ ! -path './.git/*' -type f -print0 | xargs -0 clamscan > /dev/null && echo All good!
158

159
160
161
162
163
164
165
166
167
sshargs := $(shell git config --get remote.gerrit.url | sed -re 's~^ssh://([^@]*)@([^:]*):([0-9]*)/mahara~-p \3 -l \1 \2~')
sha1chain := $(shell git log $(mergebase)..HEAD --pretty=format:%H | xargs)
changeidchain := $(shell git log $(mergebase)..HEAD --pretty=format:%b | grep '^Change-Id:' | cut -d' ' -f2)

securitycheck:
	@if ssh $(sshargs) gerrit query --format TEXT -- $(shell echo $(sha1chain) $(changeidchain) | sed -e 's/ / OR /g') | grep 'status: DRAFT' >/dev/null; then \
		echo "This change has drafts in the chain. Please use make security instead"; \
		false; \
	fi
168
169
170
171
	@if git log $(mergebase)..HEAD --pretty=format:%B | grep -iE '(security|cve)' >/dev/null; then \
		echo "This change has a security keyword in it. Please use make security instead"; \
		false; \
	fi
172
173

push: securitycheck minaccept
174
175
	@echo "Pushing the change upstream..."
	@if test -z "$(TAG)"; then \
176
		git push gerrit HEAD:refs/publish/master; \
177
	else \
178
		git push gerrit HEAD:refs/publish/master/$(TAG); \
179
	fi
180
181
182
183
184
185
186
187
188

security: minaccept
	@echo "Pushing the SECURITY change upstream..."
	@if test -z "$(TAG)"; then \
		git push gerrit HEAD:refs/drafts/master; \
	else \
		git push gerrit HEAD:refs/drafts/master/$(TAG); \
	fi
	ssh $(sshargs) gerrit set-reviewers --add \"Mahara Security Managers\" -- $(sha1chain)
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210

# Builds Mahara server docker image
docker-image:
	docker build --pull --file docker/Dockerfile.mahara-base \
	  --build-arg BASE_VERSION=$(DOCKER_UBUNTU_VERSION) \
		--tag mahara-base:$(DOCKER_UBUNTU_VERSION) .
	docker build --file docker/Dockerfile.mahara-web \
	  --build-arg BASE_IMAGE=mahara-base:$(DOCKER_UBUNTU_VERSION) \
	  --tag mahara .

# Builds a docker image that is able to build Mahara. Useful if you don't want
# to install dependencies on your system.
# The builder is made for the user that will use it. This is so that the built
# files are owned by the user and not some other user (eg not root)
docker-builder:
	docker build --pull --file docker/Dockerfile.mahara-base \
	  --build-arg BASE_VERSION=$(DOCKER_UBUNTU_VERSION) \
		--tag mahara-base:$(DOCKER_UBUNTU_VERSION) .
	docker build --file docker/Dockerfile.mahara-builder \
	  --build-arg BASE_IMAGE=mahara-base:$(DOCKER_UBUNTU_VERSION) \
		--build-arg IMAGE_UID=$(shell id -u) --build-arg IMAGE_GID=$(shell id -g) \
		--tag mahara-builder .