semantic-release
, you need to decide which parts of the release lifecycle are important to that plugin. For example, it is best to always have a verifyConditions
step because you may be receiving inputs from a user and want to make sure they exist. A plugin can abide by any of the following lifecycles:verifyConditions
analyzeCommits
verifyRelease
generateNotes
addChannel
prepare
publish
success
fail
semantic-release
will require the plugin via node
and look through the required object for methods named like the lifecyles stated above. For example, if your plugin only had a verifyConditions
and success
step, the main
file for your object would need to export
an object with verifyConditions
and success
functions.pluginConfig
- an object containing the options that a user may pass in via their release.config.js
file (or similar)context
- provided by semantic-release
for access to things like env
variables set on the running process.pluginConfig
and context
as parameters.yarn init
. This will provide you with a basic node project to get started with. From there, create an index.js
file, and make sure it is specified as the main
in the package.json
. We will use this file to orchestrate the lifecycle methods later on.src
or lib
folder in the root of the project. This is where we will store our logic and code for how our lifecycle methods work. Finally, create a test
folder so you can write tests related to your logic.index.js
file, you can start by writing the following codesrc
folder, create a file called verify.js
and add the followingsemantic-release
, it would run when the verify
step occurred.option
is passed. An option
is a configuration object that is specific to your plugin. For example, the user may set an option
in their release config like:message
option will be passed to the pluginConfig
object mentioned earlier. We can use the validation method we created to verify this option exists so we can perform logic based on that knowledge. In our verify
file, we can add the following:stdout
stderr
logger
verifyConditions
lifecycle):cwd
env
envCi
isCi
commit
branch
options
semantic-release
via CLI, configuration files etc.branch
channel
tags
type
name
range
accept
main
branches
analyzeCommits
lifecycle context has keyscommits
(List)commit
(Object)long
(String, Commit hash)short
(String, Commit hash)tree
(Object)long
(String, Commit hash)short
(String, Commit hash)author
(Object)name
(String)email
(String)date
(String, ISO 8601 timestamp)committer
(Object)name
(String)email
(String)date
(String, ISO 8601 timestamp)subject
(String, Commit message subject)body
(String, Commit message body)hash
(String, Commit hash)committerDate
(String, ISO 8601 timestamp)message
(String)gitTags
(String, List of git tags)releases
(List)lastRelease
(Object)version
(String)gitTag
(String)channels
(List)gitHead
(String, Commit hash)name
(String)nextRelease
(Object)type
(String)channel
(String)gitHead
(String, Git hash)version
(String, version without v
)gitTag
(String, version with v
)name
(String)verifyRelease
.generateNotes
has populated nextRelease.notes
.success
and fail
are mutually exclusive, only one of them will be run.releases
publish
lifecyclesuccess
and fail
are mutually exclusive, only one of them will be run.errors
options
, environment variables exist to allow users to pass tokens and set special URLs. These are set on the context
object instead of the pluginConfig
object. Let's say we wanted to check for GITHUB_TOKEN
in the environment because we want to post to GitHub on the user's behalf. To do this, we can add the following to our verify
command:context.logger
to provide debug logging in the plugin.PLUGIN_PACKAGE_NAME
is automatically inferred.fail
lifecycle receive the errors correctly. For any other types of errors the internal error handling does nothing, lets them through up until the final catch and does not call any fail
plugins.commit-analyzer
) can change the result. This way it is possible to create more advanced rules or situations, e.g. if none of the commits would result in new release, then a default can be defined.