A script to just update instUI

Closes: CORE-1709

This is what our Jenkins job to pull in every instui RC commit will use

Test plan:
* run `yarn upgrade-instructure-ui`
* it should make a commit that has new entries in yarn.lock for all the
  instUI packages that uses the latest rc version on the npm registry
* it should not affect anything else besides yarn.lock

Change-Id: I78cce6e801015819c4e4b27e26ede352deceebb9
Reviewed-on: https://gerrit.instructure.com/160435
Tested-by: Jenkins
Reviewed-by: Brent Burgoyne <bburgoyne@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
This commit is contained in:
Ryan Shaw 2018-08-10 10:22:49 -06:00
parent b766794156
commit e8a88cceea
3 changed files with 66 additions and 1 deletions

View File

@ -102,6 +102,7 @@
},
"devDependencies": {
"@sentry/webpack-plugin": "^1.5.2",
"@yarnpkg/lockfile": "^1.0.2",
"axe-core": "~2.1.7",
"babel-cli": "^6",
"babel-core": "^6",
@ -229,7 +230,8 @@
"jspec": "./spec/jspec.sh",
"jspec-watch": "./spec/jspec.sh --watch",
"a11y-report": "./spec/jspec.sh --a11y",
"upgrade-and-dedupe": "rm -rf yarn.lock node_modules && yes 1 | yarn install --flat --production --ignore-scripts && git checkout package.json && yarn install && git add yarn.lock"
"upgrade-and-dedupe": "rm -rf yarn.lock node_modules && yes 1 | yarn install --flat --production --ignore-scripts && git checkout package.json && yarn install && git add yarn.lock",
"upgrade-instructure-ui": "script/upgrade-instructure-ui"
},
"resolutions": {
"@instructure/ui-a11y": "5.16.0-rc.4",

59
script/upgrade-instructure-ui Executable file
View File

@ -0,0 +1,59 @@
#!/usr/bin/env node
/*
* Copyright (C) 2018 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Removes all "@instructure/ui-<whatever>" entries from yarn.lock so that the
* next time you run yarn it uses all of the latest versions available on npm
*/
const fs = require('fs')
const lockfile = require('@yarnpkg/lockfile')
const packageJson = require('../package.json')
const {promisify} = require('util')
const exec = promisify(require('child_process').exec)
const yarnFile = fs.readFileSync('yarn.lock', 'utf8')
const yarnJson = lockfile.parse(yarnFile)
console.log('Removing "@instructue" entries from yarn.lock and configuring package.json "resolutions" for all instUI stuff...')
const promises = Object.keys(yarnJson.object)
.filter(k => k.startsWith('@instructure'))
.map(async k => {
delete yarnJson.object[k]
const pkgName = `@${k.split('@')[1]}`
if (!packageJson.resolutions[pkgName]) {
const latestRcOnRegistry = (await exec(`npm view ${pkgName} dist-tags.rc`)).stdout.trim()
packageJson.resolutions[pkgName] = `${latestRcOnRegistry}`
}
})
Promise.all(promises).then(async () => {
fs.writeFileSync('yarn.lock', lockfile.stringify(yarnJson.object), 'utf8')
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2), 'utf8')
console.log('Running `yarn` to install new package versions...')
await exec(`yarn --ignore-scripts`)
console.log('Cleaning up "resolutions" from package.json...')
await exec(`git checkout package.json`)
await exec(`yarn`)
await exec(`git add yarn.lock`)
console.log('Commiting changes...')
await exec(`git commit -m "upgrade instUI to the latest rc"`)
console.log('Made a commit to upgrade instUI to the latest rc. You should push it to gerrit.')
})

View File

@ -782,6 +782,10 @@
"@webassemblyjs/wast-parser" "1.5.13"
long "^3.2.0"
"@yarnpkg/lockfile@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.0.2.tgz#833d163680a151d2441a2489f5fe5fa87ac87726"
JSONStream@^0.8.4:
version "0.8.4"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-0.8.4.tgz#91657dfe6ff857483066132b4618b62e8f4887bd"