Skip to content

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 ​

  1. Enable github.release: true in the configuration file (or pass --github.release on the command line).
  2. 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 repo scope, and note that it covers every repository you can access (the note is pre-filled; feel free to change it to your project name).
  3. Provide the Token through the GITHUB_TOKEN environment variable (never write a Token into a configuration file or commit it to a repository):
bash
export GITHUB_TOKEN="ghp_xxxxxxxxxxxx"
release

To use a different environment variable name, set github.tokenRef:

json
{
  "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):

  1. Environment variable: GITHUB_TOKEN (or the variable name specified by github.tokenRef).
  2. Local gh CLI: when the environment variable is not set, gh auth token is run automatically (with --hostname <host> added automatically for GitHub Enterprise) to read the credentials of the locally logged-in gh CLI.
  3. 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:

Operationclassic Tokenfine-grained Token
Verify collaborator permissions (when run locally)repoMetadata read
Create and update ReleasesrepoContents write
Read a Release by tagrepoContents read
Read commits and compare commits (contributor resolution, Release Notes object template)repoContents read
Comment automatically on related PRs / issuesrepoIssues write
Release-via-PR moderepoPull 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.host explicitly specified in the configuration (GitHub Enterprise);
  • The address that GitHub Actions declares for itself in environment variables (GITHUB_SERVER_URL when GITHUB_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:

json
{
  "github": {
    "release": true,
    "host": "github.example.com"
  }
}

Authentication and GitHub Actions ​

  • When run locally, the init stage verifies that the Token is valid and that the current user is a collaborator on the repository (skip with github.skipChecks: true).
  • When running in GitHub Actions (detected through the GITHUB_ACTIONS environment variable), authentication and collaborator checks are skipped automatically and the secrets.GITHUB_TOKEN injected by the workflow is used directly (make sure the workflow has the contents: write permission; if comments are enabled, issues: write / pull-requests: write are also required).

Browser Publishing Mode (Web Fallback) ​

  • When GITHUB_TOKEN is not set and the gh CLI 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: true forces browser-based publishing and no longer checks GITHUB_TOKEN or the gh CLI.
  • When the web mode is used in --ci mode, 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:

  1. github.autoGenerate: true: release notes are generated automatically on the GitHub server side (generate_release_notes: true), overriding notes generated locally.
  2. 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 use RELEASE_ 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:
json
{
  "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.

  1. Default fallback: the changelog generated by the built-in changelog plugin is used (if changelog produces no content, it falls back to the output of git.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):

json
{
  "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:

  1. Create the Release as a draft (draft: true) first;
  2. Upload all matching asset files;
  3. 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):

bash
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 #12 and the Markdown links [#12](https://...) generated by the changelog plugin are supported);
  • Extracts the PR numbers pointed to by /pull/N links in the changelog, and merges them (deduplicated) with merged PRs found by searching commit SHAs;
  • Posts comments using the github.comments.issue and github.comments.pr templates in turn.
json
{
  "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 to https://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 the HTTP_PROXY / HTTPS_PROXY / NO_PROXY environment variables automatically.
  • Request timeout: github.timeout (in milliseconds; 0 means 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 by github.retryMinTimeout (default 1000 milliseconds).

Configuration Options ​

OptionTypeDefaultDescription
github.releasebooleanfalseWhether to create a GitHub Release
github.releaseNamestring'Release v${version}'Release title template
github.releaseNotesstring | Function | object | nullnullCustom release notes (shell command, function or { commit, excludeMatches })
github.autoGeneratebooleanfalseLet GitHub generate the release notes automatically (overrides other releaseNotes)
github.preReleasebooleanfalseForce marking as a pre-release (pre-release version numbers are marked as true automatically)
github.draftbooleanfalseCreate as a draft Release
github.updatebooleanfalseUpdate the existing Release for the latest tag (also applies to --sync-releases)
github.tokenRefstring'GITHUB_TOKEN'Name of the environment variable the Token is read from
github.assetsstring | string[] | nullnullFiles or glob patterns to upload as Release assets
github.hoststring | nullnullGitHub Enterprise domain
github.timeoutnumber0API request timeout (in milliseconds; 0 for no limit)
github.proxystring | boolean | nullnullHTTP(S) proxy URL, or true to read the proxy environment variables
github.retryMinTimeoutnumber1000Minimum interval between retries (in milliseconds)
github.makeLatestboolean | 'legacy'trueWhether to mark it as the repository's Latest Release (set to false when releasing from a maintenance branch)
github.discussionCategoryNamestring | undefinedundefinedStart a GitHub Discussion automatically in the given category when the Release is created
github.skipChecksbooleanfalseSkip the Token authentication and collaborator permission checks
github.webbooleanfalseForce opening the release page in the browser (GITHUB_TOKEN is not checked)
github.comments.submitbooleanfalseWhether to comment automatically on related PRs and resolved issues
github.comments.issuestringSee belowIssue comment template
github.comments.prstringSee belowPR comment template

Complete Default Configuration ​

ts
{
  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._'
    }
  }
}