Skip to content

Commit

Permalink
fix(release): throw if the versions are wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
varl committed Jun 30, 2021
1 parent b6ab4db commit fc157e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
7 changes: 2 additions & 5 deletions packages/utils/src/cmds/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,20 @@ const handler = async ({ publish }) => {
deferPlugin,
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
updateDepsPlugin,
...(updateDepsPlugin ? [updateDepsPlugin] : []),
changelogPlugin,
...publisher(publish, packages),
gitPlugin,
'@semantic-release/github',
]

reporter.debug('Order of plugins')
reporter.debug(plugins)

/* rely on defaults for configuration, except for plugins as they
* need to be custom.
*
* https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md
*/
const options = {
plugins: plugins.filter(n => !!n),
plugins,
}

const config = {
Expand Down
29 changes: 15 additions & 14 deletions packages/utils/src/support/semantic-release-app-hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const { handler: publishAppHub } = publishCommand

exports.verifyConditions = (config, context) => {
const { pkgRoot } = config
const { env, nextRelease } = context
const { env } = context

const configPath = path.join(pkgRoot, 'd2.config.js')
const packagePath = path.join(pkgRoot, 'package.json')
const configPath = path.join(pkgRoot, 'd2.config.js')

if (!fs.existsSync(configPath)) {
throw new SemanticReleaseError(
Expand All @@ -21,8 +21,6 @@ exports.verifyConditions = (config, context) => {
)
}

const d2Config = require(configPath)

if (!fs.existsSync(packagePath)) {
throw new SemanticReleaseError(
`Failed to locate package.json file, does it exist in ${pkgRoot}?`,
Expand All @@ -31,15 +29,7 @@ exports.verifyConditions = (config, context) => {
)
}

const pkg = require(packagePath)

if (semver.lt(pkg.version, nextRelease.version)) {
throw new SemanticReleaseError(
`Wrong version detected in ${packagePath}, expected ${nextRelease.version} but got ${pkg.version}.`,
'EPACKAGEVERSION',
'The version in package.json should be updated to the next release version before publishing.'
)
}
const d2Config = require(configPath)

if (d2Config.type === 'lib') {
throw new SemanticReleaseError(
Expand Down Expand Up @@ -79,7 +69,18 @@ exports.verifyConditions = (config, context) => {

exports.publish = async (config, context) => {
const { pkgRoot, baseUrl, channel } = config
const { env } = context
const { env, nextRelease } = context

const packagePath = path.join(pkgRoot, 'package.json')
const pkg = require(packagePath)

if (semver.lt(pkg.version, nextRelease.version)) {
throw new SemanticReleaseError(
`Wrong version detected in ${packagePath}, expected ${nextRelease.version} but got ${pkg.version}.`,
'EPACKAGEVERSION',
'The version in package.json should be updated to the next release version before publishing.'
)
}

await publishAppHub({
cwd: pkgRoot,
Expand Down

0 comments on commit fc157e5

Please sign in to comment.