From 4d2292d8f307f15d6b343be71fb30cc298540bfc Mon Sep 17 00:00:00 2001 From: Tran Minh Duc Date: Fri, 4 Sep 2020 08:19:01 +0000 Subject: [PATCH 1/6] package change --- package-lock.json | 29 +++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 30 insertions(+) diff --git a/package-lock.json b/package-lock.json index b66e44aaa..d05b4eaea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2301,6 +2301,11 @@ "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", "dev": true }, + "array-uniq": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.2.tgz", + "integrity": "sha1-X8w3OSB3VyPP1k1lxkvvU7+eum0=" + }, "asn1": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", @@ -3280,6 +3285,11 @@ "type-detect": "^4.0.0" } }, + "deep-extend": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", + "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==" + }, "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", @@ -7213,6 +7223,17 @@ "http-https": "^1.0.0" } }, + "octonode": { + "version": "0.9.5", + "resolved": "https://registry.npmjs.org/octonode/-/octonode-0.9.5.tgz", + "integrity": "sha512-l+aX9jNVkaagh7u/q2QpNKdL8XUagdztl+ebXxBRU6FJ1tpRxAH/ygIuWh0h7eS491BsyH6bb0QZIQEC2+u5oA==", + "requires": { + "bluebird": "^3.5.0", + "deep-extend": "^0.6.0", + "randomstring": "^1.1.5", + "request": "^2.72.0" + } + }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", @@ -7692,6 +7713,14 @@ "integrity": "sha1-us7vmCMpCRQA8qKRLGzQLxCU9YU=", "dev": true }, + "randomstring": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/randomstring/-/randomstring-1.1.5.tgz", + "integrity": "sha1-bfBij3XL1ZMpMNn+OrTpVqGFGMM=", + "requires": { + "array-uniq": "1.0.2" + } + }, "range-parser": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", diff --git a/package.json b/package.json index c9a0fdd75..9ca10f997 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "ethers": "5.0.4", "ganache-cli": "6.8.2", "mathjs": "4.4.2", + "octonode": "^0.9.5", "rlp": "2.2.4", "secp256k1": "3.8.0", "sha3": "2.1.1", From 535bf55c26167383ed12468f7191aff0da37c2ed Mon Sep 17 00:00:00 2001 From: Tran Minh Duc Date: Sat, 5 Sep 2020 07:09:34 +0000 Subject: [PATCH 2/6] add report on github comment --- .travis.yml | 2 ++ .travis/remove-all-bot-comment.js | 29 +++++++++++++++++++++++++++++ .travis/report.sh | 19 +++++++++++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 .travis/remove-all-bot-comment.js diff --git a/.travis.yml b/.travis.yml index 398cc51e5..bbd86af57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,8 @@ before_script: script: - ./cmp.sh - .travis/test-part.sh + +after_success: - .travis/report.sh deploy: diff --git a/.travis/remove-all-bot-comment.js b/.travis/remove-all-bot-comment.js new file mode 100644 index 000000000..e30a91d24 --- /dev/null +++ b/.travis/remove-all-bot-comment.js @@ -0,0 +1,29 @@ +let github = require('octonode'); + +var client = github.client(process.env.GITHUB_TOKEN); + +async function getBotInfo() { + let ghme = client.me(); + const result = await ghme.infoAsync(); + return result[0]; +} + +var ghpr = client.issue(process.env.TRAVIS_REPO_SLUG, process.env.TRAVIS_PULL_REQUEST); + +async function removeBotComments(bot) { + let result = await ghpr.commentsAsync(); + let comments = result[0]; + for (let i = 0; i < comments.length; i++) { + comment = comments[i]; + if (bot == comment.user.login) { + await ghpr.deleteCommentAsync(comment.id); + } + } +} + +async function main() { + let botInfo = await getBotInfo(); + await removeBotComments(botInfo.login); +} + +main(); diff --git a/.travis/report.sh b/.travis/report.sh index d9d1a5974..f345fc165 100755 --- a/.travis/report.sh +++ b/.travis/report.sh @@ -1,4 +1,19 @@ #!/bin/bash -node contractSizeReport.js $TRAVIS_PULL_REQUEST_BRANCH -node gasUsedReport.js $TRAVIS_PULL_REQUEST_BRANCH +readonly test_part=${TEST_PART:-} +case "$test_part" in +All) + if [[ $TRAVIS_PULL_REQUEST ]]; then + sizeReport = `node contractSizeReport.js $TRAVIS_PULL_REQUEST_BRANCH` + gasReport = `node gasUsedReport.js $TRAVIS_PULL_REQUEST_BRANCH` + node travis/remove-all-bot-comment.js + curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST \ + -d "{\"body\": \"$sizeReport\"}" \ + "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/${TRAVIS_PULL_REQUEST}/comments" + + curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST \ + -d "{\"body\": \"$gasReport\"}" \ + "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/${TRAVIS_PULL_REQUEST}/comments" + fi + ;; +esac \ No newline at end of file From bb7fe9ee78045ab9c11bf2bf1fd7f222780a2839 Mon Sep 17 00:00:00 2001 From: Tran Minh Duc Date: Sat, 5 Sep 2020 07:38:31 +0000 Subject: [PATCH 3/6] fix push report to awx --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bbd86af57..d589cf2cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,7 +45,7 @@ deploy: skip_cleanup: true on: all_branches: true - condition: $TEST_PART = Sol6 + condition: $TEST_PART = All - provider: s3 access_key_id: $AWS_ACCESS_KEY_ID secret_access_key: $AWS_SECRET_ACCESS_KEY From 34dcc817cb0ff1424ec2af83454c8ee535cb3141 Mon Sep 17 00:00:00 2001 From: Tran Minh Duc Date: Sat, 5 Sep 2020 07:43:51 +0000 Subject: [PATCH 4/6] typo, add whitespace at eof --- .travis/report.sh | 2 +- contractSizeReport.js | 4 ++-- gasUsedReport.js | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis/report.sh b/.travis/report.sh index f345fc165..ce945c47a 100755 --- a/.travis/report.sh +++ b/.travis/report.sh @@ -16,4 +16,4 @@ All) "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/${TRAVIS_PULL_REQUEST}/comments" fi ;; -esac \ No newline at end of file +esac diff --git a/contractSizeReport.js b/contractSizeReport.js index 668b61a98..a6ff856de 100644 --- a/contractSizeReport.js +++ b/contractSizeReport.js @@ -37,7 +37,7 @@ async function writeReport(report) { } fs.writeFile(reportFile, jsonContent, 'utf8', function (err) { if (err) { - console.log('An error occured while writing JSON Object to File.'); + console.log('An error occurred while writing JSON Object to File.'); return console.log(err); } }); @@ -59,7 +59,7 @@ async function compareContractSize() { let remoteReport = await getRemoteReport(); if (!remoteReport) { console.log(`Could not get report for ${argv.branch}`); - console.log("Current contract size report"); + console.log('Current contract size report'); console.table(contractSizeReport); return false; } diff --git a/gasUsedReport.js b/gasUsedReport.js index e5cd5ac85..f41ab2f74 100644 --- a/gasUsedReport.js +++ b/gasUsedReport.js @@ -22,10 +22,10 @@ async function getLocalReport() { reportFile = `report/${process.env.TRAVIS_BRANCH}/gasUsed.json`; } let report = JSON.parse(fs.readFileSync(reportFile, 'utf8')); - return report + return report; } -async function compareGasConsumtion() { +async function compareGasConsumption() { let localReport = await getLocalReport(); let remoteReport = await getRemoteReport(); if (!remoteReport) { @@ -71,4 +71,4 @@ async function compareGasConsumtion() { } } -compareGasConsumtion(); +compareGasConsumption(); From 5bb04014c765e640d4da0c997075066f48b0dcd1 Mon Sep 17 00:00:00 2001 From: Tran Minh Duc Date: Sat, 5 Sep 2020 20:18:42 +0000 Subject: [PATCH 5/6] fix empty body --- .travis/report.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis/report.sh b/.travis/report.sh index ce945c47a..dca2cc0e5 100755 --- a/.travis/report.sh +++ b/.travis/report.sh @@ -4,15 +4,15 @@ readonly test_part=${TEST_PART:-} case "$test_part" in All) if [[ $TRAVIS_PULL_REQUEST ]]; then - sizeReport = `node contractSizeReport.js $TRAVIS_PULL_REQUEST_BRANCH` - gasReport = `node gasUsedReport.js $TRAVIS_PULL_REQUEST_BRANCH` + export sizeReport=$(node contractSizeReport.js $TRAVIS_PULL_REQUEST_BRANCH) + export gasReport=$(node gasUsedReport.js $TRAVIS_PULL_REQUEST_BRANCH) node travis/remove-all-bot-comment.js curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST \ - -d "{\"body\": \"$sizeReport\"}" \ + -d "{\"body\": \""$sizeReport"\"}" \ "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/${TRAVIS_PULL_REQUEST}/comments" curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST \ - -d "{\"body\": \"$gasReport\"}" \ + -d "{\"body\": \""$gasReport"\"}" \ "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/${TRAVIS_PULL_REQUEST}/comments" fi ;; From 995f4f9dace569cc2c6f787677d03ddbf9f8bfb7 Mon Sep 17 00:00:00 2001 From: Tran Minh Duc Date: Mon, 7 Sep 2020 07:18:01 +0000 Subject: [PATCH 6/6] fix multiple line --- .travis/report.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis/report.sh b/.travis/report.sh index dca2cc0e5..45ddf601a 100755 --- a/.travis/report.sh +++ b/.travis/report.sh @@ -8,11 +8,11 @@ All) export gasReport=$(node gasUsedReport.js $TRAVIS_PULL_REQUEST_BRANCH) node travis/remove-all-bot-comment.js curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST \ - -d "{\"body\": \""$sizeReport"\"}" \ + -d "{\"body\": \"$sizeReport\"}" \ "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/${TRAVIS_PULL_REQUEST}/comments" curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST \ - -d "{\"body\": \""$gasReport"\"}" \ + -d "{\"body\": \"$gasReport\"}" \ "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/${TRAVIS_PULL_REQUEST}/comments" fi ;;