summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2019-06-28 13:58:16 -0700
committerJason Wray <jason@mapbox.com>2019-06-28 15:37:57 -0700
commit218cc413543fdeba93ac205d352f8695706c0e9e (patch)
tree307685c08bc58f08e35aa1206fc1aab211ab9323
parent797358377de2d7402f358a9b9b19ad833c922ff5 (diff)
downloadqtlocation-mapboxgl-upstream/friedbunny-lints-some-podspecs.tar.gz
[ios, build] Add podspec lint scriptupstream/friedbunny-lints-some-podspecs
-rw-r--r--Makefile6
-rwxr-xr-xplatform/ios/scripts/lint-podspecs.js68
2 files changed, 73 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 35bf097486..aefd0b0458 100644
--- a/Makefile
+++ b/Makefile
@@ -292,10 +292,14 @@ iproj: $(IOS_PROJ_PATH)
xed $(IOS_WORK_PATH)
.PHONY: ios-lint
-ios-lint:
+ios-lint: ios-pod-lint
find platform/ios/framework -type f -name '*.plist' | xargs plutil -lint
find platform/ios/app -type f -name '*.plist' | xargs plutil -lint
+.PHONY: ios-pod-lint
+ios-pod-lint:
+ ./platform/ios/scripts/lint-podspecs.js
+
.PHONY: ios-test
ios-test: $(IOS_PROJ_PATH)
set -o pipefail && $(IOS_XCODEBUILD_SIM) -scheme 'CI' test $(XCPRETTY)
diff --git a/platform/ios/scripts/lint-podspecs.js b/platform/ios/scripts/lint-podspecs.js
new file mode 100755
index 0000000000..c5e1c6d49b
--- /dev/null
+++ b/platform/ios/scripts/lint-podspecs.js
@@ -0,0 +1,68 @@
+#!/usr/bin/env node
+
+const fs = require('fs');
+const execSync = require('child_process').execSync;
+const _ = require('lodash');
+const semver = require('semver');
+
+console.step = _.partial(console.log, '\n\033[1m\033[36m*', _, '\033[0m');
+
+const podspecsPath = 'platform/ios';
+
+/*
+ ------------------------
+*/
+console.step(`Running CocoaPods linter against podspecs in '${podspecsPath}'`)
+execSync(`pod spec lint ${podspecsPath}/*.podspec --quick`, {stdio: 'inherit'});
+
+/*
+ ------------------------
+*/
+console.step('Checking Mapbox SDK version strings in podspecs')
+const podspecs = fs.readdirSync(podspecsPath).filter(fn => fn.endsWith('.podspec'));
+
+let matchedVersions = [];
+
+for (const podspecFilename of podspecs) {
+ console.log(podspecFilename);
+ const podspecContents = fs.readFileSync(`${podspecsPath}/${podspecFilename}`, 'utf8');
+
+ /*
+ This regular expression:
+ - Matches single lines in the format: version = '9.9.9'
+ - Groups the version number inside the single quotes.
+ - Ignores whitespace at the start of the line and between parts of the definition using: \s*?
+ */
+ const regex = /^\s*?version\s*?=\s*?'(.*)'$/gmi;
+
+ const match = regex.exec(podspecContents);
+ if (!match) {
+ console.error(' ❌ No version string found');
+ process.exitCode = 1;
+ continue;
+ }
+
+ const matchedVersion = match[1];
+ matchedVersions.push(matchedVersion);
+
+ const semanticVersion = semver.valid(matchedVersion);
+ if (!semanticVersion) {
+ console.error(` ❌ ${matchedVersion} is not a valid semantic version`);
+ process.exitCode = 1;
+ continue;
+ }
+
+ console.log(` ✅ ${matchedVersion} is a valid semantic version`);
+}
+
+/*
+ ------------------------
+*/
+console.step('Checking version consistency')
+const uniqueVersions = _.uniq(matchedVersions);
+if (uniqueVersions.length != 1) {
+ console.error('❌ Versions in podspecs do not match:', uniqueVersions);
+ process.exitCode = 1;
+} else {
+ console.log(`✅ ${uniqueVersions[0]} is set in all podspecs`);
+}