Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.

Commit 3bfb619

Browse files
wrmswindmillYorkShen
authored andcommitted
[Travis] Add Lint in TravisCI and Update iOS TravisCI (#2731)
Add the following tasks: * Android Lint * OCLint
1 parent 0135e3c commit 3bfb619

9 files changed

+276
-70
lines changed

Diff for: .travis.yml

+99-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
os: linux
22
language: node_js
3-
node_js: 7.6
3+
node_js: 12.6.0
44
matrix:
55
fast_finish: true
66
include:
@@ -25,29 +25,63 @@ matrix:
2525
- android-26
2626
- extra-android-m2repository
2727
- env: TEST_SUITE=android ABI=x86
28+
language: android
29+
dist: trusty
30+
jdk: oraclejdk8
31+
android:
32+
components:
33+
- android-26
34+
- extra-android-m2repository
35+
# static check
36+
- env: TEST_SUITE=static_code_analysis OCLINT=true
37+
osx_image: xcode7.2
38+
language: objective-c
39+
- env: TEST_SUITE=static_code_analysis ANDROID_LINT=true
2840
language: android
2941
dist: trusty
3042
jdk: oraclejdk8
3143
android:
3244
components:
3345
- android-26
3446
- extra-android-m2repository
47+
3548
cache:
3649
directories:
3750
- npm
3851
- $HOME/.gradle/caches/
3952
- $HOME/.gradle/wrapper/
4053
- $HOME/.android/build-cache
4154
- $HOME/android-ndk-r18b
55+
- bundle
56+
4257
before_cache:
4358
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
4459
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
60+
- rm -fr $HOME/node_modules/*
61+
62+
before_install:
63+
- |
64+
# install android lint
65+
if [[ ("$TEST_SUITE" = "static_code_analysis") && ("${ANDROID_LINT}" = "true") ]]; then
66+
apt-get install rubygems
67+
gem install bundler
68+
bundle install
69+
fi
70+
71+
# install oclint
72+
if [[ ("$TEST_SUITE" = "static_code_analysis") && ("${OCLINT}" = "true") ]]; then
73+
brew cask uninstall oclint
74+
brew tap oclint/formulae
75+
brew install oclint
76+
fi
77+
78+
79+
4580
install:
4681
- |
47-
case $TEST_SUITE in
48-
"android")
82+
if [[ ("$TEST_SUITE" = "android") || ("${ANDROID_LINT}" = "true") ]]; then
4983
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
50-
nvm install 7.6
84+
nvm install 12.6.0
5185
npm install
5286
echo y | sdkmanager "cmake;3.6.4111459"
5387
if find "${HOME}/android-ndk-r18b" -mindepth 1 | read; then
@@ -64,11 +98,22 @@ install:
6498
export ANDROID_NDK_HOME=$HOME/android-ndk-r18b
6599
export PATH=$PATH:$ANDROID_NDK_HOME
66100
echo "ndk.dir=$ANDROID_NDK_HOME" > android/local.properties
67-
;;
68-
"jsfm" | "danger" | "ios" )
101+
elif [[ ("$TEST_SUITE" = "jsfm") || ("$TEST_SUITE" = "danger") || ("${OCLINT}" = "true") ]]; then
102+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
103+
nvm install 12.6.0
69104
npm install
70-
;;
71-
esac
105+
elif [[ ("$TEST_SUITE" = "ios") ]]; then
106+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
107+
nvm install 12.6.0
108+
109+
git submodule update --init --remote
110+
cd weex-playground/ios && bash update_podfile_for_travisci.sh
111+
cd ../../ && npm install
112+
cd weex-playground/ios && pod install --repo-update
113+
cd ../../
114+
fi
115+
116+
72117
script:
73118
- |
74119
case $TEST_SUITE in
@@ -87,29 +132,65 @@ script:
87132
GRADLE_ABI=""
88133
;;
89134
esac
90-
91-
hasAndroidFile=$(npm run danger -- run --dangerfile ./dangerfile-android.js)
92-
echo "The value of hasAndroidFile is ${hasAndroidFile}"
93-
if [[ "$hasAndroidFile" =~ "hasAndroidFile" ]]; then
135+
if npm run danger -- ci --dangerfile ./dangerfile-android.js | grep -q "hasAndroidFile" ; then
94136
cd android
95137
./gradlew clean install -PbuildRuntimeApi=true ${GRADLE_ABI} --info
96138
./gradlew install -PbuildRuntimeApi=false ${GRADLE_ABI} --info
97139
fi
98140
;;
99141
"jsfm" )
100-
npm run danger -- run --dangerfile ./dangerfile-jsfm.js
142+
npm run danger -- ci -i jsfm --dangerfile ./dangerfile-jsfm.js
101143
;;
102144
"danger" )
103-
npm run danger -- run --dangerfile ./dangerfile.js
145+
npm run danger -- ci -i danger --dangerfile ./dangerfile.js
104146
;;
105147
"ios" )
106-
hasIosFile=$(npm run danger -- run --dangerfile ./dangerfile-ios.js)
107-
echo "The value of hasIosFile is ${hasIosFile}"
108-
if [[ "$hasIosFile" =~ "hasIosFile" ]]; then
109-
xcodebuild -project ios/sdk/WeexSDK.xcodeproj test -scheme WeexSDKTests CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -destination "platform=iOS Simulator,name=iPhone 6"
148+
if npm run danger -- ci --dangerfile ./dangerfile-ios.js | grep -q "hasIosFile" ; then
149+
# build WeexSDK and run WeexSDKTests
150+
xcodebuild -quiet -project ios/sdk/WeexSDK.xcodeproj test -scheme WeexSDKTests CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -destination "platform=iOS Simulator,name=iPhone 6" || exit 1
151+
# build WeexDemo and run WeexDemo test
152+
cd weex-playground/ios && mkdir tmp && mv * tmp;cd tmp
153+
xcodebuild -quiet -workspace WeexDemo.xcworkspace test -scheme WeexDemo CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -destination "platform=iOS Simulator,name=iPhone 6" || exit 1
110154
fi
111155
;;
112156
esac
157+
158+
if [[ ("$TEST_SUITE" = "static_code_analysis") && ("${OCLINT}" = "true") ]]; then
159+
if npm run danger -- ci --dangerfile ./dangerfile-static-check.js | grep -q "hasCFile" ; then
160+
echo "hasCFile"
161+
cd ios/sdk && xcodebuild | xcpretty -r json-compilation-database -o compile_commands.json
162+
oclint-json-compilation-database oclint_args -- \
163+
-disable-rule=ShortVariableName \
164+
-disable-rule=LongLine \
165+
-disable-rule=LongMethod \
166+
-disable-rule=HighNcssMethod \
167+
-disable-rule=LongVariableName \
168+
-disable-rule=HighCyclomaticComplexity \
169+
-disable-rule=HighNPathComplexity \
170+
-disable-rule=UnusedLocalVariable \
171+
-disable-rule=DoubleNegative \
172+
-disable-rule=MultipleUnaryOperator \
173+
-disable-rule=DeepNestedBlock \
174+
-disable-rule=AssignIvarOutsideAccessors \
175+
-disable-rule=BitwiseOperatorInConditional \
176+
-max-priority-1=15000 \
177+
-max-priority-2=15000 \
178+
-max-priority-3=15000 > oclint.log
179+
export TITLE="OCLint Result"
180+
cd ../../ && npm run danger -- ci -i oclint --dangerfile ./dangerfile-output.js
181+
fi
182+
fi
183+
184+
if [[ ("$TEST_SUITE" = "static_code_analysis") && ("${ANDROID_LINT}" = "true") ]]; then
185+
if npm run danger -- ci --dangerfile ./dangerfile-static-check.js | grep -q "hasAndroidFile" ; then
186+
echo "hasAndroidFile"
187+
cd android
188+
./gradlew :weex_sdk:lint --quiet
189+
export TITLE="AndroidLint Result"
190+
cd ../ && npm run danger -- ci -i androidlint --dangerfile ./dangerfile-output.js
191+
fi
192+
fi
193+
113194
notifications:
114195
webhooks:
115196
on_pull_requests: false

Diff for: Dangerfile

Whitespace-only changes.

Diff for: dangerfile-ios.js

+2-19
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,5 @@ if (!hasIosFile && danger.git.deleted_files) {
9090
}
9191

9292
if(hasIosFile){
93-
console.log('hasIosFile');
94-
}
95-
// console.log('-----------------------------hasIosFile-----------------------------:'+hasIosFile);
96-
// if(hasIosFile){
97-
// var runTestCmd='source ~/.bash_profile; '
98-
// +'xcodebuild -project ios/sdk/WeexSDK.xcodeproj test '
99-
// +'-scheme WeexSDKTests CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO '
100-
// +'-destination "platform=iOS Simulator,name=iPhone 6"'
101-
// runSuccess = shell.exec(runTestCmd,{ async: false, timeout: 8 * 60 * 1000, maxBuffer: 200 * 1024 * 1024 }).code == 0;
102-
// if(!runSuccess){
103-
// fail("ios platform run unit test failed!");
104-
// }
105-
// }else{
106-
// console.log('has no ios file changed.');
107-
// message('has no ios file changed.');
108-
// }
109-
// message('ios test finished.')
110-
111-
93+
console.log('hasIosFile!!!');
94+
}

Diff for: dangerfile-output.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { fail, warn } from 'danger'
21+
const shell = require('shelljs')
22+
const title = process.env.TITLE
23+
const fs = require('fs')
24+
25+
// code come from: https://stackoverflow.com/a/12745196
26+
// get the index of nth char in string
27+
function nth_occurrence (string, char, nth) {
28+
var first_index = string.indexOf(char)
29+
var length_up_to_first_index = first_index + 1
30+
if (nth === 1) {
31+
return first_index;
32+
} else {
33+
var string_after_first_occurrence = string.slice(length_up_to_first_index);
34+
var next_occurrence = nth_occurrence(string_after_first_occurrence, char, nth - 1);
35+
if (next_occurrence === -1) {
36+
return -1;
37+
} else {
38+
return length_up_to_first_index + next_occurrence;
39+
}
40+
}
41+
}
42+
43+
if (title === 'OCLint Result') {
44+
const command = 'cat ios/sdk/oclint.log | grep -i "P[1|2]"'
45+
const child = shell.exec(command)
46+
if (child.stdout !== '') {
47+
fail(child.stdout)
48+
fail(title)
49+
}
50+
if (child.stderr !== '') {
51+
fail(child.stderr)
52+
fail(title)
53+
}
54+
}
55+
else if (title === 'AndroidLint Result') {
56+
var content = fs.readFileSync('android/sdk/build/reports/lint-results.html', 'utf8')
57+
// in xml report,Overview Section,Disabled Checks Section and Suppressing Warnings and Errors Section is not reported.
58+
// in html report, those Section are included,
59+
// but Overview Section can't work in markdown,
60+
// on the other hand,Disabled Checks Section and Suppressing Warnings and Errors Section are not needed.
61+
// the first section is Overview section,
62+
// the last two section are Disabled Checks Section and Suppressing Warnings and Errors Section.
63+
// so we should grep the str from the second <section to the third </section> from last"
64+
const occurance = content.split('</section>').length - 1
65+
if (occurance > 3) {
66+
content = content.substr(nth_occurrence(content, '<section ', 2))
67+
content = content.substr(0, nth_occurrence(content, '</section>', occurance - 3))
68+
fail(content)
69+
fail(title)
70+
}
71+
}

Diff for: dangerfile-static-check.js

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { danger } from "danger";
21+
import fs from "fs";
22+
import path from 'path';
23+
import GitHubApi from 'github';
24+
import parseDiff from 'parse-diff';
25+
import shell from "shelljs";
26+
27+
const type_unknown = 0;
28+
const type_c = 1;
29+
const type_android = 2;
30+
31+
const getFileType = file => {
32+
if (file.match(/.+\.(m|h|mm|cpp|cc)/)) {
33+
return type_c;
34+
} else if (file.match(/android/)) {
35+
return type_android;
36+
} else {
37+
return type_unknown;
38+
}
39+
}
40+
41+
var hasCFile = false;
42+
var hasAndroidFile = false;
43+
44+
function check(file_type) {
45+
var has_file_type = false;
46+
if (!has_file_type && danger.git.created_files) {
47+
danger.git.created_files.some(file => {
48+
var f = (getFileType(file) == file_type)
49+
if (f) {
50+
has_file_type = f;
51+
}
52+
return f;
53+
});
54+
}
55+
56+
if (!has_file_type && danger.git.modified_files) {
57+
danger.git.modified_files.some(file => {
58+
var f = (getFileType(file) == file_type)
59+
if (f) {
60+
has_file_type = f;
61+
}
62+
return f;
63+
});
64+
}
65+
66+
if (!has_file_type && danger.git.deleted_files) {
67+
danger.git.deleted_files.some(file => {
68+
var f = (getFileType(file) == file_type)
69+
if (f) {
70+
has_file_type = f;
71+
}
72+
return f;
73+
});
74+
}
75+
76+
return has_file_type
77+
}
78+
79+
hasCFile = check(type_c)
80+
hasAndroidFile = check(type_android)
81+
82+
var output_str = ""
83+
if (hasCFile) {
84+
output_str += 'hasCFile\n'
85+
}
86+
if (hasAndroidFile) {
87+
output_str += 'hasAndroidFile\n'
88+
}
89+
console.log(output_str)

Diff for: ios/sdk/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*compile_commands.json

Diff for: ios/sdk/WeexSDK/Sources/Utility/WXVersion.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#import "WXVersion.h"
2121
#import "WXDefine.h"
2222

23-
static const char* WeexSDKBuildTime = "2019-07-16 07:08:34 UTC";
24-
static const unsigned long WeexSDKBuildTimestamp = 1563260914;
23+
static const char* WeexSDKBuildTime = "2019-07-21 09:08:41 UTC";
24+
static const unsigned long WeexSDKBuildTimestamp = 1563700121;
2525

2626
NSString* GetWeexSDKVersion(void)
2727
{

0 commit comments

Comments
 (0)