- Notifications
You must be signed in to change notification settings - Fork141
semantic-release plugin to publish a GitHub release and comment on released Pull Requests/Issues
License
semantic-release/github
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
semantic-release plugin to publish aGitHub release and comment on released Pull Requests/Issues.
| Step | Description |
|---|---|
verifyConditions | Verify the presence and the validity of the authentication (set viaenvironment variables) and theassets option configuration. |
publish | Publish aGitHub release, optionally uploading file assets. |
addChannel | Update aGitHub release'spre-release field. |
success | Add a comment to eachGitHub Issue orPull Request resolved by the release and close issues previously open by thefail step. |
fail | Open or update aGitHub Issue with information about the errors that caused the release to fail. |
Tip
You do not need to directly depend on this package if you are usingsemantic-release.semantic-release already depends on this package, and defining your own direct dependency can result in conflicts when you updatesemantic-release.
$ npm install @semantic-release/github -D
The plugin can be configured in thesemantic-release configuration file:
{"plugins": ["@semantic-release/commit-analyzer","@semantic-release/release-notes-generator", ["@semantic-release/github", {"assets": [ {"path":"dist/asset.min.css","label":"CSS distribution" }, {"path":"dist/asset.min.js","label":"JS distribution" } ] } ] ]}With this exampleGitHub releases will be published with the filedist/asset.min.css anddist/asset.min.js.
The GitHub authentication configuration isrequired and can be set viaenvironment variables.
Follow theCreating a personal access token for the command line documentation to obtain an authentication token. The token has to be made available in your CI environment via theGH_TOKEN environment variable. The user associated with the token must have push permission to the repository.
When creating the token, theminimum required scopes are:
repofor a private repositorypublic_repofor a public repository
Note on GitHub Actions: You can use the default token which is provided in the secretGITHUB_TOKEN. However releases done with this token will NOT trigger release events to start other workflows.If you have actions that trigger on newly created releases, please use a generated token for that and store it in your repository's secrets (any other name than GITHUB_TOKEN is fine).
When using theGITHUB_TOKEN, theminimum required permissions are:
contents: writeto be able to publish a GitHub releaseissues: writeto be able to comment on released issuespull-requests: writeto be able to comment on released pull requests
| Variable | Description |
|---|---|
GITHUB_TOKEN orGH_TOKEN | Required. The token used to authenticate with GitHub. |
GITHUB_URL orGH_URL | The GitHub server endpoint. |
GITHUB_PREFIX orGH_PREFIX | The GitHub API prefix, relative toGITHUB_URL. |
GITHUB_API_URL | The GitHub API endpoint. Note that this overwritesGITHUB_PREFIX. |
| Option | Description | Default |
|---|---|---|
githubUrl | The GitHub server endpoint. | GH_URL orGITHUB_URL environment variable. |
githubApiPathPrefix | The GitHub API prefix, relative togithubUrl. | GH_PREFIX orGITHUB_PREFIX environment variable. |
githubApiUrl | The GitHub API endpoint. Note that this overwritesgithubApiPathPrefix. | GITHUB_API_URL environment variable. |
proxy | The proxy to use to access the GitHub API. Set tofalse to disable usage of proxy. Seeproxy. | HTTP_PROXY environment variable. |
assets | An array of files to upload to the release. Seeassets. | - |
successComment | The comment to add to each issue and pull request resolved by the release. Set tofalse to disable commenting on issues and pull requests. SeesuccessComment. | :tada: This issue has been resolved in version ${nextRelease.version} :tada:\n\nThe release is available on [GitHub release](<github_release_url>) |
successCommentCondition | Use this as condition, when to comment on issues or pull requests. SeesuccessCommentCondition | - |
failComment | The content of the issue created when a release fails. Set tofalse to disable opening an issue when a release fails. SeefailComment. | Friendly message with links tosemantic-release documentation and support, with the list of errors that caused the release to fail. |
failTitle | The title of the issue created when a release fails. Set tofalse to disable opening an issue when a release fails. | The automated release is failing 🚨 |
failCommentCondition | Use this as condition, when to comment on or create an issues in case of failures. SeefailCommentCondition. | - |
labels | Thelabels to add to the issue created when a release fails. Set tofalse to not add any label. | ['semantic-release'] |
assignees | Theassignees to add to the issue created when a release fails. | - |
releasedLabels | Thelabels to add to each issue and pull request resolved by the release. Set tofalse to not add any label. SeereleasedLabels. | ['released<%= nextRelease.channel ? \ on @${nextRelease.channel}` : "" %>']- |
addReleases | Will add release links to the GitHub Release. Can befalse,"bottom" or"top". SeeaddReleases. | false |
draftRelease | A boolean indicating if a GitHub Draft Release should be created instead of publishing an actual GitHub Release. | false |
releaseNameTemplate | ALodash template to customize the github release's name | <%= nextverison.name %> |
releaseBodyTemplate | ALodash template to customize the github release's body | <%= nextverison.notes %> |
discussionCategoryName | The category name in which to create a linked discussion to the release. Set tofalse to disable creating discussion for a release. | false |
Can befalse, a proxy URL or anObject with the following properties:
| Property | Description | Default |
|---|---|---|
host | Required. Proxy host to connect to. | - |
port | Required. Proxy port to connect to. | File name extracted from thepath. |
secureProxy | Iftrue, then use TLS to connect to the proxy. | false |
headers | Additional HTTP headers to be sent on the HTTP CONNECT method. | - |
Seenode-https-proxy-agent andnode-http-proxy-agent for additional details.
'http://168.63.76.32:3128': use the proxy running on host168.63.76.32 and port3128 for each GitHub API request.{host: '168.63.76.32', port: 3128, headers: {Foo: 'bar'}}: use the proxy running on host168.63.76.32 and port3128 for each GitHub API request, setting theFoo header value tobar.
Can be aglob or andArray ofglobs andObjects with the following properties:
| Property | Description | Default |
|---|---|---|
path | Required. Aglob to identify the files to upload. | - |
name | The name of the downloadable file on the GitHub release. | File name extracted from thepath. |
label | Short description of the file displayed on the GitHub release. | - |
Each entry in theassetsArray is globbed individually. Aglobcan be aString ("dist/**/*.js" or"dist/mylib.js") or anArray ofStrings that will be globbed together(["dist/**", "!**/*.css"]).
If a directory is configured, all the files under this directory and its children will be included.
Thename andlabel for each assets are generated withLodash template. The following variables are available:
| Parameter | Description |
|---|---|
branch | The branch from which the release is done. |
lastRelease | Object withversion,gitTag andgitHead of the last release. |
nextRelease | Object withversion,gitTag,gitHead andnotes of the release being done. |
commits | Array of commitObjects withhash,subject,bodymessage andauthor. |
Note: If a file has a match inassets it will be included even if it also has a match in.gitignore.
'dist/*.js': include all thejs files in thedist directory, but not in its sub-directories.
[['dist', '!**/*.css']]: include all the files in thedist directory and its sub-directories excluding thecssfiles.
[{path: 'dist/MyLibrary.js', label: 'MyLibrary JS distribution'}, {path: 'dist/MyLibrary.css', label: 'MyLibrary CSS distribution'}]: include thedist/MyLibrary.js anddist/MyLibrary.css files, and label themMyLibrary JS distribution andMyLibrary CSS distribution in the GitHub release.
[['dist/**/*.{js,css}', '!**/*.min.*'], {path: 'build/MyLibrary.zip', label: 'MyLibrary'}]: include all thejs andcss files in thedist directory and its sub-directories excluding the minified version, plus thebuild/MyLibrary.zip file and label itMyLibrary in the GitHub release.
[{path: 'dist/MyLibrary.js', name: 'MyLibrary-${nextRelease.gitTag}.js', label: 'MyLibrary JS (${nextRelease.gitTag}) distribution'}]: include the filedist/MyLibrary.js and upload it to the GitHub release with nameMyLibrary-v1.0.0.js and labelMyLibrary JS (v1.0.0) distribution which will generate the link:
[MyLibrary JS (v1.0.0) distribution](MyLibrary-v1.0.0.js)
The message for the issue comments is generated withLodash template. The following variables are available:
| Parameter | Description |
|---|---|
branch | Object withname,type,channel,range andprerelease properties of the branch from which the release is done. |
lastRelease | Object withversion,channel,gitTag andgitHead of the last release. |
nextRelease | Object withversion,channel,gitTag,gitHead andnotes of the release being done. |
commits | Array of commitObjects withhash,subject,bodymessage andauthor. |
releases | Array with a releaseObjects for each release published, with optional release data such asname andurl. |
issue | AGitHub API pull request object for pull requests related to a commit, orGitHub API issue object for issues resolved viakeywords |
ThesuccessCommentThis ${issue.pull_request ? 'pull request' : 'issue'} is included in version ${nextRelease.version} will generate the comment:
This pull request is included in version 1.0.0
ALodash template string that should evaluate to a truthy or falsy variable. The following variables are available:
| Parameter | Description |
|---|---|
branch | Object withname,type,channel,range andprerelease properties of the branch from which the release is done. |
lastRelease | Object withversion,channel,gitTag andgitHead of the last release. |
nextRelease | Object withversion,channel,gitTag,gitHead andnotes of the release being done. |
commits | Array of commitObjects withhash,subject,bodymessage andauthor. |
releases | Array with a releaseObjects for each release published, with optional release data such asname andurl. |
issue | AGitHub API Pull Request object for pull requests related to a commit |
- do not create any comments at all: set to
falseor templating:"<% return false; %>" - to only comment on issues:
"<% return !issue.pull_request; %>" - to only comment on pull requests:
"<% return issue.pull_request; %>" - to avoid comment on PRs or issues created by Bots:
"<% return issue.user.type !== 'Bot'; %>" - you can use labels to filter issues:
"<% return issue.labels?.some((label) => { return label.name === ('semantic-release-relevant'); }); %>"
check theGitHub API issue object for properties which can be used for the filter
The message for the issue content is generated withLodash template. The following variables are available:
| Parameter | Description |
|---|---|
branch | The branch from which the release had failed. |
errors | AnArray ofSemanticReleaseError. Each error has themessage,code,pluginName anddetails properties.pluginName contains the package name of the plugin that threw the error.details contains a information about the error formatted in markdown. |
ThefailCommentThis release from branch ${branch.name} had failed due to the following errors:\n- ${errors.map(err => err.message).join('\\n- ')} will generate the comment:
This release from branch master had failed due to the following errors:
- Error message 1
- Error message 2
ALodash template string that should evaluate to a truthy or falsy variable. The following variables are available:
| Parameter | Description |
|---|---|
branch | Object withname,type,channel,range andprerelease properties of the branch from which the release is done. |
lastRelease | Object withversion,channel,gitTag andgitHead of the last release. |
nextRelease | Object withversion,channel,gitTag,gitHead andnotes of the release being done. |
commits | Array of commitObjects withhash,subject,bodymessage andauthor. |
releases | Array with a releaseObjects for each release published, with optional release data such asname andurl. |
issue | AGitHub API pull request object for pull requests related to a commit, orGitHub API issue object for issues resolved viakeywords |
- do not create any comments at all: set to
falseor templating:"<% return false; %>" - to only comment on main branch:
"<% return branch.name === 'main' %>" - you can use labels to filter issues, i.e. to not comment if the issue is labeled with
wip:"<% return !issue.labels?.includes('wip') %>"
check theGitHub API Pull Request Object for properties which can be used for the filter
Each label name is generated withLodash template. The following variables are available:
| Parameter | Description |
|---|---|
branch | Object withname,type,channel,range andprerelease properties of the branch from which the release is done. |
lastRelease | Object withversion,channel,gitTag andgitHead of the last release. |
nextRelease | Object withversion,channel,gitTag,gitHead andnotes of the release being done. |
commits | Array of commitObjects withhash,subject,bodymessage andauthor. |
releases | Array with a releaseObjects for each release published, with optional release data such asname andurl. |
issue | AGitHub API pull request object for pull requests related to a commit, orGitHub API issue object for issues resolved viakeywords |
ThereleasedLabels['released<%= nextRelease.channel ? ` on @\${nextRelease.channel}` : "" %> from <%= branch.name %>'] will generate the label:
released on @next from branch next
Add links to other releases to the GitHub release body.
Valid values for this option arefalse,"top" or"bottom".
SeeThe introducing PR for an example on how it will look.
About
semantic-release plugin to publish a GitHub release and comment on released Pull Requests/Issues
Topics
Resources
License
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.