0.1.1 • Published 8 months ago

@joedoyle23/semantic-release-github-pullrequest v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

semantic-release-github-pullrequest

This plugin is a plugin for semantic-release.

It automatically creates a pull request containing changes for any files you want to publish in your repository, like release notes of your newly published release.

npm npm Build Code coverage Lines of Code License

StepDescription
verifyConditionsVerify that all needed configuration is present.
publishCreate a branch to upload all assets and create the pull request on the base branch on GitHub.

Install

Add the plugin to your npm-project:

npm install semantic-release-github-pullrequest -D

Usage

The plugin can be configured in the semantic-release configuration file:

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    [
      "semantic-release-github-pullrequest", {
        "assets": ["CHANGELOG.md"],
        "baseRef": "main"
      }
    ]
  ]
}

With this example, a GitHub pull request will be created, with the content of CHANGELOG.md file, on the main branch.

Configuration

GitHub authentication

The GitHub authentication configuration is required and can be set via environment variables.

Follow the Creating 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 the GH_TOKEN_RELEASE or GH_TOKEN environment variable. The user associated with the token must have push permission to the repository.

When creating the token, the minimum required scopes are:

Note on GitHub Actions: You can use the default token which is provided in the secret GITHUB_TOKEN. However no workflows will be triggered in the Pull Request, providing it to be merged. You can use GH_TOKEN or GITHUB_TOKEN with the secret GITHUB_TOKEN to create the release, and use GH_TOKEN_RELEASE with this plugin to create the Pull Request.

Environment variables

VariableDescription
GH_TOKEN_RELEASE, GH_TOKEN or GITHUB_TOKENRequired. The token used to authenticate with GitHub.
GITHUB_API_URL or GH_URL or GITHUB_URLThe GitHub Enterprise endpoint.
GH_PREFIX or GITHUB_PREFIXThe GitHub Enterprise API prefix.
GH_SHA or GITHUB_SHAThe commit sha reference to create the new branch for the pull request. On GitHub Actions, this variable is automatically set.

Options

OptionDescriptionDefault
githubUrlThe GitHub Enterprise endpoint.GH_URL or GITHUB_URL environment variable.
githubApiPathPrefixThe GitHub Enterprise API prefix.GH_PREFIX or GITHUB_PREFIX environment variable.
proxyThe proxy to use to access the GitHub API. Set to false to disable usage of proxy. See proxy.HTTP_PROXY environment variable.
assetsRequired.. An array of files to upload to the release. See assets.-
branchName of the branch that will be created in the repository.semantic-release-pr<%= nextRelease.version ? \-\${nextRelease.version}` : "" %>`
pullrequestTitleTitle for the pull request. This title will also be used for all commit created to upload the assets. See pullrequestTitle.chore(release): update release<%= nextRelease.version ? \ \${nextRelease.version}` : "" %>`
labelsThe labels to add to the pull request created. Set to false to not add any label.['semantic-release']
baseRefThe base branch used to create the pull request (usually main or master).main

proxy

Can be false, a proxy URL or an Object with the following properties:

PropertyDescriptionDefault
hostRequired. Proxy host to connect to.-
portRequired. Proxy port to connect to.File name extracted from the path.
secureProxyIf true, then use TLS to connect to the proxy.false
headersAdditional HTTP headers to be sent on the HTTP CONNECT method.-

See node-https-proxy-agent and node-http-proxy-agent for additional details.

proxy examples

'http://168.63.76.32:3128': use the proxy running on host 168.63.76.32 and port 3128 for each GitHub API request. {host: '168.63.76.32', port: 3128, headers: {Foo: 'bar'}}: use the proxy running on host 168.63.76.32 and port 3128 for each GitHub API request, setting the Foo header value to bar.

assets

Can be a glob or and Array of globs and Objects with the following properties:

PropertyDescriptionDefault
pathRequired. A glob to identify the files to upload.-
nameThe name of the downloadable file on the GitHub release.File name extracted from the path.
labelShort description of the file displayed on the GitHub release.-

Each entry in the assets Array is globbed individually. A glob can be a String ("dist/**/*.js" or "dist/mylib.js") or an Array of Strings that will be globbed together (["dist/**", "!**/*.css"]).

If a directory is configured, all the files under this directory and its children will be included.

The name and label for each assets are generated with Lodash template. The following variables are available:

ParameterDescription
branchThe branch from which the release is done.
lastReleaseObject with version, gitTag and gitHead of the last release.
nextReleaseObject with version, gitTag, gitHead and notes of the release being done.
commitsArray of commit Objects with hash, subject, body message and author.

Note: If a file has a match in assets it will be included even if it also has a match in .gitignore.

pullrequestTitle

The title of the pull request is generated with Lodash template. The following variables are available:

ParameterDescription
branchObject with name, type, channel, range and prerelease properties of the branch from which the release is done.
lastReleaseObject with version, channel, gitTag and gitHead of the last release.
nextReleaseObject with version, channel, gitTag, gitHead and notes of the release being done.
releasesArray with a release Objects for each release published, with optional release data such as name and url.