GitHub Releases
@neosjs/release ships with a built-in github plugin. During a release it can automatically create or update a GitHub Release through the GitHub REST API, upload release assets, open a Discussion, and post comments on the related PRs / issues. When no Token is configured, it automatically falls back to a pre-filled release page in the browser.
Quick Start
- Enable
github.release: truein the configuration file (or pass--github.releaseon the command line). - Create a GitHub Token; either of the following works (GitHub recommends fine-grained Tokens first; the permissions required by each feature are listed below):
- fine-grained Token: under Repository access, select only the target repository, and under Repository permissions grant Contents: Read and write and Metadata: Read-only.
- classic Token: select the
reposcope, and note that it covers every repository you can access (the note is pre-filled; feel free to change it to your project name).
- Provide the Token through the
GITHUB_TOKENenvironment variable (never write a Token into a configuration file or commit it to a repository):
export GITHUB_TOKEN="ghp_xxxxxxxxxxxx"
releaseTo use a different environment variable name, set github.tokenRef:
{
"github": {
"release": true,
"tokenRef": "MY_GITHUB_TOKEN"
}
}Credential Sources and Priority
The github plugin and --sync-releases resolve GitHub credentials in the following order (the Token is never written to the log):
- Environment variable:
GITHUB_TOKEN(or the variable name specified bygithub.tokenRef). - Local
ghCLI: when the environment variable is not set,gh auth tokenis run automatically (with--hostname <host>added automatically for GitHub Enterprise) to read the credentials of the locally logged-inghCLI. - Web fallback: when neither is available, a warning is printed and the tool falls back to a pre-filled release page in the browser.
Token and Permissions
The repo scope of a classic Token covers every repository you can access (both in organizations and personal); a fine-grained Token can be limited to specific repositories with permissions granted per feature. The fine-grained Token permissions required by the operations performed by the github plugin are:
| Operation | classic Token | fine-grained Token |
|---|---|---|
| Verify collaborator permissions (when run locally) | repo | Metadata read |
| Create and update Releases | repo | Contents write |
| Read a Release by tag | repo | Contents read |
| Read commits and compare commits (contributor resolution, Release Notes object template) | repo | Contents read |
| Comment automatically on related PRs / issues | repo | Issues write |
| Release-via-PR mode | repo | Pull requests read and write |
TIP
To publish Releases only, granting Contents: Read and write on the target repository is enough. If the organization requires approval for fine-grained Tokens, an organization owner must approve the Token before it can access the organization's repositories. Uploading Release assets (github.assets) with a fine-grained Token has not been tested yet; when you need to upload assets, a classic Token is recommended for now.
Which Host a Token Is Sent To
The host name in the git remote URL may be a mirror or a look-alike domain, so it cannot decide where a Token goes. A Token from an environment variable (GITHUB_TOKEN, or the variable specified by github.tokenRef) is only ever sent to the following three kinds of hosts. The github plugin, Release-via-PR, --sync-releases and contributor username resolution all follow this rule:
- The official domain
github.com; - The
github.hostexplicitly specified in the configuration (GitHub Enterprise); - The address that GitHub Actions declares for itself in environment variables (
GITHUB_SERVER_URLwhenGITHUB_ACTIONS=true, i.e. Actions on a self-hosted instance).
When a Token is present in the environment but the host of the repository is not in this list, the release stops immediately and asks you to specify the host with github.host: the Token is neither sent anywhere nor replaced with other credentials (--dry-run prints the same hint). Credentials of the local gh CLI are not restricted by this rule: gh auth token --hostname <host> reads the Token that was registered with it when logging in to that host.
For example, when git remote points to https://github.example.com/acme/demo.git, this self-hosted instance must be declared explicitly:
{
"github": {
"release": true,
"host": "github.example.com"
}
}Authentication and GitHub Actions
- When run locally, the
initstage verifies that the Token is valid and that the current user is a collaborator on the repository (skip withgithub.skipChecks: true). - When running in GitHub Actions (detected through the
GITHUB_ACTIONSenvironment variable), authentication and collaborator checks are skipped automatically and thesecrets.GITHUB_TOKENinjected by the workflow is used directly (make sure the workflow has thecontents: writepermission; if comments are enabled,issues: write/pull-requests: writeare also required).
Browser Publishing Mode (Web Fallback)
- When
GITHUB_TOKENis not set and theghCLI is not logged in locally, a warning is printed automatically and the tool falls back to browser mode: it opens the GitHub "new Release" page in the default browser, pre-filled with the tag, title, body and pre-release flag. - Setting
github.web: trueforces browser-based publishing and no longer checksGITHUB_TOKENor theghCLI. - When the web mode is used in
--cimode, the browser is not launched; the pre-filled release link is printed instead. - The browser publishing mode does not support uploading
github.assets.
Custom Release Notes
Release notes are determined in the following order of priority:
github.autoGenerate: true: release notes are generated automatically on the GitHub server side (generate_release_notes: true), overriding notes generated locally.github.releaseNotes: three forms of customization are supported:- Shell command string: the command is executed and its standard output is used as the release notes (
${...}template variables are supported; execution is refused when a value contains shell syntax, so useRELEASE_environment variables for multi-line content, see Lifecycle hooks). - Function (JS / TS configuration files only): receives the full context and returns a string or
Promise<string>. - Object template
{ commit, excludeMatches }: calls the GitHub Compare API to fetch the commits since the previous tag and renders them line by line with the template:
- Shell command string: the command is executed and its standard output is used as the release notes (
{
"github": {
"release": true,
"releaseNotes": {
"commit": "* ${commit.subject} (${sha}){ - thanks @${author.login}!}",
"excludeMatches": ["dependabot[bot]", "neosjs-bot"]
}
}
}In the template, ${a.b} is field interpolation; a local fragment wrapped in braces {...} is omitted entirely when it matches any string in excludeMatches.
- Default fallback: the changelog generated by the built-in
changelogplugin is used (ifchangelogproduces no content, it falls back to the output ofgit.logCommand). When the default changelog is used,([@user](https://github.com/user))in the contributor entries at the end is automatically converted to(@user)before being sent to the GitHub Release, so that GitHub renders the native Contributors avatar bar.
Uploading Release Assets
Specify a single file path or an array of glob patterns through github.assets (template variables such as ${version} are supported):
{
"github": {
"release": true,
"assets": [
"dist/*.zip",
"dist/app-${version}.tar.gz"
]
}
}Compatibility with GitHub "Immutable Releases"
When a repository has immutable releases enabled, the GitHub API rejects assets added to a Release after it has been officially published. Therefore, when creating a new Release with github.assets configured, @neosjs/release automatically uses a three-step draft flow:
- Create the Release as a draft (
draft: true) first; - Upload all matching asset files;
- If the configuration is not a draft (
github.draft !== true), update the Release to officially published (draft: false).
Updating an Existing Release
With github.update: true (or --github.update), if the latest Release of the repository corresponds to the current latestTag, the tool updates that Release instead of creating a new one.
This is commonly used to add notes or build assets to a version that has already been released (combine it with --no-increment --no-git to skip the version increment and Git operations):
release --no-increment --no-git --github.release --github.update --github.assets="dist/*.zip"To sync or backfill Releases for multiple historical versions in bulk from CHANGELOG.md, use --sync-releases.
Automatically Commenting on Resolved Issues and Merged PRs
With github.comments.submit: true enabled, after a new Release has been created successfully the tool automatically:
- Parses the issues closed in this changelog (both plain
#12and the Markdown links[#12](https://...)generated by thechangelogplugin are supported); - Extracts the PR numbers pointed to by
/pull/Nlinks in the changelog, and merges them (deduplicated) with merged PRs found by searching commit SHAs; - Posts comments using the
github.comments.issueandgithub.comments.prtemplates in turn.
{
"github": {
"release": true,
"comments": {
"submit": true,
"issue": ":rocket: _This issue has been resolved in ${tagName}. See [${releaseName}](${releaseUrl}) for release notes._",
"pr": ":rocket: _This pull request is included in ${tagName}. See [${releaseName}](${releaseUrl}) for release notes._"
}
}
}Comments are a best-effort extra step: the Release has already been created at this point, and a failing comment or search request only prints a warning/error log without failing the release as a whole.
GitHub Enterprise, Proxy, Timeout and Retry
- GitHub Enterprise: set
github.host: "github.example.com"; the API base URL is resolved automatically tohttps://github.example.com/api/v3. - HTTP(S) proxy:
github.proxy: "http://127.0.0.1:7890": use the specified HTTP/HTTPS proxy.github.proxy: true: read theHTTP_PROXY/HTTPS_PROXY/NO_PROXYenvironment variables automatically.
- Request timeout:
github.timeout(in milliseconds;0means no limit). - Automatic retry: when a retryable status code is encountered (
408,413,429,500,502,503,504,521,522,524), the request is retried automatically up to 2 times; the minimum wait interval is controlled bygithub.retryMinTimeout(default1000milliseconds).
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
github.release | boolean | false | Whether to create a GitHub Release |
github.releaseName | string | 'Release v${version}' | Release title template |
github.releaseNotes | string | Function | object | null | null | Custom release notes (shell command, function or { commit, excludeMatches }) |
github.autoGenerate | boolean | false | Let GitHub generate the release notes automatically (overrides other releaseNotes) |
github.preRelease | boolean | false | Force marking as a pre-release (pre-release version numbers are marked as true automatically) |
github.draft | boolean | false | Create as a draft Release |
github.update | boolean | false | Update the existing Release for the latest tag (also applies to --sync-releases) |
github.tokenRef | string | 'GITHUB_TOKEN' | Name of the environment variable the Token is read from |
github.assets | string | string[] | null | null | Files or glob patterns to upload as Release assets |
github.host | string | null | null | GitHub Enterprise domain |
github.timeout | number | 0 | API request timeout (in milliseconds; 0 for no limit) |
github.proxy | string | boolean | null | null | HTTP(S) proxy URL, or true to read the proxy environment variables |
github.retryMinTimeout | number | 1000 | Minimum interval between retries (in milliseconds) |
github.makeLatest | boolean | 'legacy' | true | Whether to mark it as the repository's Latest Release (set to false when releasing from a maintenance branch) |
github.discussionCategoryName | string | undefined | undefined | Start a GitHub Discussion automatically in the given category when the Release is created |
github.skipChecks | boolean | false | Skip the Token authentication and collaborator permission checks |
github.web | boolean | false | Force opening the release page in the browser (GITHUB_TOKEN is not checked) |
github.comments.submit | boolean | false | Whether to comment automatically on related PRs and resolved issues |
github.comments.issue | string | See below | Issue comment template |
github.comments.pr | string | See below | PR comment template |
Complete Default Configuration
{
github: {
release: false,
releaseName: 'Release v${version}',
releaseNotes: null,
autoGenerate: false,
preRelease: false,
draft: false,
update: false,
tokenRef: 'GITHUB_TOKEN',
assets: null,
host: null,
timeout: 0,
proxy: null,
makeLatest: true,
skipChecks: false,
web: false,
comments: {
submit: false,
issue: ':rocket: _This issue has been resolved in ${tagName}. See [${releaseName}](${releaseUrl}) for release notes._',
pr: ':rocket: _This pull request is included in ${tagName}. See [${releaseName}](${releaseUrl}) for release notes._'
}
}
}