This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Travis] Add Lint in TravisCI and Update iOS TravisCI (#2731)
Add the following tasks: * Android Lint * OCLint
- Loading branch information
1 parent
0135e3c
commit 3bfb619
Showing
9 changed files
with
276 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { fail, warn } from 'danger' | ||
const shell = require('shelljs') | ||
const title = process.env.TITLE | ||
const fs = require('fs') | ||
|
||
// code come from: https://stackoverflow.com/a/12745196 | ||
// get the index of nth char in string | ||
function nth_occurrence (string, char, nth) { | ||
var first_index = string.indexOf(char) | ||
var length_up_to_first_index = first_index + 1 | ||
if (nth === 1) { | ||
return first_index; | ||
} else { | ||
var string_after_first_occurrence = string.slice(length_up_to_first_index); | ||
var next_occurrence = nth_occurrence(string_after_first_occurrence, char, nth - 1); | ||
if (next_occurrence === -1) { | ||
return -1; | ||
} else { | ||
return length_up_to_first_index + next_occurrence; | ||
} | ||
} | ||
} | ||
|
||
if (title === 'OCLint Result') { | ||
const command = 'cat ios/sdk/oclint.log | grep -i "P[1|2]"' | ||
const child = shell.exec(command) | ||
if (child.stdout !== '') { | ||
fail(child.stdout) | ||
fail(title) | ||
} | ||
if (child.stderr !== '') { | ||
fail(child.stderr) | ||
fail(title) | ||
} | ||
} | ||
else if (title === 'AndroidLint Result') { | ||
var content = fs.readFileSync('android/sdk/build/reports/lint-results.html', 'utf8') | ||
// in xml report,Overview Section,Disabled Checks Section and Suppressing Warnings and Errors Section is not reported. | ||
// in html report, those Section are included, | ||
// but Overview Section can't work in markdown, | ||
// on the other hand,Disabled Checks Section and Suppressing Warnings and Errors Section are not needed. | ||
// the first section is Overview section, | ||
// the last two section are Disabled Checks Section and Suppressing Warnings and Errors Section. | ||
// so we should grep the str from the second <section to the third </section> from last" | ||
const occurance = content.split('</section>').length - 1 | ||
if (occurance > 3) { | ||
content = content.substr(nth_occurrence(content, '<section ', 2)) | ||
content = content.substr(0, nth_occurrence(content, '</section>', occurance - 3)) | ||
fail(content) | ||
fail(title) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { danger } from "danger"; | ||
import fs from "fs"; | ||
import path from 'path'; | ||
import GitHubApi from 'github'; | ||
import parseDiff from 'parse-diff'; | ||
import shell from "shelljs"; | ||
|
||
const type_unknown = 0; | ||
const type_c = 1; | ||
const type_android = 2; | ||
|
||
const getFileType = file => { | ||
if (file.match(/.+\.(m|h|mm|cpp|cc)/)) { | ||
return type_c; | ||
} else if (file.match(/android/)) { | ||
return type_android; | ||
} else { | ||
return type_unknown; | ||
} | ||
} | ||
|
||
var hasCFile = false; | ||
var hasAndroidFile = false; | ||
|
||
function check(file_type) { | ||
var has_file_type = false; | ||
if (!has_file_type && danger.git.created_files) { | ||
danger.git.created_files.some(file => { | ||
var f = (getFileType(file) == file_type) | ||
if (f) { | ||
has_file_type = f; | ||
} | ||
return f; | ||
}); | ||
} | ||
|
||
if (!has_file_type && danger.git.modified_files) { | ||
danger.git.modified_files.some(file => { | ||
var f = (getFileType(file) == file_type) | ||
if (f) { | ||
has_file_type = f; | ||
} | ||
return f; | ||
}); | ||
} | ||
|
||
if (!has_file_type && danger.git.deleted_files) { | ||
danger.git.deleted_files.some(file => { | ||
var f = (getFileType(file) == file_type) | ||
if (f) { | ||
has_file_type = f; | ||
} | ||
return f; | ||
}); | ||
} | ||
|
||
return has_file_type | ||
} | ||
|
||
hasCFile = check(type_c) | ||
hasAndroidFile = check(type_android) | ||
|
||
var output_str = "" | ||
if (hasCFile) { | ||
output_str += 'hasCFile\n' | ||
} | ||
if (hasAndroidFile) { | ||
output_str += 'hasAndroidFile\n' | ||
} | ||
console.log(output_str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*compile_commands.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.