Skip to content

Commit 30124d7

Browse files
authored
ci: Enable travis build result comment in pull request (#59)
* travis: when pull requests, send the wrong result as a comment to github (#54) * travis: get the result of the make linkcheck and then change it's format Signed-off-by: Jingru Wang <[email protected]> * travis: change the comment header Signed-off-by: Jingru Wang <[email protected]> * travis: when use cur_core,specify it in job(gitlab) Signed-off-by: Jingru Wang <[email protected]> * travis: add job name when send comment (#56) * travis: add job name when send comment Signed-off-by: Jingru Wang <[email protected]> * travis: trigger a build Signed-off-by: Jingru <[email protected]> * travis: use html element pre to ensure line breaks Signed-off-by: Jingru <[email protected]>
1 parent 73a2623 commit 30124d7

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

.ci/before_install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ fi
2929
pip install PrettyTable || die
3030
pip install colorama || die
3131
pip install configparser || die
32+
pip install requests || die
3233
}

.ci/build.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import os
44
import sys
5+
import requests
56
from prettytable import PrettyTable
67
from colorama import Fore, Back, Style
78
from configparser import ConfigParser
@@ -374,14 +375,32 @@ def get_expected_result(expected_file, app_path, board, bd_ver):
374375
return result
375376

376377

378+
def send_pull_request_comment(columns, results):
379+
job = os.environ.get("NAME")
380+
comment_job = "## " + job + "\n"
381+
if len(results)>0:
382+
head = "|".join(columns) + "\n"
383+
table_format = "|".join(["---"]*len(columns)) + "\n"
384+
table_head =head +table_format
385+
comments = ""
386+
comment = ""
387+
for result in results:
388+
for k in result:
389+
comment += (k.replace(Fore.RED, "")).replace("\n", "<br>") +" |"
390+
comment = comment.rstrip("|") + "\n"
391+
comments += comment
392+
comment_on_pull_request(comment_job + table_head + comments)
393+
394+
377395
def show_results(results, expected=None):
378-
columns = ['TOOLCHAIN', 'APP', "TOOLCHAIN_VER", 'CONF', 'PASS']
396+
columns = ["TOOLCHAIN_VER", 'TOOLCHAIN', 'APP', 'CONF', 'PASS']
379397
failed_pt = PrettyTable(columns)
380398
failed_results = []
381399
success_results = []
382400
expected_results = None
383401
success_pt = PrettyTable(columns)
384402
expected_pt = PrettyTable(columns)
403+
385404
for result in results:
386405
status = result.pop("status")
387406
if status != 0:
@@ -398,6 +417,7 @@ def show_results(results, expected=None):
398417

399418
if expected is not None:
400419
expected_results = failed_results
420+
send_pull_request_comment(columns, expected_results)
401421
for result in expected_results:
402422
if len(result) > 0:
403423
expected_pt.add_row(result)
@@ -413,6 +433,8 @@ def show_results(results, expected=None):
413433
success_pt.add_row(result)
414434
print Fore.GREEN + "Successfull results"
415435
print success_pt
436+
437+
416438
print Style.RESET_ALL
417439
sys.stdout.flush()
418440

@@ -427,6 +449,7 @@ def show_results(results, expected=None):
427449

428450
print Fore.RED + "Failed result:"
429451
print failed_pt
452+
430453
print Style.RESET_ALL
431454
sys.stdout.flush()
432455

@@ -529,14 +552,26 @@ def build_makefiles_project(config):
529552
diff_expected_differents[app_path] = copy.deepcopy(expected_different[app_path])
530553

531554
print "There are {} projects, and they are compiled for {} times".format(app_count, count)
532-
results_list = build_result_combine_tail(apps_results)
555+
results_list = copy.deepcopy(build_result_combine_tail(apps_results))
533556
show_results(results_list)
534557
expected_differents_list = build_result_combine_tail(diff_expected_differents)
535558
show_results(expected_differents_list, expected=True)
536559

537560
return applications_failed, diff_expected_differents
538561

539562

563+
def comment_on_pull_request(comment):
564+
pr_number = os.environ.get("TRAVIS_PULL_REQUEST")
565+
slug = os.environ.get("TRAVIS_REPO_SLUG")
566+
token = os.environ.get("GH_TOKEN")
567+
if all([pr_number, slug, token, comment]):
568+
url = 'https://api.github.com/repos/{slug}/issues/{number}/comments'.format(
569+
slug=slug, number=pr_number)
570+
response = requests.post(url, data=json.dumps({'body': comment}),
571+
headers={'Authorization': 'token ' + token})
572+
return response.json()
573+
574+
540575
def get_options_parser():
541576
configs = dict()
542577
toolchainlist = ["gnu", "mw"]
@@ -590,4 +625,6 @@ def get_options_parser():
590625
else:
591626
print "these applications failed with some configuration: "
592627
print expected_differents.keys()
628+
comment = "applications failed with some configuration: \n" + "\n".join(expected_differents.keys())
629+
comment_on_pull_request(comment)
593630
sys.exit(1)

.ci/deploy_doc.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ make html &> build_html.log || { tail -n 100 build_html.log ; die "Build sphinx
2525
# Check if this is a pull request
2626
if [ "$TRAVIS_PULL_REQUEST" != "false" ] ; then
2727
echo "Don't push built docs to gh-pages for pull request "
28+
29+
make linkcheck -k 2>&1
30+
COMMENT_CONTENT=$(sed 's/$/&<br>/g' build/linkcheck/output.txt)
31+
COMMENT_HEAD="# Sphinx link check result \n***********************\n<pre>"
32+
COMMENT_TAIL="</pre>"
33+
COMMENT="${COMMENT_HEAD}${COMMENT_CONTENT}${COMMENT_TAIL}"
34+
bash -c "$COMMENTS"
2835
exit 0
2936
fi
3037

.gitlab-ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ variables:
44
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache"
55
OSP_ROOT: "."
66
TOOLCHAIN: "gnu"
7-
CUR_CORE: "none"
87
TOOLCHAIN_VER: "2017.09"
98
EXPECTED: ".ci/expected.ini"
109
PARALLEL: ""

.travis.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ env:
1515
"context": "travis-ci/$NAME",
1616
"target_url": "https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID"
1717
}\nDATA'
18+
19+
COMMENT=none
20+
COMMENTS=$'curl -so/dev/null --user "$EMBARC_BOT" --request POST
21+
https://api.github.com/repos/$TRAVIS_REPO_SLUG/issues/$TRAVIS_PULL_REQUEST/comments
22+
--data @- << DATA\n{
23+
"body": "$COMMENT"
24+
}\nDATA'
1825
1926
cache:
2027
pip: true
@@ -28,7 +35,7 @@ branches:
2835

2936
before_install:
3037
- bash .ci/before_install.sh
31-
# setup git config
38+
# setup git config
3239
- git config --global user.name "embARC Automated Bot"
3340
- git config --global user.email "[email protected]"
3441

0 commit comments

Comments
 (0)