@dyn-temp/version-build
v1.0.4
Published
This repository houses various code utilities involved in the overall CICD workflow - semantic versioning, linting ,etc.
Downloads
2
Readme
#utilities This repository houses various code utilities involved in the overall CICD workflow - semantic versioning, linting ,etc.
versioning tool
Using git commands it will work with the target project's repository to create tags and release branchces. For the first iteration it will generate only minor and patch versions. The major verion flow is yet to be decided.
Every application will implement it's own flow using the functions exposed by the node-version-build tool.
Every application will commit using the Conventional Commits specification. This is important because the node-version-tool will look in the commit message for the structural elements defined by the Conventional Commits specification.
Dependency
Installation
npm install {path_to_repo}
Usage
The module exposes a gitCommands object.
const gitCommands = new GitCommands();
Functions
getTags() Returns the tags list as present in the target repo. Useful to return the last tag. Usually the first step in the repo-specific implementation.
| Sample call | Sample response |
| --- | --- |
| await gitCommands.getTags()
| TagList { all: [ '0.0.1', '0.0.1-beta.0.1' ], latest: '0.0.1-beta.0.1' }
|
getCommitsSinceTag(from) Retruns the list of commits starting with the 'from' parameter. It will disregard the merge commits as they are not important for the versioning process. This function is called by the shouldAdvanceVersion() function to determine what part of the version should be updates.
Sample call: await gitCommands.getCommitsSinceTag(lastTag.latest)
Sample response Commits [
{
hash: '279bfbcb3298b7ffb45b210c15aa38897871a313',
date: '2023-10-18T14:10:50+03:00',
message: 'wip: commit #2',
refs: 'HEAD -> main, tag: 0.0.1-beta.0.1, 0.0.1-beta.0.1',
body: '',
author_name: 'Author One',
author_email: '[email protected]'
},
{
hash: 'e8d7506348d221d5549b9337333f7e68c3924df6',
date: '2023-10-18T13:56:34+03:00',
message: 'wip: new commit',
refs: '',
body: '',
author_name: 'Author two',
author_email: '[email protected]'
}
]
getHead()
Returns the current GIT head hash excluding the merge commits. Used by the getCommitsSinceTag() function.
incremenVersion(tag, part) Returns an increment of the part parameter based on the tag parameter.
Sample Call - major version: gitCommands.incremenVersion('1.0.0', 'major')
Sample response - major version: 2.0.0
Sample Call - minor version: gitCommands.incremenVersion('1.0.0', 'minor')
Sample response - minor version: 1.1.0
Sample Call - patch version: gitCommands.incremenVersion('1.0.0', 'patch')
Sample response - patch version: 1.0.1
createReleaseBranch(branch) Acts on the repository and creates a new branch on the current head, using the naming convention v{branch}. This branch will act as the release candidate. Returns void.
createTag(name) Acts on the repository and creates a new tag on the current head. Returns void.
Sample Usage
import gitCommands from "@version-build/version-build";
const lastTag = await gitCommands.getTags(); // .latest
const commits = await gitCommands.getCommitsSinceTag(lastTag.latest);
// get the needed version update
const shouldAdvanceMajor = await gitCommands.shouldAdvanceVersion(lastTag.latest, 'breaking');
const shouldAdvanceMinor = await gitCommands.shouldAdvanceVersion(lastTag.latest, 'feat');
const shouldAdvancePatch = await gitCommands.shouldAdvanceVersion(lastTag.latest, 'fix');
const result = {
"advenceMajor": false,
"advanceMinor": false,
"advancePatch": false,
"newVersion": null
};
if (shouldAdvanceMajor) {
throw new Error("Major version update! Please contact the system administrator.");
}
if (shouldAdvanceMinor) {
const newVersion = gitCommands.incremenVersion(lastTag.latest, 'minor');
gitCommands.createReleaseBranch(newVersion);
gitCommands.createTag(newVersion);
result.advanceMinor = shouldAdvanceMinor;
result.newVersion = newVersion
}
if (shouldAdvancePatch) {
const newVersion = gitCommands.incremenVersion(lastTag.latest, 'patch');
gitCommands.createReleaseBranch(newVersion);
gitCommands.createTag(newVersion);
result.advancePatch = shouldAdvanceMinor;
result.newVersion = newVersion
}
console.log(result);
8b1e7f3 (versioning and build tool initial commit)