Skip to content

Commit

Permalink
feat(ui-scripts): post gerrit reviews from publish script
Browse files Browse the repository at this point in the history
...to log the published version for the commit.

refs INSTUI-1947

Change-Id: Ie7379438ec47f635542a3272efa058ba3ec35298
Reviewed-on: https://gerrit.instructure.com/187475
Tested-by: Jenkins
Reviewed-by: Steve Jensen <sejensen@instructure.com>
QA-Review: Jennifer Stern <jstern@instructure.com>
Product-Review: Jennifer Stern <jstern@instructure.com>
  • Loading branch information
junyper committed Mar 29, 2019
1 parent 08dedf3 commit b63ec87
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ SLACK_USERNAME=instui
SLACK_WEBHOOK=
SSH_KEY_PATH=
SSH_USERNAME=
CHROMATIC_APP_CODE=
CHROMATIC_APP_CODE=
GERRIT_HOST=
GERRIT_PORT=
4 changes: 4 additions & 0 deletions Jenkinsfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ pipeline {
GIT_USERNAME="${GIT_USERNAME}"
GIT_REMOTE_URL="${GIT_REMOTE_URL}"
GIT_REMOTE_NAME="${GIT_REMOTE_NAME}"
GERRIT_HOST="${GERRIT_HOST}"
GERRIT_PORT="${GERRIT_PORT}"
GERRIT_CHANGE_NUMBER="${GERRIT_CHANGE_NUMBER}"
GERRIT_PATCHSET_NUMBER="${GERRIT_PATCHSET_NUMBER}"
UV_THREADPOOL_SIZE=128
}

Expand Down
4 changes: 2 additions & 2 deletions Jenkinsfile.vrt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pipeline {

environment {
CHROMATIC_APP_CODE="${CHROMATIC_APP_CODE}"
GERRIT_CHANGE_ID="${GERRIT_CHANGE_ID}",
GERRIT_PROJECT="${GERRIT_PROJECT}",
GERRIT_CHANGE_ID="${GERRIT_CHANGE_ID}"
GERRIT_PROJECT="${GERRIT_PROJECT}"
GERRIT_BRANCH="${GERRIT_BRANCH}"
GERRIT_EVENT_TYPE="${GERRIT_EVENT_TYPE}"
}
Expand Down
4 changes: 4 additions & 0 deletions docker/release
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ SLACK_USERNAME=${SLACK_USERNAME}
SLACK_WEBHOOK=${SLACK_WEBHOOK}
SSH_KEY_PATH=${SSH_KEY_PATH}
SSH_USERNAME=${SSH_USERNAME}
GERRIT_HOST=${GERRIT_HOST}
GERRIT_PORT=${GERRIT_PORT}
GERRIT_CHANGE_NUMBER=${GERRIT_CHANGE_NUMBER}
GERRIT_PATCHSET_NUMBER=${GERRIT_PATCHSET_NUMBER}
UV_THREADPOOL_SIZE=128
EOF
) > $env_file
Expand Down
11 changes: 10 additions & 1 deletion packages/ui-scripts/lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
const { getPackageJSON } = require('@instructure/pkg-utils')
const { error, info } = require('@instructure/command-utils')

const { GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER } = process.env
const {
publishPackages,
createNPMRCFile
Expand All @@ -33,6 +34,7 @@ const {
checkIfCommitIsReviewed,
isReleaseCommit
} = require('./utils/git')
const { postGerritReview } = require('./utils/gerrit')
const {
setupGit,
checkWorkingDirectory
Expand Down Expand Up @@ -66,5 +68,12 @@ async function publish (packageName, currentVersion, preidAndTag, config = {}) {
versionToRelease = 'prerelease'
}

await publishPackages(packageName, versionToRelease, preidAndTag)
const releasedVersion = await publishPackages(packageName, versionToRelease, preidAndTag)

if (GERRIT_CHANGE_NUMBER && GERRIT_PATCHSET_NUMBER) {
await postGerritReview(
`${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER}`,
`Successfully published ${releasedVersion} for this commit.`
)
}
}
61 changes: 61 additions & 0 deletions packages/ui-scripts/lib/utils/gerrit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 - present Instructure, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

const GerritBot = require('gerritbot')
const { error } = require('@instructure/command-utils')

const {
SSH_USERNAME,
GERRIT_HOST,
GERRIT_PORT,
SSH_KEY_PATH
} = process.env

let gerrit

function gerritClient () {
if (!gerrit) {
gerrit = new GerritBot.Client({
user: SSH_USERNAME,
host: GERRIT_HOST,
keyFile: SSH_KEY_PATH,
sshPort: parseInt(GERRIT_PORT)
})
}
return gerrit
}

exports.postGerritReview = async function postGerritReview (target, message, labels = {}) {
return new Promise((resolve, reject) => {
gerritClient().review(target, { message, labels }, (err) => {
if (err) {
error(`An error occured posting a gerrit review for ${target}.`)
error(err)
reject(err)
} else {
resolve()
}
})
})
}
1 change: 1 addition & 0 deletions packages/ui-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dotenv": "^7.0.0",
"eslint": "^5.15.3",
"find-up": "^3.0.0",
"gerritbot": "^1.0.3",
"gh-pages": "^2.0.1",
"http-server": "^0.11.1",
"jira-client": "^6.7.1",
Expand Down
Loading

0 comments on commit b63ec87

Please sign in to comment.