Makefile 6.05 KB
Newer Older
1 2
all: css

3
production = true
4 5 6 7 8 9 10 11 12 13 14 15 16 17
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..."
18
	@if gulp css --production $(production) ; then echo "Done!"; else npm install; gulp css --production $(production);  fi
19 20

clean-css:
21
	find ./htdocs/theme/* -maxdepth 1 -name "style" -type d -exec rm -Rf {} \;
22 23 24

help:
	@echo "Run 'make' to do "build" Mahara (currently only CSS)"
25 26
	@echo "Run 'make initcomposer' to install Composer and phpunit"
	@echo "Run 'make phpunit' to execute phpunit tests"
27 28
	@echo "Run 'make ssphp' to install SimpleSAMLphp"
	@echo "Run 'make cleanssphp' to remove SimpleSAMLphp"
29 30
	@echo "Run 'make imageoptim' to losslessly optimise all images"
	@echo "Run 'make minaccept' to run the quick pre-commit tests"
31
	@echo "Run 'make checksignoff' to check that your commits are all Signed-off-by"
32 33 34 35 36 37 38 39
	@echo "Run 'make push' to push your changes to the repo"

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 {} \;

40 41
composer := $(shell ls external/composer.phar 2>/dev/null)

42
installcomposer:
43
ifdef composer
44
	@echo "Composer already installed..."
45 46 47 48 49
else
	@echo "Installing Composer..."
	@curl -sS https://getcomposer.org/installer | php -- --install-dir=external
endif

50 51 52 53 54 55 56 57 58 59
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

60
ssphp:
61 62 63 64
ifdef simplesamlphp
	@echo "SimpleSAMLphp already exists - doing nothing"
else
	@echo "Pulling SimpleSAMLphp from download ..."
65
	@curl -sSL https://github.com/simplesamlphp/simplesamlphp/releases/download/v1.15.0/simplesamlphp-1.15.0.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.
66
#	@php external/composer.phar --working-dir=htdocs/auth/saml/extlib/simplesamlphp update --no-dev
67 68
	@echo "Copying www/resources/* files to sp/resources/ ..."
	@cp -R htdocs/auth/saml/extlib/simplesamlphp/www/resources/ htdocs/auth/saml/sp/
69 70 71 72 73
	@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!"
74 75 76
endif


77 78 79 80 81 82 83 84 85 86 87 88 89
vendorphpunit := $(shell external/vendor/bin/phpunit --version 2>/dev/null)

phpunit:
	@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


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)
90
breakpoints := $(shell git diff-tree --diff-filter=ACM --name-only --no-commit-id -r -z $(revision) |  grep -rn --include=*.feature "I insert breakpoint"  test/behat/features)
91

92
minaccept:
93
	@echo "Running minimum acceptance test..."
94 95 96 97 98 99
ifdef breakpoints
	@echo "Oops, you left breakpoints in your tests :/"
	@git diff-tree --diff-filter=ACM --name-only --no-commit-id -r -z $(revision) |  grep -rn --include=*.feature "I insert breakpoint"  test/behat/features
	@echo "Please remove breakpoints, commit and push again"
	exit 1
endif
100
ifdef revision
101
	@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
102
	@php test/versioncheck.php
103 104 105
	@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. :)"
106 107 108
else
	@echo "No revision found!"
endif
109

110
jenkinsaccept: minaccept
111
	@find ./ ! -path './.git/*' -type f -print0 | xargs -0 clamscan > /dev/null && echo All good!
112

113
sshargs := $(shell git config --get remote.gerrit.url | sed -re 's~^ssh://([^@]*)@([^:]*):([0-9]*)/mahara~-p \3 -l \1 \2~')
114
mergebase := $(shell git fetch gerrit >/dev/null 2>&1 && git merge-base HEAD gerrit/master)
115 116 117 118 119 120 121 122
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
123 124 125 126
	@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
127 128

push: securitycheck minaccept
129 130
	@echo "Pushing the change upstream..."
	@if test -z "$(TAG)"; then \
131
		git push gerrit HEAD:refs/publish/master; \
132
	else \
133
		git push gerrit HEAD:refs/publish/master/$(TAG); \
134
	fi
135 136 137 138 139 140 141 142 143

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)