mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2026-04-09 09:34:18 +00:00
Rewrite/refactor for v5, migrate to TypeScript (MAJOR)
Set Jest config file in package script Include module path Include tests in project folders Remove index module exports Hardcode configuration parameters Move parameter binding into main run function Use alias imports Run test sequentially Remove cleanup (async conflict) Revert Jest option Increase test timeout to 15 seconds
This commit is contained in:
parent
dc8f0c5755
commit
31f4e3fdf0
74 changed files with 9422 additions and 4342 deletions
29
lib/ActionConfig.js
Normal file
29
lib/ActionConfig.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ActionConfig = void 0;
|
||||
/** Represents the input configuration for the semantic-version action */
|
||||
class ActionConfig {
|
||||
constructor() {
|
||||
/** Set to specify a specific branch, default is the current HEAD */
|
||||
this.branch = "HEAD";
|
||||
/** The prefix to use to identify tags */
|
||||
this.tagPrefix = "v";
|
||||
/** A string which, if present in a git commit, indicates that a change represents a major (breaking) change. Wrap with '/' to match using a regular expression. */
|
||||
this.majorPattern = "(MAJOR)";
|
||||
/** A string which, if present in a git commit, indicates that a change represents a minor (feature) change. Wrap with '/' to match using a regular expression. */
|
||||
this.minorPattern = "(MINOR)";
|
||||
/** Pattern to use when formatting output version */
|
||||
this.versionFormat = '${major}.${minor}.${patch}';
|
||||
/** Path to check for changes. If any changes are detected in the path the 'changed' output will true. Enter multiple paths separated by spaces. */
|
||||
this.changePath = '';
|
||||
/** Use to create a named sub-version. This value will be appended to tags created for this version. */
|
||||
this.namespace = "";
|
||||
/** If true, every commit will be treated as a bump to the version. */
|
||||
this.bumpEachCommit = false;
|
||||
/** If true, the body of commits will also be searched for major/minor patterns to determine the version type */
|
||||
this.searchCommitBody = false;
|
||||
/** The output method used to generate list of users, 'csv' or 'json'. Default is 'csv'. */
|
||||
this.userFormatType = "csv";
|
||||
}
|
||||
}
|
||||
exports.ActionConfig = ActionConfig;
|
||||
60
lib/CommandRunner.js
Normal file
60
lib/CommandRunner.js
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.cmd = void 0;
|
||||
// Using require instead of import to support integration testing
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const cmd = (command, ...args) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
let output = '', errors = '';
|
||||
const options = {
|
||||
silent: true,
|
||||
listeners: {
|
||||
stdout: (data) => { output += data.toString(); },
|
||||
stderr: (data) => { errors += data.toString(); },
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
}
|
||||
};
|
||||
try {
|
||||
yield exec.exec(command, args, options);
|
||||
}
|
||||
catch (err) {
|
||||
//core.info(`The command cd '${command} ${args.join(' ')}' failed: ${err}`);
|
||||
}
|
||||
if (errors !== '') {
|
||||
//core.info(`stderr: ${errors}`);
|
||||
}
|
||||
return output;
|
||||
});
|
||||
exports.cmd = cmd;
|
||||
37
lib/ConfigurationProvider.js
Normal file
37
lib/ConfigurationProvider.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ConfigurationProvider = void 0;
|
||||
const CsvUserFormatter_1 = require("./formatting/CsvUserFormatter");
|
||||
const DefaultTagFormatter_1 = require("./formatting/DefaultTagFormatter");
|
||||
const DefaultVersionFormatter_1 = require("./formatting/DefaultVersionFormatter");
|
||||
const JsonUserFormatter_1 = require("./formatting/JsonUserFormatter");
|
||||
const DefaultCommitsProvider_1 = require("./providers/DefaultCommitsProvider");
|
||||
const DefaultCurrentCommitResolver_1 = require("./providers/DefaultCurrentCommitResolver");
|
||||
const DefaultVersionClassifier_1 = require("./providers/DefaultVersionClassifier");
|
||||
const TagLastReleaseResolver_1 = require("./providers/TagLastReleaseResolver");
|
||||
const BumpAlwaysVersionClassifier_1 = require("./providers/BumpAlwaysVersionClassifier");
|
||||
class ConfigurationProvider {
|
||||
constructor(config) {
|
||||
this.config = config;
|
||||
}
|
||||
GetCurrentCommitResolver() { return new DefaultCurrentCommitResolver_1.DefaultCurrentCommitResolver(this.config); }
|
||||
GetLastReleaseResolver() { return new TagLastReleaseResolver_1.TagLastReleaseResolver(this.config); }
|
||||
GetCommitsProvider() { return new DefaultCommitsProvider_1.DefaultCommitsProvider(this.config); }
|
||||
GetVersionClassifier() {
|
||||
if (this.config.bumpEachCommit) {
|
||||
return new BumpAlwaysVersionClassifier_1.BumpAlwaysVersionClassifier(this.config);
|
||||
}
|
||||
return new DefaultVersionClassifier_1.DefaultVersionClassifier(this.config);
|
||||
}
|
||||
GetVersionFormatter() { return new DefaultVersionFormatter_1.DefaultVersionFormatter(this.config); }
|
||||
GetTagFormatter() { return new DefaultTagFormatter_1.DefaultTagFormatter(this.config); }
|
||||
GetUserFormatter() {
|
||||
switch (this.config.userFormatType) {
|
||||
case 'json': return new JsonUserFormatter_1.JsonUserFormatter(this.config);
|
||||
case 'csv': return new CsvUserFormatter_1.CsvUserFormatter(this.config);
|
||||
default:
|
||||
throw new Error(`Unknown user format type: ${this.config.userFormatType}, supported types: json, csv`);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.ConfigurationProvider = ConfigurationProvider;
|
||||
30
lib/VersionResult.js
Normal file
30
lib/VersionResult.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VersionResult = void 0;
|
||||
/** Represents the total output for the action */
|
||||
class VersionResult {
|
||||
/**
|
||||
* Creates a new result instance
|
||||
* @param major - The major version number
|
||||
* @param minor - The minor version number
|
||||
* @param patch - The patch version number
|
||||
* @param increment - The number of commits for this version (usually used to create version suffix)
|
||||
* @param formattedVersion - The formatted semantic version
|
||||
* @param versionTag - The string to be used as a Git tag
|
||||
* @param changed - True if the version was changed, otherwise false
|
||||
* @param authors - Authors formatted according to the format mode (e.g. JSON, CSV, YAML, etc.)
|
||||
* @param currentCommit - The current commit hash
|
||||
*/
|
||||
constructor(major, minor, patch, increment, formattedVersion, versionTag, changed, authors, currentCommit) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
this.increment = increment;
|
||||
this.formattedVersion = formattedVersion;
|
||||
this.versionTag = versionTag;
|
||||
this.changed = changed;
|
||||
this.authors = authors;
|
||||
this.currentCommit = currentCommit;
|
||||
}
|
||||
}
|
||||
exports.VersionResult = VersionResult;
|
||||
52
lib/action.js
Normal file
52
lib/action.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runAction = void 0;
|
||||
const VersionResult_1 = require("./VersionResult");
|
||||
const VersionType_1 = require("./providers/VersionType");
|
||||
const UserInfo_1 = require("./providers/UserInfo");
|
||||
const VersionInformation_1 = require("./providers/VersionInformation");
|
||||
function runAction(configurationProvider) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const currentCommitResolver = configurationProvider.GetCurrentCommitResolver();
|
||||
const lastReleaseResolver = configurationProvider.GetLastReleaseResolver();
|
||||
const commitsProvider = configurationProvider.GetCommitsProvider();
|
||||
const versionClassifier = configurationProvider.GetVersionClassifier();
|
||||
const versionFormatter = configurationProvider.GetVersionFormatter();
|
||||
const tagFormmater = configurationProvider.GetTagFormatter();
|
||||
const userFormatter = configurationProvider.GetUserFormatter();
|
||||
if (yield currentCommitResolver.IsEmptyRepoAsync()) {
|
||||
let versionInfo = new VersionInformation_1.VersionInformation(0, 0, 0, 0, VersionType_1.VersionType.None, [], false);
|
||||
return new VersionResult_1.VersionResult(versionInfo.major, versionInfo.minor, versionInfo.patch, versionInfo.increment, versionFormatter.Format(versionInfo), tagFormmater.Format(versionInfo), versionInfo.changed, userFormatter.Format('author', []), '');
|
||||
}
|
||||
const currentCommit = yield currentCommitResolver.ResolveAsync();
|
||||
const lastRelease = yield lastReleaseResolver.ResolveAsync(currentCommit, tagFormmater);
|
||||
const commitSet = yield commitsProvider.GetCommitsAsync(lastRelease.hash, currentCommit);
|
||||
const classification = yield versionClassifier.ClassifyAsync(lastRelease, commitSet);
|
||||
const { major, minor, patch, increment, type, changed } = classification;
|
||||
// At this point all necessary data has been pulled from the database, create
|
||||
// version information to be used by the formatters
|
||||
let versionInfo = new VersionInformation_1.VersionInformation(major, minor, patch, increment, type, commitSet.commits, changed);
|
||||
// Group all the authors together, count the number of commits per author
|
||||
const allAuthors = versionInfo.commits
|
||||
.reduce((acc, commit) => {
|
||||
const key = `${commit.author} <${commit.authorEmail}>`;
|
||||
acc[key] = acc[key] || { n: commit.author, e: commit.authorEmail, c: 0 };
|
||||
acc[key].c++;
|
||||
return acc;
|
||||
}, {});
|
||||
const authors = Object.values(allAuthors)
|
||||
.map((u) => new UserInfo_1.UserInfo(u.n, u.e, u.c))
|
||||
.sort((a, b) => b.commits - a.commits);
|
||||
return new VersionResult_1.VersionResult(versionInfo.major, versionInfo.minor, versionInfo.patch, versionInfo.increment, versionFormatter.Format(versionInfo), tagFormmater.Format(versionInfo), versionInfo.changed, userFormatter.Format('author', authors), currentCommit);
|
||||
});
|
||||
}
|
||||
exports.runAction = runAction;
|
||||
12
lib/formatting/CsvUserFormatter.js
Normal file
12
lib/formatting/CsvUserFormatter.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CsvUserFormatter = void 0;
|
||||
class CsvUserFormatter {
|
||||
constructor(config) {
|
||||
// placeholder for consistency with other formatters
|
||||
}
|
||||
Format(type, users) {
|
||||
return users.map(user => `${user.name} <${user.email}>`).join(', ');
|
||||
}
|
||||
}
|
||||
exports.CsvUserFormatter = CsvUserFormatter;
|
||||
51
lib/formatting/DefaultTagFormatter.js
Normal file
51
lib/formatting/DefaultTagFormatter.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DefaultTagFormatter = void 0;
|
||||
/** Default tag formatter which allows a prefix to be specified */
|
||||
class DefaultTagFormatter {
|
||||
constructor(config) {
|
||||
this.namespace = config.namespace;
|
||||
this.tagPrefix = config.tagPrefix;
|
||||
this.namespaceSeperator = '-'; // maybe make configurable in the future
|
||||
}
|
||||
Format(versionInfo) {
|
||||
const result = `${this.tagPrefix}${versionInfo.major}.${versionInfo.minor}.${versionInfo.patch}`;
|
||||
if (!!this.namespace) {
|
||||
return `${result}${this.namespaceSeperator}${this.namespace}`;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
GetPattern() {
|
||||
if (!!this.namespace) {
|
||||
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]${this.namespaceSeperator}${this.namespace}`;
|
||||
}
|
||||
return `${this.tagPrefix}*[0-9].*[0-9].*[0-9]`;
|
||||
}
|
||||
Parse(tag) {
|
||||
let stripedTag;
|
||||
if (this.tagPrefix.includes('/') && tag.includes(this.tagPrefix)) {
|
||||
let tagParts = tag
|
||||
.replace(this.tagPrefix, '<--!PREFIX!-->')
|
||||
.split('/');
|
||||
stripedTag = tagParts[tagParts.length - 1]
|
||||
.replace('<--!PREFIX!-->', this.tagPrefix);
|
||||
}
|
||||
else {
|
||||
let tagParts = tag.split('/');
|
||||
stripedTag = tagParts[tagParts.length - 1];
|
||||
}
|
||||
let versionValues = stripedTag
|
||||
.substring(this.tagPrefix.length)
|
||||
.slice(0, this.namespace === '' ? 999 : -(this.namespace.length + 1))
|
||||
.split('.');
|
||||
let major = parseInt(versionValues[0]);
|
||||
let minor = versionValues.length > 1 ? parseInt(versionValues[1]) : 0;
|
||||
let patch = versionValues.length > 2 ? parseInt(versionValues[2]) : 0;
|
||||
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
||||
throw `Invalid tag ${tag} (${versionValues})`;
|
||||
}
|
||||
return [major, minor, patch];
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.DefaultTagFormatter = DefaultTagFormatter;
|
||||
16
lib/formatting/DefaultVersionFormatter.js
Normal file
16
lib/formatting/DefaultVersionFormatter.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DefaultVersionFormatter = void 0;
|
||||
class DefaultVersionFormatter {
|
||||
constructor(config) {
|
||||
this.formatString = config.versionFormat;
|
||||
}
|
||||
Format(versionInfo) {
|
||||
return this.formatString
|
||||
.replace('${major}', versionInfo.major.toString())
|
||||
.replace('${minor}', versionInfo.minor.toString())
|
||||
.replace('${patch}', versionInfo.patch.toString())
|
||||
.replace('${increment}', versionInfo.increment.toString());
|
||||
}
|
||||
}
|
||||
exports.DefaultVersionFormatter = DefaultVersionFormatter;
|
||||
13
lib/formatting/JsonUserFormatter.js
Normal file
13
lib/formatting/JsonUserFormatter.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JsonUserFormatter = void 0;
|
||||
class JsonUserFormatter {
|
||||
constructor(config) {
|
||||
// placeholder for consistency with other formatters
|
||||
}
|
||||
Format(type, users) {
|
||||
let result = users.map(u => ({ name: u.name, email: u.email }));
|
||||
return JSON.stringify(result).replace('\n', '');
|
||||
}
|
||||
}
|
||||
exports.JsonUserFormatter = JsonUserFormatter;
|
||||
2
lib/formatting/TagFormatter.js
Normal file
2
lib/formatting/TagFormatter.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
2
lib/formatting/UserFormatter.js
Normal file
2
lib/formatting/UserFormatter.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
2
lib/formatting/VersionFormatter.js
Normal file
2
lib/formatting/VersionFormatter.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
16
lib/formatting/YamlUserFormatter.js
Normal file
16
lib/formatting/YamlUserFormatter.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.YamlUserFormatter = void 0;
|
||||
class YamlUserFormatter {
|
||||
constructor(config) {
|
||||
this.lineBreak = config.userFormatLineBreak || '\n';
|
||||
this.includeType = config.includeType || false;
|
||||
}
|
||||
Format(type, users) {
|
||||
const result = users.flatMap(u => [`- name: "${u.name}"`, ` email: "${u.email}"`]).join(this.lineBreak);
|
||||
return this.includeType ?
|
||||
`${type}:${this.lineBreak}${result}` :
|
||||
result;
|
||||
}
|
||||
}
|
||||
exports.YamlUserFormatter = YamlUserFormatter;
|
||||
11
lib/formatting/index.js
Normal file
11
lib/formatting/index.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JsonUserFormatter = exports.DefaultVersionFormatter = exports.DefaultTagFormatter = exports.CsvUserFormatter = void 0;
|
||||
var CsvUserFormatter_1 = require("./CsvUserFormatter");
|
||||
Object.defineProperty(exports, "CsvUserFormatter", { enumerable: true, get: function () { return CsvUserFormatter_1.CsvUserFormatter; } });
|
||||
var DefaultTagFormatter_1 = require("./DefaultTagFormatter");
|
||||
Object.defineProperty(exports, "DefaultTagFormatter", { enumerable: true, get: function () { return DefaultTagFormatter_1.DefaultTagFormatter; } });
|
||||
var DefaultVersionFormatter_1 = require("./DefaultVersionFormatter");
|
||||
Object.defineProperty(exports, "DefaultVersionFormatter", { enumerable: true, get: function () { return DefaultVersionFormatter_1.DefaultVersionFormatter; } });
|
||||
var JsonUserFormatter_1 = require("./JsonUserFormatter");
|
||||
Object.defineProperty(exports, "JsonUserFormatter", { enumerable: true, get: function () { return JsonUserFormatter_1.JsonUserFormatter; } });
|
||||
85
lib/main.js
Normal file
85
lib/main.js
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.run = void 0;
|
||||
const action_1 = require("./action");
|
||||
const ConfigurationProvider_1 = require("./ConfigurationProvider");
|
||||
const core = __importStar(require("@actions/core"));
|
||||
function setOutput(versionResult) {
|
||||
const { major, minor, patch, increment, formattedVersion, versionTag, changed, authors, currentCommit } = versionResult;
|
||||
const repository = process.env.GITHUB_REPOSITORY;
|
||||
if (!changed) {
|
||||
core.info('No changes detected for this commit');
|
||||
}
|
||||
core.info(`Version is ${formattedVersion}`);
|
||||
if (repository !== undefined) {
|
||||
core.info(`To create a release for this version, go to https://github.com/${repository}/releases/new?tag=${versionTag}&target=${currentCommit.split('/').slice(-1)[0]}`);
|
||||
}
|
||||
core.setOutput("version", formattedVersion);
|
||||
core.setOutput("major", major.toString());
|
||||
core.setOutput("minor", minor.toString());
|
||||
core.setOutput("patch", patch.toString());
|
||||
core.setOutput("increment", increment.toString());
|
||||
core.setOutput("changed", changed.toString());
|
||||
core.setOutput("version_tag", versionTag);
|
||||
core.setOutput("authors", authors);
|
||||
}
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const config = {
|
||||
branch: core.getInput('branch'),
|
||||
tagPrefix: core.getInput('tag_prefix'),
|
||||
majorPattern: core.getInput('major_pattern'),
|
||||
minorPattern: core.getInput('minor_pattern'),
|
||||
versionFormat: core.getInput('version_format'),
|
||||
changePath: core.getInput('change_path'),
|
||||
namespace: core.getInput('namespace'),
|
||||
bumpEachCommit: core.getInput('bump_each_commit') === 'true',
|
||||
searchCommitBody: core.getInput('search_commit_body') === 'true',
|
||||
userFormatType: core.getInput('user_format_type')
|
||||
};
|
||||
if (config.versionFormat === '' && core.getInput('format') !== '') {
|
||||
core.warning(`The 'format' input is deprecated, use 'versionFormat' instead`);
|
||||
config.versionFormat = core.getInput('format');
|
||||
}
|
||||
if (core.getInput('short_tags') !== '') {
|
||||
core.warning(`The 'short_tags' input option is no longer supported`);
|
||||
}
|
||||
const configurationProvider = new ConfigurationProvider_1.ConfigurationProvider(config);
|
||||
const result = yield (0, action_1.runAction)(configurationProvider);
|
||||
setOutput(result);
|
||||
});
|
||||
}
|
||||
exports.run = run;
|
||||
run();
|
||||
52
lib/providers/BumpAlwaysVersionClassifier.js
Normal file
52
lib/providers/BumpAlwaysVersionClassifier.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BumpAlwaysVersionClassifier = void 0;
|
||||
const DefaultVersionClassifier_1 = require("./DefaultVersionClassifier");
|
||||
const VersionClassification_1 = require("./VersionClassification");
|
||||
const VersionType_1 = require("./VersionType");
|
||||
class BumpAlwaysVersionClassifier extends DefaultVersionClassifier_1.DefaultVersionClassifier {
|
||||
constructor(config) {
|
||||
super(config);
|
||||
// Placeholder for consistency
|
||||
}
|
||||
ClassifyAsync(lastRelease, commitSet) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (lastRelease.currentPatch !== null) {
|
||||
return new VersionClassification_1.VersionClassification(VersionType_1.VersionType.None, 0, false, lastRelease.currentMajor, lastRelease.currentMinor, lastRelease.currentPatch);
|
||||
}
|
||||
let { major, minor, patch } = lastRelease;
|
||||
let type = VersionType_1.VersionType.None;
|
||||
if (commitSet.commits.length === 0) {
|
||||
return new VersionClassification_1.VersionClassification(type, 0, false, major, minor, patch);
|
||||
}
|
||||
for (let commit of commitSet.commits.reverse()) {
|
||||
if (this.majorPattern(commit)) {
|
||||
major += 1;
|
||||
minor = 0;
|
||||
patch = 0;
|
||||
type = VersionType_1.VersionType.Major;
|
||||
}
|
||||
else if (this.minorPattern(commit)) {
|
||||
minor += 1;
|
||||
patch = 0;
|
||||
type = VersionType_1.VersionType.Minor;
|
||||
}
|
||||
else {
|
||||
patch += 1;
|
||||
type = VersionType_1.VersionType.Patch;
|
||||
}
|
||||
}
|
||||
return new VersionClassification_1.VersionClassification(type, 0, true, major, minor, patch);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.BumpAlwaysVersionClassifier = BumpAlwaysVersionClassifier;
|
||||
32
lib/providers/CommitInfo.js
Normal file
32
lib/providers/CommitInfo.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CommitInfo = void 0;
|
||||
/** Represents information about a commit */
|
||||
class CommitInfo {
|
||||
/**
|
||||
* Creates a new commit information instance
|
||||
* @param hash - The hash of the commit
|
||||
* @param subject - The subject of the commit message
|
||||
* @param body - The body of the commit message
|
||||
* @param author - The author's name
|
||||
* @param authorEmail - The author's email
|
||||
* @param authorDate - The date the commit was authored
|
||||
* @param committer - The committer's name
|
||||
* @param committerEmail - The committer's email
|
||||
* @param committerDate - The date the commit was committed
|
||||
* @param tags - List of any tags associated with this commit
|
||||
*/
|
||||
constructor(hash, subject, body, author, authorEmail, authorDate, committer, committerEmail, committerDate, tags) {
|
||||
this.hash = hash;
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
this.author = author;
|
||||
this.authorEmail = authorEmail;
|
||||
this.authorDate = authorDate;
|
||||
this.committer = committer;
|
||||
this.committerEmail = committerEmail;
|
||||
this.committerDate = committerDate;
|
||||
this.tags = tags;
|
||||
}
|
||||
}
|
||||
exports.CommitInfo = CommitInfo;
|
||||
11
lib/providers/CommitInfoSet.js
Normal file
11
lib/providers/CommitInfoSet.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CommitInfoSet = void 0;
|
||||
/** Represents information about a set of commits */
|
||||
class CommitInfoSet {
|
||||
constructor(changed, commits) {
|
||||
this.changed = changed;
|
||||
this.commits = commits;
|
||||
}
|
||||
}
|
||||
exports.CommitInfoSet = CommitInfoSet;
|
||||
2
lib/providers/CommitsProvider.js
Normal file
2
lib/providers/CommitsProvider.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
2
lib/providers/CurrentCommitResolver.js
Normal file
2
lib/providers/CurrentCommitResolver.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
79
lib/providers/DefaultCommitsProvider.js
Normal file
79
lib/providers/DefaultCommitsProvider.js
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DefaultCommitsProvider = void 0;
|
||||
const CommandRunner_1 = require("../CommandRunner");
|
||||
const CommitInfo_1 = require("./CommitInfo");
|
||||
const CommitInfoSet_1 = require("./CommitInfoSet");
|
||||
class DefaultCommitsProvider {
|
||||
constructor(config) {
|
||||
this.changePath = config.changePath;
|
||||
}
|
||||
GetCommitsAsync(startHash, endHash) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const logSplitter = `@@@START_RECORD`;
|
||||
const formatPlaceholders = Object.entries({
|
||||
hash: '%H',
|
||||
subject: '%s',
|
||||
body: '%b',
|
||||
author: '%an',
|
||||
authorEmail: '%ae',
|
||||
authorDate: '%aI',
|
||||
committer: '%cn',
|
||||
committerEmail: '%ce',
|
||||
committerDate: '%cI',
|
||||
tags: '%d'
|
||||
});
|
||||
const pretty = logSplitter + '%n' + formatPlaceholders
|
||||
.map(x => `@@@${x[0]}%n${x[1]}`)
|
||||
.join('%n');
|
||||
var logCommand = `git log --pretty="${pretty}" --author-date-order ${(startHash === '' ? endHash : `${startHash}..${endHash}`)}`;
|
||||
if (this.changePath !== '') {
|
||||
logCommand += ` -- ${this.changePath}`;
|
||||
}
|
||||
const log = yield (0, CommandRunner_1.cmd)(logCommand);
|
||||
const entries = log
|
||||
.split(logSplitter)
|
||||
.slice(1);
|
||||
const commits = entries.map(entry => {
|
||||
const fields = entry
|
||||
.split(`@@@`)
|
||||
.slice(1)
|
||||
.reduce((acc, value) => {
|
||||
const firstLine = value.indexOf('\n');
|
||||
const key = value.substring(0, firstLine);
|
||||
acc[key] = value.substring(firstLine + 1).trim();
|
||||
return acc;
|
||||
}, {});
|
||||
const tags = fields.tags
|
||||
.split(',')
|
||||
.map((v) => v.trim())
|
||||
.filter((v) => v.startsWith('tags: '))
|
||||
.map((v) => v.substring(5).trim());
|
||||
return new CommitInfo_1.CommitInfo(fields.hash, fields.subject, fields.body, fields.author, fields.authorEmail, new Date(fields.authorDate), fields.committer, fields.committerEmail, new Date(fields.committerDate), tags);
|
||||
});
|
||||
// check for changes
|
||||
let changed = true;
|
||||
if (this.changePath !== '') {
|
||||
if (startHash === '') {
|
||||
const changedFiles = yield (0, CommandRunner_1.cmd)(`git log --name-only --oneline ${endHash} -- ${this.changePath}`);
|
||||
changed = changedFiles.length > 0;
|
||||
}
|
||||
else {
|
||||
const changedFiles = yield (0, CommandRunner_1.cmd)(`git diff --name-only ${startHash}..${endHash} -- ${this.changePath}`);
|
||||
changed = changedFiles.length > 0;
|
||||
}
|
||||
}
|
||||
return new CommitInfoSet_1.CommitInfoSet(changed, commits);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.DefaultCommitsProvider = DefaultCommitsProvider;
|
||||
33
lib/providers/DefaultCurrentCommitResolver.js
Normal file
33
lib/providers/DefaultCurrentCommitResolver.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DefaultCurrentCommitResolver = void 0;
|
||||
const CommandRunner_1 = require("../CommandRunner");
|
||||
class DefaultCurrentCommitResolver {
|
||||
constructor(config) {
|
||||
this.branch = config.branch;
|
||||
}
|
||||
ResolveAsync() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (this.branch === 'HEAD') {
|
||||
return (yield (0, CommandRunner_1.cmd)('git', 'rev-parse', 'HEAD')).trim();
|
||||
}
|
||||
return this.branch;
|
||||
});
|
||||
}
|
||||
IsEmptyRepoAsync() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let lastCommitAll = (yield (0, CommandRunner_1.cmd)('git', 'rev-list', '-n1', '--all')).trim();
|
||||
return lastCommitAll === '';
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.DefaultCurrentCommitResolver = DefaultCurrentCommitResolver;
|
||||
90
lib/providers/DefaultVersionClassifier.js
Normal file
90
lib/providers/DefaultVersionClassifier.js
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DefaultVersionClassifier = void 0;
|
||||
const VersionClassification_1 = require("./VersionClassification");
|
||||
const VersionType_1 = require("./VersionType");
|
||||
class DefaultVersionClassifier {
|
||||
constructor(config) {
|
||||
const searchBody = config.searchCommitBody;
|
||||
this.majorPattern = this.parsePattern(config.majorPattern, searchBody);
|
||||
this.minorPattern = this.parsePattern(config.minorPattern, searchBody);
|
||||
}
|
||||
parsePattern(pattern, searchBody) {
|
||||
if (pattern.startsWith('/') && pattern.endsWith('/')) {
|
||||
var regex = new RegExp(pattern.slice(1, -1));
|
||||
return searchBody ?
|
||||
(commit) => regex.test(commit.subject) || regex.test(commit.body) :
|
||||
(commit) => regex.test(commit.subject);
|
||||
}
|
||||
else {
|
||||
const matchString = pattern;
|
||||
return searchBody ?
|
||||
(commit) => commit.subject.includes(matchString) || commit.body.includes(matchString) :
|
||||
(commit) => commit.subject.includes(matchString);
|
||||
}
|
||||
}
|
||||
getNextVersion(current, type) {
|
||||
switch (type) {
|
||||
case VersionType_1.VersionType.Major:
|
||||
return { major: current.major + 1, minor: 0, patch: 0 };
|
||||
case VersionType_1.VersionType.Minor:
|
||||
return { major: current.major, minor: current.minor + 1, patch: 0 };
|
||||
case VersionType_1.VersionType.Patch:
|
||||
return { major: current.major, minor: current.minor, patch: current.patch + 1 };
|
||||
case VersionType_1.VersionType.None:
|
||||
return { major: current.major, minor: current.minor, patch: current.patch };
|
||||
default:
|
||||
throw new Error(`Unknown change type: ${type}`);
|
||||
}
|
||||
}
|
||||
resolveCommitType(commitsSet) {
|
||||
if (commitsSet.commits.length === 0) {
|
||||
return { type: VersionType_1.VersionType.None, increment: 0, changed: commitsSet.changed };
|
||||
}
|
||||
const commits = commitsSet.commits.reverse();
|
||||
let index = 1;
|
||||
for (let commit of commits) {
|
||||
if (this.majorPattern(commit)) {
|
||||
return { type: VersionType_1.VersionType.Major, increment: commits.length - index, changed: commitsSet.changed };
|
||||
}
|
||||
index++;
|
||||
}
|
||||
index = 1;
|
||||
for (let commit of commits) {
|
||||
if (this.minorPattern(commit)) {
|
||||
return { type: VersionType_1.VersionType.Minor, increment: commits.length - index, changed: commitsSet.changed };
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return { type: VersionType_1.VersionType.Patch, increment: commitsSet.commits.length - 1, changed: true };
|
||||
}
|
||||
ClassifyAsync(lastRelease, commitSet) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { type, increment, changed } = this.resolveCommitType(commitSet);
|
||||
const { major, minor, patch } = this.getNextVersion(lastRelease, type);
|
||||
if (lastRelease.currentPatch !== null) {
|
||||
// If the current commit is tagged, we must use that version. Here we check if the version we have resolved from the
|
||||
// previous commits is the same as the current version. If it is, we will use the increment value, otherwise we reset
|
||||
// to zero. For example:
|
||||
// - commit 1 - v1.0.0+0
|
||||
// - commit 2 - v1.0.0+1
|
||||
// - commit 3 was tagged v2.0.0 - v2.0.0+0
|
||||
// - commit 4 - v2.0.1+0
|
||||
const versionsMatch = lastRelease.currentMajor === major && lastRelease.currentMinor === minor && lastRelease.currentPatch === patch;
|
||||
const currentIncremement = versionsMatch ? increment : 0;
|
||||
return new VersionClassification_1.VersionClassification(VersionType_1.VersionType.None, currentIncremement, false, lastRelease.currentMajor, lastRelease.currentMinor, lastRelease.currentPatch);
|
||||
}
|
||||
return new VersionClassification_1.VersionClassification(type, increment, changed, major, minor, patch);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.DefaultVersionClassifier = DefaultVersionClassifier;
|
||||
2
lib/providers/LastReleaseResolver.js
Normal file
2
lib/providers/LastReleaseResolver.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
26
lib/providers/ReleaseInformation.js
Normal file
26
lib/providers/ReleaseInformation.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ReleaseInformation = void 0;
|
||||
// Finds the hash of the last commit
|
||||
class ReleaseInformation {
|
||||
/**
|
||||
* Creates a new instance
|
||||
* @param major - the major version number
|
||||
* @param minor - the minor version number
|
||||
* @param patch - the patch version number
|
||||
* @param hash - the hash of commit of the last release
|
||||
* @param currentMajor - the major version number from the current commit
|
||||
* @param currentMinor - the minor version number from the current commit
|
||||
* @param currentPatch - the patch version number from the current commit
|
||||
*/
|
||||
constructor(major, minor, patch, hash, currentMajor, currentMinor, currentPatch) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
this.hash = hash;
|
||||
this.currentMajor = currentMajor;
|
||||
this.currentMinor = currentMinor;
|
||||
this.currentPatch = currentPatch;
|
||||
}
|
||||
}
|
||||
exports.ReleaseInformation = ReleaseInformation;
|
||||
72
lib/providers/TagLastReleaseResolver.js
Normal file
72
lib/providers/TagLastReleaseResolver.js
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TagLastReleaseResolver = void 0;
|
||||
const CommandRunner_1 = require("../CommandRunner");
|
||||
const ReleaseInformation_1 = require("./ReleaseInformation");
|
||||
const core = __importStar(require("@actions/core"));
|
||||
class TagLastReleaseResolver {
|
||||
constructor(config) {
|
||||
this.changePath = config.changePath;
|
||||
}
|
||||
ResolveAsync(current, tagFormatter) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const releasePattern = tagFormatter.GetPattern();
|
||||
let currentTag = (yield (0, CommandRunner_1.cmd)(`git tag --points-at ${current} ${releasePattern}`)).trim();
|
||||
const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null];
|
||||
let tag = '';
|
||||
try {
|
||||
tag = (yield (0, CommandRunner_1.cmd)('git', `describe`, `--tags`, `--abbrev=0`, `--match=${releasePattern}`, `${current}~1`)).trim();
|
||||
}
|
||||
catch (err) {
|
||||
tag = '';
|
||||
}
|
||||
if (tag === '') {
|
||||
if ((yield (0, CommandRunner_1.cmd)('git', 'remote')) !== '') {
|
||||
// Since there is no remote, we assume that there are no other tags to pull. In
|
||||
// practice this isn't likely to happen, but it keeps the test output from being
|
||||
// polluted with a bunch of warnings.
|
||||
core.warning('No tags are present for this repository. If this is unexpected, check to ensure that tags have been pulled from the remote.');
|
||||
}
|
||||
// no release tags yet, use the initial commit as the root
|
||||
return new ReleaseInformation_1.ReleaseInformation(0, 0, 0, '', currentMajor, currentMinor, currentPatch);
|
||||
}
|
||||
// parse the version tag
|
||||
const [major, minor, patch] = tagFormatter.Parse(tag);
|
||||
const root = yield (0, CommandRunner_1.cmd)('git', `merge-base`, tag, current);
|
||||
return new ReleaseInformation_1.ReleaseInformation(major, minor, patch, root.trim(), currentMajor, currentMinor, currentPatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.TagLastReleaseResolver = TagLastReleaseResolver;
|
||||
18
lib/providers/UserInfo.js
Normal file
18
lib/providers/UserInfo.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UserInfo = void 0;
|
||||
/** Represents information about a user (e.g. committer, author, tagger) */
|
||||
class UserInfo {
|
||||
/**
|
||||
* Creates a new instance
|
||||
* @param name - User's name
|
||||
* @param email - User's email
|
||||
* @param commits - Number of commits in the scope evaluated
|
||||
*/
|
||||
constructor(name, email, commits) {
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
this.commits = commits;
|
||||
}
|
||||
}
|
||||
exports.UserInfo = UserInfo;
|
||||
24
lib/providers/VersionClassification.js
Normal file
24
lib/providers/VersionClassification.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VersionClassification = void 0;
|
||||
/** The result of a version classification */
|
||||
class VersionClassification {
|
||||
/**
|
||||
* Creates a new version classification result instance
|
||||
* @param type - The type of change the current range represents
|
||||
* @param increment - The number of commits which have this version, usually zero-based
|
||||
* @param changed - True if the version has changed, false otherwise
|
||||
* @param major - The major version number
|
||||
* @param minor - The minor version number
|
||||
* @param patch - The patch version number
|
||||
*/
|
||||
constructor(type, increment, changed, major, minor, patch) {
|
||||
this.type = type;
|
||||
this.increment = increment;
|
||||
this.changed = changed;
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
}
|
||||
}
|
||||
exports.VersionClassification = VersionClassification;
|
||||
2
lib/providers/VersionClassifier.js
Normal file
2
lib/providers/VersionClassifier.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
29
lib/providers/VersionInformation.js
Normal file
29
lib/providers/VersionInformation.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VersionInformation = void 0;
|
||||
/**
|
||||
* Represents the "resolved" information about a version change, serves
|
||||
* as the input to formatters that produce the final output
|
||||
*/
|
||||
class VersionInformation {
|
||||
/**
|
||||
* Creates a new version information instance
|
||||
* @param major - The major version number
|
||||
* @param minor - The minor version number
|
||||
* @param patch - The patch version number
|
||||
* @param increment - The number of commits for this version
|
||||
* @param type - The type of change the current range represents
|
||||
* @param commits - The list of commits for this version
|
||||
* @param changed - True if the version has changed, false otherwise
|
||||
*/
|
||||
constructor(major, minor, patch, increment, type, commits, changed) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
this.increment = increment;
|
||||
this.type = type;
|
||||
this.commits = commits;
|
||||
this.changed = changed;
|
||||
}
|
||||
}
|
||||
exports.VersionInformation = VersionInformation;
|
||||
15
lib/providers/VersionType.js
Normal file
15
lib/providers/VersionType.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VersionType = void 0;
|
||||
/** Indicates the type of change a particular version change represents */
|
||||
var VersionType;
|
||||
(function (VersionType) {
|
||||
/** Indicates a major version change */
|
||||
VersionType[VersionType["Major"] = 0] = "Major";
|
||||
/** Indicates a minor version change */
|
||||
VersionType[VersionType["Minor"] = 1] = "Minor";
|
||||
/** Indicates a patch version change */
|
||||
VersionType[VersionType["Patch"] = 2] = "Patch";
|
||||
/** Indicates no change--generally this means that the current commit is already tagged with a version */
|
||||
VersionType[VersionType["None"] = 3] = "None";
|
||||
})(VersionType = exports.VersionType || (exports.VersionType = {}));
|
||||
23
lib/providers/index.js
Normal file
23
lib/providers/index.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VersionType = exports.VersionInformation = exports.VersionClassification = exports.UserInfo = exports.TagLastReleaseResolver = exports.ReleaseInformation = exports.DefaultVersionClassifier = exports.DefaultCurrentCommitResolver = exports.DefaultCommitsProvider = exports.CommitInfo = void 0;
|
||||
var CommitInfo_1 = require("./CommitInfo");
|
||||
Object.defineProperty(exports, "CommitInfo", { enumerable: true, get: function () { return CommitInfo_1.CommitInfo; } });
|
||||
var DefaultCommitsProvider_1 = require("./DefaultCommitsProvider");
|
||||
Object.defineProperty(exports, "DefaultCommitsProvider", { enumerable: true, get: function () { return DefaultCommitsProvider_1.DefaultCommitsProvider; } });
|
||||
var DefaultCurrentCommitResolver_1 = require("./DefaultCurrentCommitResolver");
|
||||
Object.defineProperty(exports, "DefaultCurrentCommitResolver", { enumerable: true, get: function () { return DefaultCurrentCommitResolver_1.DefaultCurrentCommitResolver; } });
|
||||
var DefaultVersionClassifier_1 = require("./DefaultVersionClassifier");
|
||||
Object.defineProperty(exports, "DefaultVersionClassifier", { enumerable: true, get: function () { return DefaultVersionClassifier_1.DefaultVersionClassifier; } });
|
||||
var ReleaseInformation_1 = require("./ReleaseInformation");
|
||||
Object.defineProperty(exports, "ReleaseInformation", { enumerable: true, get: function () { return ReleaseInformation_1.ReleaseInformation; } });
|
||||
var TagLastReleaseResolver_1 = require("./TagLastReleaseResolver");
|
||||
Object.defineProperty(exports, "TagLastReleaseResolver", { enumerable: true, get: function () { return TagLastReleaseResolver_1.TagLastReleaseResolver; } });
|
||||
var UserInfo_1 = require("./UserInfo");
|
||||
Object.defineProperty(exports, "UserInfo", { enumerable: true, get: function () { return UserInfo_1.UserInfo; } });
|
||||
var VersionClassification_1 = require("./VersionClassification");
|
||||
Object.defineProperty(exports, "VersionClassification", { enumerable: true, get: function () { return VersionClassification_1.VersionClassification; } });
|
||||
var VersionInformation_1 = require("./VersionInformation");
|
||||
Object.defineProperty(exports, "VersionInformation", { enumerable: true, get: function () { return VersionInformation_1.VersionInformation; } });
|
||||
var VersionType_1 = require("./VersionType");
|
||||
Object.defineProperty(exports, "VersionType", { enumerable: true, get: function () { return VersionType_1.VersionType; } });
|
||||
Loading…
Add table
Add a link
Reference in a new issue