-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: semantic release update deps (#24)
* chore: clean up plugin array * fix: add all package.json and yarn.lock files * feat: implement monorepo dependency updates as a semantic-release plugin * fix: update travis release command * chore: filter publishable packages before adding npm publisher * chore: cleanup release handler * chore: support exact version dependencies (unused) * chore: fix sleep-deprivation relics * chore: add simple smoke test to travis config
- Loading branch information
Showing
6 changed files
with
283 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# For more information about the properties used in | ||
# this file, please see the EditorConfig documentation: | ||
# https://editorconfig.org/ | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
language: node_js | ||
node_js: | ||
- 10 | ||
- 10 | ||
script: | ||
- echo "No build script, proceed..." | ||
- echo "Smoke testing d2 executable" | ||
- ./packages/d2/bin/d2 debug system | ||
deploy: | ||
- provider: script | ||
skip_cleanup: true | ||
script: | ||
- ./packages/d2-app/bin/d2-app scripts release --publish mono-npm | ||
on: | ||
tags: false | ||
branch: master | ||
- provider: script | ||
skip_cleanup: true | ||
script: | ||
- ./packages/d2-app/bin/d2-app scripts release --publish npm | ||
on: | ||
tags: false | ||
branch: master | ||
env: | ||
global: | ||
- GIT_AUTHOR_NAME=@dhis2-bot | ||
- [email protected] | ||
- GIT_COMMITTER_NAME=@dhis2-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Qor9q20p+qXe31sS7dGr8Pk6vsXMsDljvEgi32k1VuumaU2RfgPYMFtH+gYam7SIchg8A/XtWQnL5hOybc7ceVM09uRUPBtEWAy6Wn5bczt6nTsXOmfcpYH+PMnIoStG+A/636nkEDTy30k2mOa3PW+Yjh7a8jOk+yHClvoZANw3cqKjL83lW5cP/LdWe3LT5UjSUjk9hd1ndEWAUbOBEAG6MACJniF9YuwGe25JJMHArOS+pGIM3AuZsBC5lXSnALMjH2Bqfgjuhcn+djWXEvTJGr5kCwchgtqlARWUh0J5B1nwx48jvUnCyyniReKdR6n5k= | ||
global: | ||
- GIT_AUTHOR_NAME=@dhis2-bot | ||
- [email protected] | ||
- GIT_COMMITTER_NAME=@dhis2-bot | ||
- [email protected] | ||
- secure: CxBl9xFgVQhl/xFj8G9WrWKGcIB5cmdwYsSohmes2xvJZJ/2wDSC0PjewSk3BWT9CxiZ6Hv36S/54TL3q6xRsMl2GKawLtVkuozFtJd42G8wqrXVylQvix7HjgiYpPPK68sYnrV0Q3/9DK4StXYFr4JBWcgZ0pKL9KaaY7BeKMFkahRiVqa4yhTIZm1V1o6CYyQ4CKy+ZipDp9Igy+VNjSY6waTifQ5EuvL8DnETdtbp/tngUHbdXoNT+H4RQvd1f9ChRncUYlk6jTiBdGd5aN/ag0O1GY5SPQJJ4K/dyiQdbNUIb345z2tJjwr+FaUTm/fU6j+riZIs2sJ9oFlGylGokPSZQgozCtJTiP5JIP3uHtu3K9Tw/md/a1uZ8dIoCIQQoR8rx/zwlWpAVKs+ZudrNQKtnGiJ58qr5EezPuXQrMQAh+cMMkYfVRpdFv/c4yq/7SU1nK6y93gJnqw6I01nn4wNK77impIhdpwDTGbsrUdIeMojDb+VOoo3llwkeV9gRKquLZpKW1b/TXU9IQ/Icw+bN8SAnY6vqKxbg3vdBGrs9amYBIJGXxKxBZjYa+MnQiP/ipRpm3EDLn8XXiVS+VZSTCbr1cuEmJQPllTOV9c2Ov0Ie0KcBpevzfQ2p2uH+zYMSzE7+hkoQht2o+bVrSfiHqgSup8pAnYVmX4= | ||
- secure: OVdVE/sQMl0kLT4SvKFr6yVlGGC6DiQyMdUjZM4tjfh/pMNVLm8EmMccnoUSfnuDjp7lU87gbjauVP4qbMBl2j9ZBBisRAArZgf4jJ3W9H+kQGrQB8COxgWXp85mVO3qvCbbNTOCQXKPiR51kEHV4xxPcbQzLNz9endqi6zyfOGdes4kEJY/gWX+TAtYMstHVUVN097S0bLMW6xjeodlnulcEzw2LFAXSDtGj1xtjkE6XrqBIIqIR2eW/gKwiB+WGLscn9pZln1I1F2upGSE/KVBzvFk02aV5md/2PkJLtYYRxrI5LwqRvKf0FazUfsjG2BlkSV7pGySvBeLeTz2hTvOjUjXM+w5VjpL00Qor9q20p+qXe31sS7dGr8Pk6vsXMsDljvEgi32k1VuumaU2RfgPYMFtH+gYam7SIchg8A/XtWQnL5hOybc7ceVM09uRUPBtEWAy6Wn5bczt6nTsXOmfcpYH+PMnIoStG+A/636nkEDTy30k2mOa3PW+Yjh7a8jOk+yHClvoZANw3cqKjL83lW5cP/LdWe3LT5UjSUjk9hd1ndEWAUbOBEAG6MACJniF9YuwGe25JJMHArOS+pGIM3AuZsBC5lXSnALMjH2Bqfgjuhcn+djWXEvTJGr5kCwchgtqlARWUh0J5B1nwx48jvUnCyyniReKdR6n5k= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/d2-app/src/commands/scripts/support/getWorkspacePackages.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const glob = require('glob') | ||
const path = require('path') | ||
|
||
// Simplified from https://github.com/yarnpkg/yarn/blob/bb9741af4d1fe00adb15e4a7596c7a3472d0bda3/src/config.js#L814 | ||
const globPackageFilePattern = pattern => | ||
glob.sync( | ||
path.join(process.cwd(), pattern.replace(/\/?$/, '/package.json')), | ||
{ | ||
ignore: pattern.replace(/\/?$/, '/node_modules/**/package.json'), | ||
} | ||
) | ||
const getWorkspacePackages = async packageFile => { | ||
try { | ||
const rootPackage = require(packageFile) | ||
if (rootPackage.workspaces) { | ||
let workspaces | ||
if (Array.isArray(rootPackage.workspaces)) { | ||
workspaces = rootPackage.workspaces | ||
} else { | ||
workspaces = rootPackage.workspaces.packages | ||
if (!workspaces || !workspaces.isArray(workspaces)) { | ||
reporter.debug( | ||
'[release::getWorkspacePackage] Invalid workspaces key-value in root package.json' | ||
) | ||
return [] | ||
} | ||
} | ||
|
||
return workspaces.reduce( | ||
(packages, wsPattern) => [ | ||
...packages, | ||
...globPackageFilePattern(wsPattern), | ||
], | ||
[] | ||
) | ||
} | ||
} catch (e) { | ||
reporter.debug( | ||
'[release::getWorkspacePackage] Failed to load root package.json', | ||
e | ||
) | ||
} | ||
return [] | ||
} | ||
|
||
module.exports = getWorkspacePackages |
48 changes: 48 additions & 0 deletions
48
packages/d2-app/src/commands/scripts/support/normalizeAndValidatePackages.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const normalizeAndValidatePackages = packages => { | ||
const errors = [] | ||
const validPackages = [] | ||
|
||
packages.forEach(packagePath => { | ||
let pkgJsonPath | ||
if (!fs.existsSync(packagePath)) { | ||
errors.push(`Path ${packagePath} does not exist`) | ||
} else if (fs.statSync(packagePath).isDirectory()) { | ||
pkgJsonPath = path.join(packagePath, 'package.json') | ||
} else if (!packagePath.endsWith('package.json')) { | ||
errors.push( | ||
`Path ${packagePath} is not a package.json file or directory` | ||
) | ||
} else { | ||
pkgJsonPath = packagePath | ||
} | ||
|
||
if ( | ||
pkgJsonPath && | ||
fs.existsSync(pkgJsonPath) && | ||
fs.statSync(pkgJsonPath).isFile() | ||
) { | ||
try { | ||
const pkgJson = require(pkgJsonPath) | ||
|
||
validPackages.push({ | ||
path: pkgJsonPath, | ||
json: pkgJson, | ||
}) | ||
} catch (e) { | ||
errors.push({ | ||
message: `Failed to load package.json at ${pkgJsonPath}`, | ||
details: e, | ||
}) | ||
} | ||
} else { | ||
errors.push(`Package at ${packagePath} not found`) | ||
} | ||
}) | ||
|
||
return [validPackages, errors] | ||
} | ||
|
||
module.exports = normalizeAndValidatePackages |
93 changes: 93 additions & 0 deletions
93
packages/d2-app/src/commands/scripts/support/semantic-release-update-deps.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const SemanticReleaseError = require('@semantic-release/error') | ||
const AggregateError = require('aggregate-error') | ||
const normalizeAndValidatePackages = require('./normalizeAndValidatePackages') | ||
|
||
const verifyConditions = (config = {}, context) => { | ||
const { silent, packages } = config | ||
const { logger } = context | ||
if (!packages || !packages.length || packages.length < 2) { | ||
throw new SemanticReleaseError( | ||
'Invalid packages option', | ||
'EINVALIDPACKAGES', | ||
'You must pass at least two package directories to semantic-release-update-deps' | ||
) | ||
} | ||
|
||
const [validPackages, errors] = normalizeAndValidatePackages(packages) | ||
|
||
if (errors.length) { | ||
throw new AggregateError(errors) | ||
} | ||
|
||
validPackages.forEach(package => { | ||
package.label = package.json.name || '<unnamed>' | ||
if (!silent) { | ||
logger.log(`Package ${package.label} found at ${package.path}`) | ||
} | ||
}) | ||
|
||
context.packages = validPackages | ||
} | ||
|
||
const replaceDependencies = (pkg, listNames, packageNames, version) => { | ||
const dependencies = [] | ||
packageNames.forEach(packageName => { | ||
listNames.forEach(listName => { | ||
if (pkg[listName] && pkg[listName][packageName]) { | ||
pkg[listName][packageName] = version | ||
dependencies.push(`${packageName} (${listName})`) | ||
} | ||
}) | ||
}) | ||
return dependencies | ||
} | ||
|
||
const prepare = (config, context) => { | ||
if (!context.packages) { | ||
verifyConditions({ ...config, silent: true }, context) | ||
} | ||
const { silent, exact } = config | ||
const { nextRelease, logger, packages } = context | ||
|
||
const targetVersion = exact | ||
? nextRelease.version | ||
: `^${nextRelease.version}` | ||
|
||
const names = packages.map(package => package.json.name).filter(n => n) | ||
packages.forEach(package => { | ||
const pkgJson = package.json | ||
const relativePath = path.relative(context.cwd, package.path) | ||
|
||
pkgJson.version = nextRelease.version | ||
if (!silent) { | ||
logger.log( | ||
`Updated version to ${nextRelease.version} for package ${ | ||
package.label | ||
} at ${relativePath}` | ||
) | ||
} | ||
|
||
replaceDependencies( | ||
pkgJson, | ||
['dependencies', 'devDependencies', 'peerDependencies'], | ||
names, | ||
targetVersion | ||
).forEach( | ||
dep => | ||
!silent && | ||
logger.log( | ||
`Upgraded dependency ${dep}@${targetVersion} for ${ | ||
package.label | ||
} at ${relativePath}` | ||
) | ||
) | ||
fs.writeFileSync( | ||
package.path, | ||
JSON.stringify(pkgJson, undefined, config.tabSpaces || 2) + '\n' | ||
) | ||
}) | ||
} | ||
|
||
module.exports = { verifyConditions, prepare } |