A Strategy to publish NPM packages source controlled in Github.
This strategy will:
- Create a Git tag named after the next version using GitTagCommand
- Switch to a temporary branch using GitSwitchBranchCommand
- Generate a changelog and store it into a file using FileWriterCommand
- Bump the package.json version property to the next version using NpmBumpPackageVersionCommand
- Commit the generated changelog using GitCommitCommand
- Push changelog changes using GitPushBranchCommand
- Switch to back to the initial branch using GitSwitchBranchCommand
- Create a Github pull request to merge release changes using GithubCreatePullRequestCommand
- Create a Github release using GithubCreateReleaseCommand
- Comment on Github issues mentioned in the the release commits using GithubCreateIssueCommentsCommand
- Publish the package to an npm registry using NpmPublishPackageCommand
Type: object literal
Type: Logger
Default: processStdoutLogger
Type: Release
Type: string
Default: origin
Type: GitClient
Default: GitExecaClient
Type: string
Default: undefined
A short-hand to perform git commits using a specific author & committer email and name.
Example:
/*
* The value must be in author format: "NAME <EMAIL>"
*/
{ gitActor: "bot <bot@email.com>" }
It is also possible to explicitly use the equivalent environment variables:
GIT_COMMITTER_NAME: bot
GIT_COMMITTER_EMAIL: bot@email.com
GIT_AUTHOR_NAME: bot
GIT_AUTHOR_EMAIL: bot@email.com
Type: string
Default: process.cwd()
Type: string
Default: options.workingDirectory
The working directory to use for npm commands.
Type: string
Default: ${workingDirectory}/CHANGELOG.md
Type: boolean
Default: true
Regenerate the changelog (next and previous versions).
Type: object literal
An object literal with 3 properties:
{
owner: "abstracter-io",
repo: "atomic-release",
personalAccessToken: "Github personal access token with repository access"
}
Type: object literal
{
// config for "main" branch
main: {
isStableGithubRelease: true // Will not mark the created Github release as "pre release"
npmRegistryDistTag: "latest" // <-- will enable doing: npm install @abstracter/atomic-release ("latest" is the default when installing)
}
// config for "beta" branch
beta: {
isStableGithubRelease: false, // Will mark the created Github release as "pre release" (falsy by default)
npmRegistryDistTag: "unstable" // <-- will enable doing: npm install @abstracter/atomic-release@unstable
}
}
鈩癸笍 聽 GitStrategy options are also applicable.
const { GithubNpmPackageStrategy } = require("@abstracter/atomic-release/strategies");
const { gitSemanticRelease } = require("@abstracter/atomic-release/adapters/git-semantic-release");
const github = {
owner: "abstracter-io",
repo: "atomic-release",
host: "https://github.com",
};
const stableBranchName = "main";
const createRelease = () => {
return gitSemanticRelease({
stableBranchName,
workingDirectory: process.cwd(),
preReleaseBranches: {
beta: "beta",
},
conventionalChangelogWriterContext: {
host: github.host,
owner: github.owner,
repository: github.repo,
repoUrl: `${github.host}//${github.owner}/${github.repo}`,
},
});
};
const createStrategy = (release) => {
return new GithubNpmPackageStrategy({
release,
remote: "origin",
changelogFilePath: `${process.cwd()}/CHANGELOG.md`,
workingDirectory: process.cwd(),
regenerateChangeLog: true,
github: {
repo: github.repo,
owner: github.owner,
personalAccessToken: process.env.GITHUB_PAT_TOKEN,
},
branchConfig: {
[stableBranchName]: {
isStable: true,
npmRegistryDistTag: "latest",
},
beta: {
npmRegistryDistTag: "beta",
},
},
});
};
createRelease().then(createStrategy).then((strategy => strategy.run()));