aboutsummaryrefslogtreecommitdiff
path: root/tools/release-checks.sh
blob: a16bee4019f39d284071f72116b6dd0bcd9945eb (plain)
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
#!/bin/sh

LANG_FILE=tools/exported-language-codes.csv
RESDIR=WordPress/src/main/res/
BUILDFILE=WordPress/build.gradle

function checkDeviceToTest() {
	lines=$(adb devices -l|wc -l)
	if [ $lines -le 2 ]; then
		echo You need a device connected or an emulator running
		exit 2
	fi
}

function runConnectedTests() {
	echo Tests will be run on following devices:
	adb devices -l
	echo -----------
	./gradlew cIT
}

function pOk() {
	echo "[$(tput setaf 2)OK$(tput sgr0)]"
}

function pFail() {
	echo "[$(tput setaf 1)KO$(tput sgr0)]"
}

function checkENStrings() {
	if [[ -n $(git status --porcelain|grep "M res") ]]; then
		/bin/echo -n "Unstagged changes detected in $RESDIR/ - can't continue..."
		pFail
		exit 3
	fi
	# save local changes
	git stash | grep "No local changes to save" > /dev/null
	needpop=$?

	rm -f $RESDIR/values-??/strings.xml $RESDIR/values-??-r??/strings.xml
	/bin/echo -n "Check for missing strings (slow)..."
	./gradlew build > /dev/null 2>&1 && pOk || (pFail; ./gradlew build)
	./gradlew clean > /dev/null 2>&1
	git checkout -- $RESDIR/

	# restore local changes
	if [ $needpop -eq 1 ]; then
	     git stash pop > /dev/null
	fi
}

function checkNewLanguages() {
	/bin/echo -n "Check for potential new languages..."
	langs=`curl -L http://translate.wordpress.org/projects/apps/android/dev 2> /dev/null \
   		| grep -B 1 morethan90|grep "android/dev/" \
   		| sed "s+.*android/dev/\([a-zA-Z-]*\)/default.*+\1+"`
	nerrors=''
	for lang in $langs; do
		grep "^$lang," $LANG_FILE > /dev/null
		if [ $? -ne 0 ]; then
			nerrors=$nerrors"language code $lang has reached 90% translation threshold and hasn't been found in $LANG_FILE\n"
		fi
	done
	if [ "x$nerrors" = x ]; then
		pOk
	else
		pFail
		echo $nerrors
	fi
}

function printVersion() {
	gradle_version=$(grep -E 'versionName' $BUILDFILE | sed s/versionName// | grep -Eo "[a-zA-Z0-9.-]+" )
	echo "$BUILDFILE version $gradle_version"
}

function checkGradleProperties() {
	/bin/echo -n "Check WordPress/gradle.properties..."
	checksum=`cat WordPress/gradle.properties | grep -v "^wp.debug." | grep "^wp."|tr "[A-Z]" "[a-z]" | sed "s/ //g" | sort | sha1sum | cut -d- -f1 | sed "s/ //g"`
	known_checksum="4058cdf3d784e4b79f63514d4780e92c28b5ab78"
	if [ x$checksum != x$known_checksum ]; then
		pFail
		exit 5
	fi
	pOk
}

checkNewLanguages
# checkENStrings
checkGradleProperties
printVersion
# checkDeviceToTest
# runConnectedTests