From 7bae018249d1c778968d341c8f8338d4d9bc03d3 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Wed, 9 Jan 2019 15:10:58 -0800 Subject: [PATCH 1/8] chore: adding encrypted bolt bot app private key --- .travis.yml | 1 + .../bolt-design-system-bot.private-key.pem.enc | Bin 0 -> 1680 bytes 2 files changed, 1 insertion(+) create mode 100644 scripts/bolt-design-system-bot.private-key.pem.enc diff --git a/.travis.yml b/.travis.yml index 78d31e36c8..829a93f6ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -69,6 +69,7 @@ jobs: - www/pattern-lab/index.html before_install: + - openssl aes-256-cbc -K $encrypted_4537e53f71e7_key -iv $encrypted_4537e53f71e7_iv -in scripts/bolt-design-system-bot.private-key.pem.enc -out scripts -d && ls && ls scripts - nvm install # version lifted from `.nvmrc` - curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.9.4 - export PATH="$HOME/.yarn/bin:$PATH" diff --git a/scripts/bolt-design-system-bot.private-key.pem.enc b/scripts/bolt-design-system-bot.private-key.pem.enc new file mode 100644 index 0000000000000000000000000000000000000000..2049f9848b7ae6e0d442da8f8b6db044257c2056 GIT binary patch literal 1680 zcmV;B25g-YiMXVDcQ@u}XooJj7>cg4c$tX2Dk);j`sAs!N zm*iFykj!Bawr6b7`uW(Nx;{t_v-Tf`6n_OT@m90OS{3=u6dDhPd{r^4o z3LVEyGr~g8h2+1&bDN+3_+}rGVdA2M-9vl!dpxa5S4E630laKo2SPmjRj z*L^SIwH3FpGtyN55tbKMUzV%ja!>2Ebq+r-$HZP0Ptip?WLY)yK4kD{4zm6V38uv_ zxg{eIYhZ;rR#eFn8X$hVAMQ=Kf&8+VMLEqU;F6^o0?w24t`dX%HUlU_I`@Reg6Q#Q zl{N9KZ^lpX7nk~rJ+W|I4{5GEAZm5!q4clGrHA^OZ4Y>~&{GHI1G*2u3`>CV{a-8o z2e#Xz`lr7*PDeVPn5X4t5!P3Ifh?oiLK_(!93Q$Sj3H3FkjuX-a~lf#NB7q4`BAbh z*ra`HbVCXllZA%V%SvS?9H>lS6r2(sQL&{_=RA_It)wI{u&rGvTu7yH+gD=wQC`-aCB4{dNMrWB3UqxP z^8?ED@$f0h!)JB99)Ba)pSf?|ZewO(?{1xFr+UyE^!~L9s(&SBRpI-XBjEa1x$C?tX_B#+PQ2Ddy}Q~$I%V>%W~mBZM-ozZ6gM`lgg%-iKuPE%qqA*Q z#ZP+|QED<7O4heT+aR41{qKUS=b`GLTv9CxCa)6e4p%!ofk4w%4XTmEI;k16`iu6> z508(g9;ktgxNGu54EkB`ZVxH`y9+WTiic+o%8~hFZ;GC`egSUq=Fd8|rUCd`w$j~@ z89vK~TKZjx^admfBN8mGKtp9@s$R}#fAzSO_Zjk^s5`#0SBl}^BZz}>iPfVMyH|bS zfFGyJ?;aOhfxb;7(%#T6LxuXZauoLhM2a;CmC08Gg}PElgqp|IeAnV3xw)UM_Yuuq zg&-RGKDm0xJ>v-AwM|E3ab1u5rEvpQh8x+Q)AbFVZn9i#5N1jjof>f&j4)UG(aZmwZGriqq_Y8gBG2+%M& ztH$BIj>#znUjZHq1K$y-!b1Qj*aZGw2wi7bjA>#2uvl$l^>xs*7(4zT!Qh zgVylJOiFr4;|toc3K9D zrYUbX0dp_3B-nOW83V4@w)=G~YvP42?pr%tny}Zuf-BBSpXquJ92(b1xsR~xM=knb zWt5(*h}bZvaRpexRIiFuIT_ZCP0IN922#Oab`L64|UFwc0H5ri6y()iQ~&% z8{2I<-!E{Ov(7S6_TfyoQ8ngy$2KY82^cBnANN-|8(j}t?bB|h-}?$H5z`PqM66JL z7D%{Gsu1cE4{}X^Ju^P!iw}Q3%kBa`b=t-Dkjv2`0mjlwkdg<}URxVbFz4qOPT$sG zn6!k1?9Qo}u&3@kVEu$G6LHgp8sAa_6S~m+v_yVk9n2KP*9p%?gkjk;(ELC>IEfms zE)FowIR;do(?LAMDxb*Eb!Tc|O5Z3Tx(A-K^y2bTETu;4al3-Ga_P0T-w>(^8Oyg2 ayAc@hQc;O8<}$Xn(4C3SrR&yW_=HC} Date: Wed, 9 Jan 2019 15:15:20 -0800 Subject: [PATCH 2/8] chore: travis tweak --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 829a93f6ae..79f911005d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -69,7 +69,7 @@ jobs: - www/pattern-lab/index.html before_install: - - openssl aes-256-cbc -K $encrypted_4537e53f71e7_key -iv $encrypted_4537e53f71e7_iv -in scripts/bolt-design-system-bot.private-key.pem.enc -out scripts -d && ls && ls scripts + - openssl aes-256-cbc -K $encrypted_4537e53f71e7_key -iv $encrypted_4537e53f71e7_iv -in scripts/bolt-design-system-bot.private-key.pem.enc -out scripts/bolt-design-system-bot.private-key.pem -d && ls && ls scripts - nvm install # version lifted from `.nvmrc` - curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.9.4 - export PATH="$HOME/.yarn/bin:$PATH" From d690c443876d0055f6c5383569c46d14bbfa8ca6 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Wed, 9 Jan 2019 15:50:42 -0800 Subject: [PATCH 3/8] chore: try out check run --- .travis.yml | 3 +- package.json | 7 +-- scripts/check-run.js | 87 +++++++++++++++++++++++++++++++++ scripts/sample-check-run-use.js | 37 ++++++++++++++ yarn.lock | 79 ++++++++++++++++++++++++++++++ 5 files changed, 209 insertions(+), 4 deletions(-) create mode 100644 scripts/check-run.js create mode 100644 scripts/sample-check-run-use.js diff --git a/.travis.yml b/.travis.yml index 79f911005d..d12d8373df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,7 @@ jobs: - phpenv config-rm xdebug.ini - composer global require hirak/prestissimo - yarn run setup:quick + - node scripts/sample-check-run-use.js script: yarn run test cache: yarn: true @@ -69,7 +70,7 @@ jobs: - www/pattern-lab/index.html before_install: - - openssl aes-256-cbc -K $encrypted_4537e53f71e7_key -iv $encrypted_4537e53f71e7_iv -in scripts/bolt-design-system-bot.private-key.pem.enc -out scripts/bolt-design-system-bot.private-key.pem -d && ls && ls scripts + - openssl aes-256-cbc -K $encrypted_4537e53f71e7_key -iv $encrypted_4537e53f71e7_iv -in scripts/bolt-design-system-bot.private-key.pem.enc -out scripts/bolt-design-system-bot.private-key.pem -d - nvm install # version lifted from `.nvmrc` - curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.9.4 - export PATH="$HOME/.yarn/bin:$PATH" diff --git a/package.json b/package.json index cfe23cd0ad..960c5fb352 100644 --- a/package.json +++ b/package.json @@ -45,10 +45,11 @@ }, "dependencies": { "ci-utils": "^0.5.0", - "sassdoc": "^2.5.0", - "npm-run-all": "^4.1.5", "jest": "^23.6.0", - "jest-serializer-html": "^5.0.0" + "jest-serializer-html": "^5.0.0", + "jsonwebtoken": "^8.4.0", + "npm-run-all": "^4.1.5", + "sassdoc": "^2.5.0" }, "husky": { "hooks": { diff --git a/scripts/check-run.js b/scripts/check-run.js new file mode 100644 index 0000000000..cf65dbdaf8 --- /dev/null +++ b/scripts/check-run.js @@ -0,0 +1,87 @@ +const jwt = require('jsonwebtoken'); +const fs = require('fs'); +const { join } = require('path'); +const fetch = require('node-fetch'); +const { getGitSha } = require('ci-utils'); + +const installationId = '572023'; +const repoSlug = 'boltdesignsystem/bolt'; +const privateKey = fs.readFileSync( + join(__dirname, './bolt-design-system-bot.private-key.pem'), + 'utf8', +); + +if (!privateKey) { + console.error('Could not find private key PEM file'); + process.exit(1); +} + +const jwtToken = jwt.sign( + { + iss: installationId, + }, + privateKey, + { + algorithm: 'RS256', + expiresIn: '10m', + }, +); + +const getHeaders = token => ({ + 'Content-Type': 'application/json', + Accept: + 'application/vnd.github.antiope-preview+json, application/vnd.github.machine-man-preview+json, application/vnd.github.v3+json', + Authorization: `Bearer ${token}`, +}); + +/** + * @return {Promise<{token: string, expires_at: string}>} + */ +async function getAccessToken() { + try { + return fetch( + `https://api.github.com/app/installations/${installationId}/access_tokens`, + { + method: 'POST', + headers: { + ...getHeaders(jwtToken), + }, + }, + ).then(res => res.json()); + } catch (err) { + console.error('error getting access token ', err); + process.exit(1); + } +} + +/** + * @param name + * @param status + * @param output + * @return {Promise} + * @link https://developer.github.com/v3/checks/runs/#create-a-check-run + */ +async function createCheckRun({ name, status, output }) { + try { + const token = await getAccessToken(); + return fetch(`https://api.github.com/repos/${repoSlug}/check-runs`, { + method: 'POST', + headers: { + ...getHeaders(token), + }, + body: JSON.stringify({ + name, + status, + output, + head_sha: getGitSha(), + }), + }).then(res => res.json()); + } catch (err) { + console.error('error setting check run ' + name + ' to ' + status, err); + process.exit(1); + } +} + +module.exports = { + createCheckRun, +}; diff --git a/scripts/sample-check-run-use.js b/scripts/sample-check-run-use.js new file mode 100644 index 0000000000..4361c62d46 --- /dev/null +++ b/scripts/sample-check-run-use.js @@ -0,0 +1,37 @@ +#!/usr/bin/env node +const { outputBanner } = require('ci-utils'); +const { createCheckRun } = require('./check-run'); + +outputBanner('Sending sample check run!'); + +createCheckRun({ + name: 'ima tester', + status: 'in_progress', + output: { + title: 'ima output title', + summary: 'ima output summary', + text: 'ima output text *with* markdown!!', + images: [ + { + alt: 'img 1', + image_url: + 'https://design.basalt.io/images/brand-stock/julentto-photography-184055.jpg', + caption: 'ima caption for img 1', + }, + { + alt: 'img 2', + image_url: + 'https://design.basalt.io/images/brand-stock/clarisse-meyer-304306.jpg', + caption: 'ima caption for img 2', + }, + ], + }, +}) + .then(results => { + outputBanner('Sample check run received'); + console.log(results); + }) + .catch(error => { + console.error('check run error', error); + process.exit(1); + }); diff --git a/yarn.lock b/yarn.lock index 56b6627739..d3ab1d40ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2943,6 +2943,11 @@ buffer-alloc@^1.2.0: buffer-alloc-unsafe "^1.1.0" buffer-fill "^1.0.0" +buffer-equal-constant-time@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819" + integrity sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk= + buffer-fill@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/buffer-fill/-/buffer-fill-1.0.0.tgz#f8f78b76789888ef39f205cd637f68e702122b2c" @@ -5044,6 +5049,13 @@ ecc-jsbn@~0.1.1: jsbn "~0.1.0" safer-buffer "^2.1.0" +ecdsa-sig-formatter@1.0.10: + version "1.0.10" + resolved "https://registry.yarnpkg.com/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.10.tgz#1c595000f04a8897dfb85000892a0f4c33af86c3" + integrity sha1-HFlQAPBKiJffuFAAiSoPTDOvhsM= + dependencies: + safe-buffer "^5.0.1" + editorconfig-checker@^1.3.3: version "1.3.3" resolved "https://registry.yarnpkg.com/editorconfig-checker/-/editorconfig-checker-1.3.3.tgz#282aa44d3f3abc5228078593733a039250a1ee1d" @@ -8781,6 +8793,21 @@ jsonschema@^1.2.4: resolved "https://registry.yarnpkg.com/jsonschema/-/jsonschema-1.2.4.tgz#a46bac5d3506a254465bc548876e267c6d0d6464" integrity sha512-lz1nOH69GbsVHeVgEdvyavc/33oymY1AZwtePMiMj4HZPMbP5OIKK3zT9INMWjwua/V4Z4yq7wSlBbSG+g4AEw== +jsonwebtoken@^8.4.0: + version "8.4.0" + resolved "https://registry.yarnpkg.com/jsonwebtoken/-/jsonwebtoken-8.4.0.tgz#8757f7b4cb7440d86d5e2f3becefa70536c8e46a" + integrity sha512-coyXjRTCy0pw5WYBpMvWOMN+Kjaik2MwTUIq9cna/W7NpO9E+iYbumZONAz3hcr+tXFJECoQVrtmIoC3Oz0gvg== + dependencies: + jws "^3.1.5" + lodash.includes "^4.3.0" + lodash.isboolean "^3.0.3" + lodash.isinteger "^4.0.4" + lodash.isnumber "^3.0.3" + lodash.isplainobject "^4.0.6" + lodash.isstring "^4.0.1" + lodash.once "^4.0.0" + ms "^2.1.1" + jsprim@^1.2.2: version "1.4.1" resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2" @@ -8791,6 +8818,23 @@ jsprim@^1.2.2: json-schema "0.2.3" verror "1.10.0" +jwa@^1.1.5: + version "1.1.6" + resolved "https://registry.yarnpkg.com/jwa/-/jwa-1.1.6.tgz#87240e76c9808dbde18783cf2264ef4929ee50e6" + integrity sha512-tBO/cf++BUsJkYql/kBbJroKOgHWEigTKBAjjBEmrMGYd1QMBC74Hr4Wo2zCZw6ZrVhlJPvoMrkcOnlWR/DJfw== + dependencies: + buffer-equal-constant-time "1.0.1" + ecdsa-sig-formatter "1.0.10" + safe-buffer "^5.0.1" + +jws@^3.1.5: + version "3.1.5" + resolved "https://registry.yarnpkg.com/jws/-/jws-3.1.5.tgz#80d12d05b293d1e841e7cb8b4e69e561adcf834f" + integrity sha512-GsCSexFADNQUr8T5HPJvayTjvPIfoyJPtLQBwn5a4WZQchcrPMPMAWcC1AzJVRDKyD6ZPROPAxgv6rfHViO4uQ== + dependencies: + jwa "^1.1.5" + safe-buffer "^5.0.1" + keyv@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/keyv/-/keyv-3.1.0.tgz#ecc228486f69991e49e9476485a5be1e8fc5c4d9" @@ -9418,6 +9462,11 @@ lodash.identity@~2.4.1: resolved "https://registry.yarnpkg.com/lodash.identity/-/lodash.identity-2.4.1.tgz#6694cffa65fef931f7c31ce86c74597cf560f4f1" integrity sha1-ZpTP+mX++TH3wxzobHRZfPVg9PE= +lodash.includes@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/lodash.includes/-/lodash.includes-4.3.0.tgz#60bb98a87cb923c68ca1e51325483314849f553f" + integrity sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8= + lodash.isarguments@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" @@ -9428,6 +9477,11 @@ lodash.isarray@^3.0.0: resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55" integrity sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U= +lodash.isboolean@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz#6c2e171db2a257cd96802fd43b01b20d5f5870f6" + integrity sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY= + lodash.isequal@^4.0.0, lodash.isequal@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0" @@ -9443,6 +9497,16 @@ lodash.isfunction@~2.4.1: resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-2.4.1.tgz#2cfd575c73e498ab57e319b77fa02adef13a94d1" integrity sha1-LP1XXHPkmKtX4xm3f6Aq3vE6lNE= +lodash.isinteger@^4.0.4: + version "4.0.4" + resolved "https://registry.yarnpkg.com/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz#619c0af3d03f8b04c31f5882840b77b11cd68343" + integrity sha1-YZwK89A/iwTDH1iChAt3sRzWg0M= + +lodash.isnumber@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz#3ce76810c5928d03352301ac287317f11c0b1ffc" + integrity sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w= + lodash.isobject@~2.4.1: version "2.4.1" resolved "https://registry.yarnpkg.com/lodash.isobject/-/lodash.isobject-2.4.1.tgz#5a2e47fe69953f1ee631a7eba1fe64d2d06558f5" @@ -9450,6 +9514,16 @@ lodash.isobject@~2.4.1: dependencies: lodash._objecttypes "~2.4.1" +lodash.isplainobject@^4.0.6: + version "4.0.6" + resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" + integrity sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs= + +lodash.isstring@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451" + integrity sha1-1SfftUVuynzJu5XV2ur4i6VKVFE= + lodash.keys@^3.0.0: version "3.1.2" resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a" @@ -9488,6 +9562,11 @@ lodash.noop@~2.4.1: resolved "https://registry.yarnpkg.com/lodash.noop/-/lodash.noop-2.4.1.tgz#4fb54f816652e5ae10e8f72f717a388c7326538a" integrity sha1-T7VPgWZS5a4Q6PcvcXo4jHMmU4o= +lodash.once@^4.0.0: + version "4.1.1" + resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac" + integrity sha1-DdOXEhPHxW34gJd9UEyI+0cal6w= + lodash.pick@^4.4.0: version "4.4.0" resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3" From c1cd43a75cb621e181b6ad199f13e32bf75e1398 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Wed, 9 Jan 2019 17:34:57 -0800 Subject: [PATCH 4/8] ci: setup check suite instead of GitHub statuses --- .travis.yml | 2 +- scripts/check-run.js | 138 +++++++++++++++++++++++++------- scripts/create-check-suite.js | 10 +++ scripts/deploy.js | 51 +++++++++--- scripts/sample-check-run-use.js | 37 --------- 5 files changed, 160 insertions(+), 78 deletions(-) create mode 100644 scripts/create-check-suite.js delete mode 100644 scripts/sample-check-run-use.js diff --git a/.travis.yml b/.travis.yml index d12d8373df..5fbe1ca0c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ jobs: - phpenv config-rm xdebug.ini - composer global require hirak/prestissimo - yarn run setup:quick - - node scripts/sample-check-run-use.js + - node ./scripts/create-check-suite.js script: yarn run test cache: yarn: true diff --git a/scripts/check-run.js b/scripts/check-run.js index cf65dbdaf8..ceb7def819 100644 --- a/scripts/check-run.js +++ b/scripts/check-run.js @@ -5,7 +5,7 @@ const fetch = require('node-fetch'); const { getGitSha } = require('ci-utils'); const installationId = '572023'; -const repoSlug = 'boltdesignsystem/bolt'; +const repoSlug = 'bolt-design-system/bolt'; const privateKey = fs.readFileSync( join(__dirname, './bolt-design-system-bot.private-key.pem'), 'utf8', @@ -18,7 +18,7 @@ if (!privateKey) { const jwtToken = jwt.sign( { - iss: installationId, + iss: '23351', }, privateKey, { @@ -27,6 +27,16 @@ const jwtToken = jwt.sign( }, ); +let accessToken; + +/** + * Get Date in format GitHub wants + * @return {string} - current date like '2019-01-09T23:31:24.748Z' + */ +function getDate() { + return new Date().toISOString(); +} + const getHeaders = token => ({ 'Content-Type': 'application/json', Accept: @@ -35,53 +45,125 @@ const getHeaders = token => ({ }); /** - * @return {Promise<{token: string, expires_at: string}>} + * @return {Promise} */ async function getAccessToken() { - try { - return fetch( - `https://api.github.com/app/installations/${installationId}/access_tokens`, - { - method: 'POST', - headers: { - ...getHeaders(jwtToken), - }, + const response = await fetch( + `https://api.github.com/app/installations/${installationId}/access_tokens`, + { + method: 'POST', + headers: { + ...getHeaders(jwtToken), }, - ).then(res => res.json()); - } catch (err) { - console.error('error getting access token ', err); + }, + ).catch(err => { + console.error('error getting access token', err); process.exit(1); + }); + + const results = await response.json(); + if (!response.ok) { + console.log(results); + throw new Error( + `Error getting access token: ${response.status} ${response.statusText}. ${ + results.message + }`, + ); } + + accessToken = results.token; + return results.token; } /** - * @param name - * @param status - * @param output * @return {Promise} - * @link https://developer.github.com/v3/checks/runs/#create-a-check-run + * @link https://developer.github.com/v3/checks/suites/#create-a-check-suite */ -async function createCheckRun({ name, status, output }) { - try { - const token = await getAccessToken(); - return fetch(`https://api.github.com/repos/${repoSlug}/check-runs`, { +async function createCheckSuite() { + const token = accessToken || (await getAccessToken()); + const response = await fetch( + `https://api.github.com/repos/${repoSlug}/check-suites`, + { method: 'POST', headers: { ...getHeaders(token), }, body: JSON.stringify({ - name, - status, - output, head_sha: getGitSha(), }), - }).then(res => res.json()); - } catch (err) { + }, + ).catch(err => { + console.error('error creating check suite', err); + process.exit(1); + }); + + const results = await response.json(); + if (!response.ok) { + console.log(results); + throw new Error( + `Error creating check suite: ${response.status} ${response.statusText}. ${ + results.message + }`, + ); + } + + return results; +} + +/** + * @param opt + * @param opt.name + * @param opt.status + * @param opt.output + * @param [opt.conclusion] - The final conclusion of the check. Can be one of success, failure, neutral, cancelled, timed_out, or action_required. When the conclusion is action_required, additional details should be provided on the site specified by details_url. + * @return {Promise} + * @link https://developer.github.com/v3/checks/runs/#create-a-check-run + */ +async function setCheckRun({ name, status, output, conclusion }) { + const token = accessToken || (await getAccessToken()); + const body = { + name, + status, + output, + head_sha: getGitSha(), + }; + switch (status) { + case 'in_progress': + body.started_at = getDate(); + break; + case 'completed': + body.completed_at = getDate(); + body.conclusion = conclusion; + break; + } + const response = await fetch( + `https://api.github.com/repos/${repoSlug}/check-runs`, + { + method: 'POST', + headers: { + ...getHeaders(token), + }, + body: JSON.stringify(body), + }, + ).catch(err => { console.error('error setting check run ' + name + ' to ' + status, err); process.exit(1); + }); + + const results = await response.json(); + if (!response.ok) { + console.log(results); + throw new Error( + `Error creating check run: ${response.status} ${response.statusText}. ${ + results.message + }`, + ); } + + return results; } module.exports = { - createCheckRun, + createCheckSuite, + setCheckRun, }; diff --git a/scripts/create-check-suite.js b/scripts/create-check-suite.js new file mode 100644 index 0000000000..a6d724b4d0 --- /dev/null +++ b/scripts/create-check-suite.js @@ -0,0 +1,10 @@ +#!/usr/bin/env node +const { createCheckSuite } = require('./check-run'); + +createCheckSuite() + .then(results => { + console.log(`Check Suite Created ${results.id}`); + }) + .catch(() => { + process.exit(1); + }); diff --git a/scripts/deploy.js b/scripts/deploy.js index c340dd4708..7ceb1043db 100755 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -15,6 +15,7 @@ const { spawnSync } = require('child_process'); const { promisify } = require('util'); const gitSemverTags = require('git-semver-tags'); const promisifyGitTags = promisify(gitSemverTags); +const { setCheckRun } = require('./check-run'); async function init() { try { @@ -86,9 +87,10 @@ async function init() { if (NOW_TOKEN) baseNowArgs.push(`--token=${NOW_TOKEN}`); - await setGitHubStatus({ - state: 'pending', - context: 'deploy/now.sh', + + await setCheckRun({ + name: 'deploy/now.sh', + status: 'in_progress', }); outputBanner('Starting deploy...'); @@ -122,6 +124,18 @@ async function init() { if (deployOutput.status !== 0) { console.error('Error deploying:'); console.log(deployOutput.stdout, deployOutput.stderr); + await setCheckRun({ + status: 'completed', + name: 'deploy/now.sh', + conclusion: 'failure', + output: { + title: 'Now.sh Deploy failure', + summary: ` +${deployOutput.stdout} +${deployOutput.stderr} + `.trim(), + }, + }); process.exit(1); } console.log(deployOutput.stdout, deployOutput.stderr); @@ -150,20 +164,33 @@ async function init() { console.error('Error aliasing:'); console.log(aliasOutput.stdout, aliasOutput.stderr); - await setGitHubStatus({ - state: 'error', - context: 'deploy/now.sh', - description: `${aliasOutput.stdout} - ${aliasOutput.stderr}`, + await setCheckRun({ + status: 'completed', + name: 'deploy/now.sh', + conclusion: 'failure', + output: { + title: 'Now.sh Deploy failure', + summary: ` +${aliasOutput.stdout} +${aliasOutput.stderr} + `.trim(), + }, }); process.exit(1); } console.log(aliasOutput.stdout, aliasOutput.stderr); - await setGitHubStatus({ - state: 'success', - context: 'deploy/now.sh', - url: deployedUrl, - description: `Alias set to ${aliasedUrl}`, + await setCheckRun({ + status: 'completed', + name: 'deploy/now.sh', + conclusion: 'success', + output: { + title: 'Now.sh Deploy', + summary: ` +- ${deployedUrl} +- ${aliasedUrl} + `.trim(), + }, }); // if this is a tagged release, then it should become the main site. we aliased above so we have a tagged version out as well i.e. `v1-2-3-boltdesignsystem.com` diff --git a/scripts/sample-check-run-use.js b/scripts/sample-check-run-use.js deleted file mode 100644 index 4361c62d46..0000000000 --- a/scripts/sample-check-run-use.js +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env node -const { outputBanner } = require('ci-utils'); -const { createCheckRun } = require('./check-run'); - -outputBanner('Sending sample check run!'); - -createCheckRun({ - name: 'ima tester', - status: 'in_progress', - output: { - title: 'ima output title', - summary: 'ima output summary', - text: 'ima output text *with* markdown!!', - images: [ - { - alt: 'img 1', - image_url: - 'https://design.basalt.io/images/brand-stock/julentto-photography-184055.jpg', - caption: 'ima caption for img 1', - }, - { - alt: 'img 2', - image_url: - 'https://design.basalt.io/images/brand-stock/clarisse-meyer-304306.jpg', - caption: 'ima caption for img 2', - }, - ], - }, -}) - .then(results => { - outputBanner('Sample check run received'); - console.log(results); - }) - .catch(error => { - console.error('check run error', error); - process.exit(1); - }); From bd08c3fbda4b65fc09bba1a661b1792b7c380bd2 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Wed, 9 Jan 2019 17:57:30 -0800 Subject: [PATCH 5/8] bump --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5fbe1ca0c6..52df030251 100644 --- a/.travis.yml +++ b/.travis.yml @@ -90,4 +90,3 @@ notifications: on_failure: never # @todo re-enable slack: secure: cNto+gWAoK1JM9jBNG4i4rMSybv3twMbqlFSCohQFBDMwKFMdlyWqFDX6iYKtHxWEDzrZyRz3qiJ8/S44mgjeKJ/xHbHDtPchp/KL2P1htipvwD2EZXobcBEGl83v2rmtFO1WNJUPB3RIJE2yt1wJsX7NIXpDw82hePmaIvNJmtbLpK/J5uaFqGNHIsctmULgVmGSNSTyK4nYxxjNNLd0EvO37Y6VN8FhsKNu2NHMKeeQxinEvETDUh8XuqXZYNWE3PBvVa4OiDhgnr5K27jsnWX+wEmqg0xY+CMf7mUSTqVN61fA7LnHyM0qcGGmB6YTv4QYLMwPydp+nsjDcm3St9D+KOTsQ4ExOaEAL/6EnAEpl8GtxST+ytdqswhCC4yMCO61Hy+M5AoXgDSGrrXHgZakDMAcEVcJdH38791hRxcuM3ldVmHAlAWFdgRLG5rRMVh3qoXz7jbraoTdjyKMegQIQdKR2SX7O9Dv0EEtLz4lTFN2RENvAjLggUPPU+ESoUHmSbwmPGnt7jy3ra2AI3nnYpfn/0e6Op/A3z7HLbdm3XyuNWoTPhy1mc4Adca+HosJ37UPv7nDRIGds1sKYAeWq94+rEk+/6IQ/oRIDRhSYsQbLLWnU6DH4o7iOj7D+X/ngjqmF75nW2s5+7rtdBHFvNzOJalCKHiDTMfdlQ= - From 9a306f7a32bdd241183b44e1da919c4ba04bfaf8 Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Wed, 9 Jan 2019 18:18:53 -0800 Subject: [PATCH 6/8] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 52df030251..b8b45ea744 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ jobs: - phpenv config-rm xdebug.ini - composer global require hirak/prestissimo - yarn run setup:quick - - node ./scripts/create-check-suite.js + #- node ./scripts/create-check-suite.js script: yarn run test cache: yarn: true From 83b285dfe75f675e30046f8a8d77157652dcfeac Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Wed, 9 Jan 2019 21:23:35 -0800 Subject: [PATCH 7/8] fix: remove Bolt Bot comments, cleanup deploy script --- scripts/deploy.js | 93 ++++++++++++++++------------------------------- 1 file changed, 32 insertions(+), 61 deletions(-) diff --git a/scripts/deploy.js b/scripts/deploy.js index 7ceb1043db..a75e2e4011 100755 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -1,16 +1,6 @@ #!/usr/bin/env node -const url = require('url'); const { resolve } = require('path'); -const querystring = require('querystring'); -const { - setGitHubStatus, - createGitHubComment, - outputBanner, - runAndShow, - runAndReturn, - getGitSha, -} = require('ci-utils'); -const fetch = require('node-fetch'); +const { outputBanner, getGitSha } = require('ci-utils'); const { spawnSync } = require('child_process'); const { promisify } = require('util'); const gitSemverTags = require('git-semver-tags'); @@ -87,27 +77,33 @@ async function init() { if (NOW_TOKEN) baseNowArgs.push(`--token=${NOW_TOKEN}`); - await setCheckRun({ - name: 'deploy/now.sh', + name: 'Deploy - now.sh', status: 'in_progress', }); outputBanner('Starting deploy...'); - const deployOutput = spawnSync('now', [ - 'deploy', - '--force', - '--meta', - `TRAVIS_BUILD_WEB_URL="${TRAVIS_BUILD_WEB_URL}"`, - '--env', - `DOCKER_TAG=${gitSha}`, - '--build-env', - `DOCKER_TAG=${gitSha}`, - ...baseNowArgs, - ], { - encoding: 'utf8', - cwd: resolve(__dirname, '../deploys'), - }); + const deployOutput = spawnSync( + 'now', + [ + 'deploy', + '--force', + `--meta TRAVIS_BUILD_WEB_URL="${TRAVIS_BUILD_WEB_URL}"`, + `--meta TRAVIS_PULL_REQUEST_BRANCH="${TRAVIS_PULL_REQUEST_BRANCH}"`, + `--meta TRAVIS_BRANCH="${TRAVIS_BRANCH}"`, + `--meta branchName="${branchName}"`, + `--meta gitSha="${gitSha}"`, + '--env', + `DOCKER_TAG=${gitSha}`, + '--build-env', + `DOCKER_TAG=${gitSha}`, + ...baseNowArgs, + ], + { + encoding: 'utf8', + cwd: resolve(__dirname, '../deploys'), + }, + ); // const deployOutput = spawnSync( // 'now', @@ -126,7 +122,7 @@ async function init() { console.log(deployOutput.stdout, deployOutput.stderr); await setCheckRun({ status: 'completed', - name: 'deploy/now.sh', + name: 'Deploy - now.sh', conclusion: 'failure', output: { title: 'Now.sh Deploy failure', @@ -166,7 +162,7 @@ ${deployOutput.stderr} await setCheckRun({ status: 'completed', - name: 'deploy/now.sh', + name: 'Deploy - now.sh', conclusion: 'failure', output: { title: 'Now.sh Deploy failure', @@ -182,7 +178,7 @@ ${aliasOutput.stderr} await setCheckRun({ status: 'completed', - name: 'deploy/now.sh', + name: 'Deploy - now.sh', conclusion: 'success', output: { title: 'Now.sh Deploy', @@ -202,10 +198,12 @@ ${aliasOutput.stderr} { encoding: 'utf8' }, ); if (aliasOutput2.status !== 0) { + // @todo setCheckRun console.error('Error aliasing:'); console.log(aliasOutput2.stdout, aliasOutput2.stderr); process.exit(1); } + // @todo setCheckRun console.log(aliasOutput2.stdout, aliasOutput2.stderr); console.log('aliasing www.boltdesignsystem.com to main site too.'); @@ -215,12 +213,15 @@ ${aliasOutput.stderr} { encoding: 'utf8' }, ); if (aliasOutput3.status !== 0) { + // @todo setCheckRun console.error('Error aliasing:'); console.log(aliasOutput3.stdout, aliasOutput3.stderr); process.exit(1); } + // @todo setCheckRun console.log(aliasOutput3.stdout, aliasOutput3.stderr); } else if (TRAVIS_TAG && TRAVIS_TAG !== latestTag) { + // @todo setCheckRun console.error( `Error aliasing: Travis Tag of ${TRAVIS_TAG} doesn't match the latest tag of ${latestTag}`, ); @@ -230,40 +231,10 @@ ${aliasOutput.stderr} "Skipping now.sh tag alias since this isn't a tagged version.", ); } - - // `TRAVIS_PULL_REQUEST` is either `'false'` or a PR number like `'55'`. All strings. - if (TRAVIS && TRAVIS_PULL_REQUEST !== 'false') { - console.log( - 'This is a Pull Request build, so will not try to comment on PR.', - ); - - // The GitHub comment template - Can handle HTML - const githubCommentText = ` -:zap: PR built on Travis and deployed a now preview here: - -- Branch link: ${aliasedUrl} -- Permalink: ${deployedUrl} - -
- -- Commit built: ${process.env.TRAVIS_COMMIT} -- [Travis build](https://travis-ci.org/${process.env.TRAVIS_REPO_SLUG}/builds/${ - process.env.TRAVIS_BUILD_ID - }) - -
-`.trim(); - // end GitHub comment template - const results = await createGitHubComment(githubCommentText, TRAVIS_PULL_REQUEST); - console.log(`GitHub comment made: ${results.html_url}`); - - } else { - console.log('This is not a Pull Request build, so will not try to comment on PR.'); - } - // @todo Errors should be passed to `catch` } catch (error) { console.log('Error'); console.error(error); + process.exit(1); } } From 59dfdd05ffe9fe3d88d67357da32461c2c6b3aba Mon Sep 17 00:00:00 2001 From: Evan Lovely Date: Thu, 10 Jan 2019 12:41:25 -0800 Subject: [PATCH 8/8] chore: disable now meta flags --- scripts/deploy.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/deploy.js b/scripts/deploy.js index a75e2e4011..68fab42ea7 100755 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -88,11 +88,11 @@ async function init() { [ 'deploy', '--force', - `--meta TRAVIS_BUILD_WEB_URL="${TRAVIS_BUILD_WEB_URL}"`, - `--meta TRAVIS_PULL_REQUEST_BRANCH="${TRAVIS_PULL_REQUEST_BRANCH}"`, - `--meta TRAVIS_BRANCH="${TRAVIS_BRANCH}"`, - `--meta branchName="${branchName}"`, - `--meta gitSha="${gitSha}"`, + //`--meta TRAVIS_BUILD_WEB_URL="${TRAVIS_BUILD_WEB_URL}"`, + //`--meta TRAVIS_PULL_REQUEST_BRANCH="${TRAVIS_PULL_REQUEST_BRANCH}"`, + //`--meta TRAVIS_BRANCH="${TRAVIS_BRANCH}"`, + //`--meta branchName="${branchName}"`, + //`--meta gitSha="${gitSha}"`, '--env', `DOCKER_TAG=${gitSha}`, '--build-env',