semantic-release plugin to publish a GitHub release and comment on released Pull Requests/Issues
—
Core semantic-release plugin interface functions that handle the complete release workflow from validation to post-release actions. These functions implement the semantic-release plugin specification and are called automatically by semantic-release during the release process.
Validates GitHub authentication, repository permissions, and plugin configuration before starting the release process.
/**
* Validates GitHub authentication and plugin configuration
* @param pluginConfig - Plugin configuration options
* @param context - semantic-release context with env, options, logger
* @param options - Optional Octokit constructor override
* @throws {AggregateError} When validation fails
*/
async function verifyConditions(
pluginConfig: PluginConfig,
context: Context,
options?: { Octokit?: typeof Octokit }
): Promise<void>;Validation Checks:
Usage Example:
// Called automatically by semantic-release, but can be invoked directly
import { verifyConditions } from "@semantic-release/github";
await verifyConditions(
{
assets: ["dist/*.js"],
successComment: "Released in ${nextRelease.version}",
labels: ["semantic-release"]
},
{
env: process.env,
options: { repositoryUrl: "https://github.com/owner/repo.git" },
logger: console
}
);Creates GitHub releases with optional asset uploads and discussion creation.
/**
* Creates GitHub releases and uploads assets
* @param pluginConfig - Plugin configuration options
* @param context - semantic-release context with release information
* @param options - Optional Octokit constructor override
* @returns Release information with URL, name, ID, and discussion URL
*/
async function publish(
pluginConfig: PluginConfig,
context: Context,
options?: { Octokit?: typeof Octokit }
): Promise<ReleaseResult>;Features:
Usage Examples:
// Simple release without assets
const result = await publish(
{},
{
env: process.env,
options: { repositoryUrl: "https://github.com/owner/repo.git" },
branch: { name: "main" },
nextRelease: {
gitTag: "v1.0.0",
name: "1.0.0",
version: "1.0.0",
notes: "## Changes\n- Initial release"
},
logger: console
}
);
// Returns: { url: "https://github.com/owner/repo/releases/tag/v1.0.0", name: "GitHub release", id: 12345 }
// Release with assets and custom templates
const result = await publish(
{
assets: [
{ path: "dist/*.js", label: "JavaScript Distribution" },
{ path: "docs/*.pdf", label: "Documentation" }
],
releaseNameTemplate: "${nextRelease.version} - ${nextRelease.channel || 'stable'}",
releaseBodyTemplate: "## Release Notes\n${nextRelease.notes}\n\n## Assets\nSee attached files",
discussionCategoryName: "Releases"
},
context
);Updates GitHub release pre-release status for channel management in semantic-release workflows.
/**
* Updates GitHub release pre-release status for channel management
* @param pluginConfig - Plugin configuration options
* @param context - semantic-release context with channel information
* @param options - Optional Octokit constructor override
* @returns Release information with URL and name
*/
async function addChannel(
pluginConfig: PluginConfig,
context: Context,
options?: { Octokit?: typeof Octokit }
): Promise<ReleaseResult>;Behavior:
Usage Example:
// Promote a prerelease to stable
const result = await addChannel(
{},
{
env: process.env,
options: { repositoryUrl: "https://github.com/owner/repo.git" },
branch: { name: "main" },
nextRelease: {
gitTag: "v1.0.0",
name: "1.0.0",
notes: "Promoted to stable channel"
},
logger: console
}
);Comments on resolved issues and PRs after successful releases, providing users with release information and closure.
/**
* Comments on resolved issues and PRs after successful release
* @param pluginConfig - Plugin configuration options
* @param context - semantic-release context with commits and release info
* @param options - Optional Octokit constructor override
*/
async function success(
pluginConfig: PluginConfig,
context: Context,
options?: { Octokit?: typeof Octokit }
): Promise<void>;Features:
Usage Example:
await success(
{
successComment: "🎉 This issue has been resolved in version ${nextRelease.version}",
successCommentCondition: "true", // Always comment
releasedLabels: ["released", "v${nextRelease.version}"],
labels: false // Don't add additional labels
},
{
env: process.env,
options: { repositoryUrl: "https://github.com/owner/repo.git" },
commits: [
{ hash: "abc123", message: "fix: resolve issue #42" }
],
nextRelease: { version: "1.0.1", gitTag: "v1.0.1" },
releases: [{ url: "https://github.com/owner/repo/releases/tag/v1.0.1" }],
logger: console
}
);Creates or updates GitHub issues when releases fail, providing detailed error information to maintainers.
/**
* Creates or updates GitHub issues when release fails
* @param pluginConfig - Plugin configuration options
* @param context - semantic-release context with error information
* @param options - Optional Octokit constructor override
*/
async function fail(
pluginConfig: PluginConfig,
context: Context,
options?: { Octokit?: typeof Octokit }
): Promise<void>;Features:
Usage Example:
await fail(
{
failTitle: "Automated release failed 🚨",
failComment: "The release failed with the following error:\n\n${errors[0].message}",
failCommentCondition: "true",
assignees: ["maintainer1", "maintainer2"],
labels: ["bug", "release-failure"]
},
{
env: process.env,
options: { repositoryUrl: "https://github.com/owner/repo.git" },
branch: { name: "main" },
errors: [
new Error("GitHub token expired")
],
logger: console
}
);All plugin lifecycle functions throw AggregateError instances containing one or more SemanticReleaseError objects when validation or execution fails. Common error scenarios include:
try {
await verifyConditions(config, context);
} catch (error) {
if (error instanceof AggregateError) {
error.errors.forEach(err => {
console.error(`${err.code}: ${err.message}`);
console.error(err.details);
});
}
}Install with Tessl CLI
npx tessl i tessl/npm-semantic-release--github