constsemanticRelease=require("semantic-release");const { WritableStreamBuffer } =require("stream-buffers");conststdoutBuffer=newWritableStreamBuffer();conststderrBuffer=newWritableStreamBuffer();try {constresult=awaitsemanticRelease( {// Core options branches: ["+([0-9])?(.{+([0-9]),x}).x","master","main","next","next-major", { name:"beta", prerelease:true }, { name:"alpha", prerelease:true }, ], repositoryUrl:"https://github.com/me/my-package.git",// Shareable config extends:"my-shareable-config",// Plugin options githubUrl:"https://my-ghe.com", githubApiPathPrefix:"/api-prefix", }, { // Run semantic-release from `/path/to/git/repo/root` without having to change local process `cwd` with `process.chdir()`
cwd:"/path/to/git/repo/root",// Pass the variable `MY_ENV_VAR` to semantic-release without having to modify the local `process.env` env: { ...process.env, MY_ENV_VAR:"MY_ENV_VAR_VALUE" },// Store stdout and stderr to use later instead of writing to `process.stdout` and `process.stderr` stdout: stdoutBuffer, stderr: stderrBuffer, } );if (result) {const { lastRelease,commits,nextRelease,releases } = result;console.log(`Published ${nextRelease.type} release version ${nextRelease.version} containing ${commits.length} commits.` );if (lastRelease.version) {console.log(`The last release was "${lastRelease.version}".`); }for (constreleaseof releases) {console.log(`The release was published with plugin "${release.pluginName}".`); } } else {console.log("No release published."); }// Get stdout and stderr contentconstlogs=stdoutBuffer.getContentsAsString("utf8");consterrors=stderrBuffer.getContentsAsString("utf8");} catch (err) {console.error("The automated release failed with %O", err);}
API
semanticRelease([options], [config]) => Promise
Run semantic-release and returns a Promise that resolves to a Result object.
The list of commit(s) included in the new release.
Each commit object has the following properties:
Example:
[ { commit: { long:'68eb2c4d778050b0701136ca129f837d7ed494d2', short:'68eb2c4' }, tree: { long:'7ab515d12bd2cf431745511ac4ee13fed15ab578', short:'7ab515d' }, author: { name:'Me', email:'me@email.com', date:2018-07-22T20:52:44.000Z }, committer: { name:'Me', email:'me@email.com', date:2018-07-22T20:52:44.000Z }, subject:'feat: a new feature', body:'Description of the new feature', hash:'68eb2c4d778050b0701136ca129f837d7ed494d2', message:'feat: a new feature\n\nDescription of the new feature', committerDate:2018-07-22T20:52:44.000Z } ]
nextRelease
Type: Object
Information related to the newly published release:
Example:
{ type:'minor', gitHead:'68eb2c4d778050b0701136ca129f837d7ed494d2', version:'1.1.0', gitTag:'v1.1.0', notes:'Release notes for version 1.1.0...', channel :'next'}
releases
Type: Array<Object>
The list of releases published or made available to a distribution channel.
Each release object has the following properties:
Example:
[ { name:'GitHub release', url:'https://github.com/me/my-package/releases/tag/v1.1.0', type:'minor', gitHead:'68eb2c4d778050b0701136ca129f837d7ed494d2', version:'1.1.0', gitTag:'v1.1.0', notes:'Release notes for version 1.1.0...', pluginName:'@semantic-release/github' channel: 'next' }, { name:'npm package (@latest dist-tag)', url:'https://www.npmjs.com/package/my-package', type:'minor', gitHead:'68eb2c4d778050b0701136ca129f837d7ed494d2', version:'1.1.0', gitTag:'v1.1.0', notes:'Release notes for version 1.1.0...', pluginName:'@semantic-release/npm' channel: 'next' } ]