-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow 'git commit' and 'git push' during the prepare and/or pub…
…lish step
- Loading branch information
Showing
5 changed files
with
298 additions
and
51 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
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,31 +1,88 @@ | ||
const {defaultTo, castArray} = require('lodash'); | ||
const {defaultTo, castArray, isNil} = require('lodash'); | ||
const verifyGit = require('./lib/verify'); | ||
const prepareGit = require('./lib/prepare'); | ||
const commitAndPushGit = require('./lib/commit-and-push'); | ||
|
||
let verified; | ||
let prepareVerified; | ||
let publishVerified; | ||
|
||
function verifyConditions(pluginConfig, context) { | ||
function isPrepareConfigured(pluginConfig, context) { | ||
return ( | ||
!isPublishConfigured(pluginConfig, context) || | ||
!isNil(pluginConfig.prepare) || | ||
castArray(context.options.prepare).some(config => config && config.path === '@semantic-release/git') | ||
); | ||
} | ||
|
||
function isPublishConfigured(pluginConfig, context) { | ||
return ( | ||
!isNil(pluginConfig.publish) || | ||
castArray(context.options.publish).some(config => config && config.path === '@semantic-release/git') | ||
); | ||
} | ||
|
||
function resolvePluginConfig(step, pluginConfig, context) { | ||
// If the plugin config is defined under its intended step, prefer that | ||
if (pluginConfig[step]) { | ||
pluginConfig = pluginConfig[step]; | ||
} | ||
|
||
// If the Git prepare plugin or publish plugin is used and has `assets` or `message` configured, validate them now in order to prevent any release if the configuration is wrong | ||
const {options} = context; | ||
// If the Git prepare plugin is used and has `assets` or `message` configured, validate them now in order to prevent any release if the configuration is wrong | ||
if (options.prepare) { | ||
const preparePlugin = | ||
castArray(options.prepare).find(config => config.path && config.path === '@semantic-release/git') || {}; | ||
if (options[step]) { | ||
const stepPlugin = | ||
castArray(options[step]).find(config => config.path && config.path === '@semantic-release/git') || {}; | ||
|
||
pluginConfig.assets = defaultTo(pluginConfig.assets, stepPlugin.assets); | ||
pluginConfig.message = defaultTo(pluginConfig.message, stepPlugin.message); | ||
} | ||
|
||
pluginConfig.assets = defaultTo(pluginConfig.assets, preparePlugin.assets); | ||
pluginConfig.message = defaultTo(pluginConfig.message, preparePlugin.message); | ||
return pluginConfig; | ||
} | ||
|
||
function verifyConditions(pluginConfig, context) { | ||
const prepareConfig = resolvePluginConfig('prepare', pluginConfig, context); | ||
if (prepareConfig) { | ||
verifyGit(prepareConfig); | ||
prepareVerified = true; | ||
} | ||
|
||
verifyGit(pluginConfig); | ||
verified = true; | ||
const publishConfig = resolvePluginConfig('publish', pluginConfig, context); | ||
if (publishConfig) { | ||
verifyGit(publishConfig); | ||
publishVerified = true; | ||
} | ||
} | ||
|
||
async function prepare(pluginConfig, context) { | ||
if (!verified) { | ||
if (!isPrepareConfigured(pluginConfig, context)) { | ||
// If a 'publish' config is specifically called out and 'prepare' is not, ignore this step | ||
return; | ||
} | ||
|
||
pluginConfig = resolvePluginConfig('prepare', pluginConfig, context); | ||
|
||
if (!prepareVerified) { | ||
verifyGit(pluginConfig); | ||
prepareVerified = true; | ||
} | ||
|
||
await commitAndPushGit(pluginConfig, context); | ||
} | ||
|
||
async function publish(pluginConfig, context) { | ||
if (!isPublishConfigured(pluginConfig, context)) { | ||
// If a 'publish' config isn't specifically called out, ignore this step | ||
return; | ||
} | ||
|
||
pluginConfig = resolvePluginConfig('publish', pluginConfig, context); | ||
|
||
if (!publishVerified) { | ||
verifyGit(pluginConfig); | ||
verified = true; | ||
publishVerified = true; | ||
} | ||
|
||
await prepareGit(pluginConfig, context); | ||
await commitAndPushGit(pluginConfig, context); | ||
} | ||
|
||
module.exports = {verifyConditions, prepare}; | ||
module.exports = {verifyConditions, prepare, publish}; |
File renamed without changes.
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
Oops, something went wrong.