Skip to content

Commit

Permalink
Release 0.1.1 added gh-actions-stats package
Browse files Browse the repository at this point in the history
  • Loading branch information
michmich112 committed Sep 8, 2021
1 parent 7599745 commit 612b1df
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 532 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ Example: `major.minor.build[-patch][->dev]`
## More examples
To see more examples, check out [version-bumper](https://github.com/michmich112/version-bumper) which automatically bumps
your versions based on the branching model you define and customize.

## Notes
This action uses the `gh-action-stats` package to track usage. See the data collected at [gh-action-stats-js](https://github.com/michmich112/gh-action-stats-js).

111 changes: 8 additions & 103 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,116 +27,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateSchemeRegexp = exports.getCurrentVersion = void 0;
const core = __importStar(require("@actions/core"));
const fs = __importStar(require("fs"));
const readline = __importStar(require("readline"));
const utils_1 = require("./utils");
const gh_action_stats_1 = __importDefault(require("gh-action-stats"));
const FAILURE = 1;
function test() {
return __awaiter(this, void 0, void 0, function* () {
const options = getActionOptions();
Object.freeze(options);
const schemeRegExp = generateSchemeRegexp(options.schema);
const version = yield getCurrentVersion(options, schemeRegExp);
console.info(`[SUCCESS] - found version ${version}`);
return version;
});
}
function getActionOptions() {
const schema = core.getInput('schema', { required: true });
const versionFile = core.getInput('version-file', { required: true });
const versionLine = parseInt(core.getInput('version-line')) || undefined;
return {
schema,
versionFile,
versionLine,
};
}
function getCurrentVersion(options, regExp) {
var e_1, _a;
return __awaiter(this, void 0, void 0, function* () {
const { versionFile: path, versionLine: line } = options;
// verify the path actually corresponds to a file
if (!fs.existsSync(path))
throw new Error(`Version file with path ${path} does not exist.`);
const rl = readline.createInterface({ input: fs.createReadStream(path), crlfDelay: Infinity });
let counter = 1, initialMatch;
try {
for (var rl_1 = __asyncValues(rl), rl_1_1; rl_1_1 = yield rl_1.next(), !rl_1_1.done;) {
const ln = rl_1_1.value;
const match = ln.match(regExp);
if (!initialMatch && match !== null)
initialMatch = match[0]; // set the initial match
if (!line && initialMatch) { // return straight away if line is not specified
console.log(`Match found line ${counter} -> ${initialMatch}`);
return initialMatch;
}
// if the user has specified a line number we go all the way to it
if (line && counter === line) {
if (match !== null) {
console.log(`Found scheme match line ${counter} -> ${match[0]}`);
return match[0];
}
else {
console.log(`No match found for specified scheme on specified line ${line}.`);
if (initialMatch) {
console.log(`Using previous found match: ${initialMatch}`);
return initialMatch;
}
else
console.log(`No match found previously. Continuing file search.`);
}
}
else if (line && counter > line && initialMatch) {
console.log(`Match found line ${counter} -> ${initialMatch}`);
return initialMatch;
}
counter++; // increment line counter
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (rl_1_1 && !rl_1_1.done && (_a = rl_1.return)) yield _a.call(rl_1);
}
finally { if (e_1) throw e_1.error; }
}
throw new Error(`No match found in file. Unable to identify current version number.`);
});
}
exports.getCurrentVersion = getCurrentVersion;
/**
* scheme must be of form <tag><seperator>[<tag><seperator>]
* tag will be used to generate commands
* - strstatus is a reserved tag that inserts the status as a string, also mapped to the status command
* seperators are used to seperate tags. allowed seperators are: .,;-_><
* brackets define optional tags. they wont be displayed if there are no tags after them and if they are = to 0
* generated regex will identify the scheme in the passed options file
* @param scheme
*/
function generateSchemeRegexp(scheme) {
let seperators = new Set(scheme.match(/[.,;:\-_><]+/gm) || []), tags = new Set(scheme.split(/[.,;:\-_><\]\[]+/g).filter((tag) => tag !== "")),
// regExp = scheme.replace(/[\[\]]/gm, "");
regExp = scheme.replace(/\[/gm, '(').replace(/\]/gm, ')?');
seperators.forEach((sep) => regExp = regExp.replace(new RegExp('\\' + sep.split('').join('\\'), 'g'), '\\' + sep.split('').join('\\')));
tags.forEach((tag) => regExp = regExp.replace(tag, '[0-9]+'));
return new RegExp(regExp);
}
exports.generateSchemeRegexp = generateSchemeRegexp;
function main() {
return __awaiter(this, void 0, void 0, function* () {
const options = getActionOptions();
gh_action_stats_1.default(); // collect the stats of the action run
const options = utils_1.getActionOptions();
Object.freeze(options);
const schemeRegExp = generateSchemeRegexp(options.schema);
const version = yield getCurrentVersion(options, schemeRegExp);
const schemeRegExp = utils_1.generateSchemeRegexp(options.schema);
const version = yield utils_1.getCurrentVersion(options, schemeRegExp);
console.info(`[SUCCESS] - found version ${version}`);
return version;
});
Expand Down
18 changes: 9 additions & 9 deletions dist/tests/main.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
const utils_1 = require("../utils");
describe("Generate Regular expression from scheme description", () => {
describe("General semantic cases: major.minor.build", () => {
let scheme = 'major.minor.build', genRegExp = index_1.generateSchemeRegexp(scheme);
let scheme = 'major.minor.build', genRegExp = utils_1.generateSchemeRegexp(scheme);
console.log(genRegExp);
test("it should identify the correct item in the string for a simple input", () => {
let match = "1.2.3".match(genRegExp);
Expand Down Expand Up @@ -36,7 +36,7 @@ describe("Generate Regular expression from scheme description", () => {
});
});
describe("General semantic cases w/ optional tag: major.minor[.build]", () => {
let scheme = 'major.minor[.build]', genRegExp = index_1.generateSchemeRegexp(scheme);
let scheme = 'major.minor[.build]', genRegExp = utils_1.generateSchemeRegexp(scheme);
test("it should identify the correct item in the string for simple input (w/ optional)", () => {
let match = "1.2.3".match(genRegExp);
expect(match).not.toBe(null);
Expand Down Expand Up @@ -79,7 +79,7 @@ describe("Generate Regular expression from scheme description", () => {
});
});
describe("General semantic cases w/ optional tags: major.minor[.build][.commit]", () => {
let scheme = 'major.minor[.build][.commit]', genRegExp = index_1.generateSchemeRegexp(scheme);
let scheme = 'major.minor[.build][.commit]', genRegExp = utils_1.generateSchemeRegexp(scheme);
test("it should identify the correct item in the string for simple input (w/ optionals)", () => {
let match = "1.2.3.4".match(genRegExp);
expect(match).not.toBe(null);
Expand Down Expand Up @@ -133,7 +133,7 @@ describe("Generate Regular expression from scheme description", () => {
});
});
describe("General semantic cases w/ compound optional tags: major.minor[.build[-commit]]", () => {
let scheme = 'major.minor[.build[-commit]]', genRegExp = index_1.generateSchemeRegexp(scheme);
let scheme = 'major.minor[.build[-commit]]', genRegExp = utils_1.generateSchemeRegexp(scheme);
test("it should identify the correct item in the string for simple input (w/ optionals)", () => {
let match = "1.2.3-4".match(genRegExp);
expect(match).not.toBe(null);
Expand Down Expand Up @@ -188,22 +188,22 @@ describe("Generate Regular expression from scheme description", () => {
});
describe("Case with multiple seperators", () => {
test("multiple seperators -> 1.2->3", () => {
let match = "1.2->3".match(index_1.generateSchemeRegexp("major.minor->build"));
let match = "1.2->3".match(utils_1.generateSchemeRegexp("major.minor->build"));
expect(match).not.toBe(null);
expect(match[0]).toBe("1.2->3");
});
test("multiple seperators with optional -> 1.2->3", () => {
let match = "1.2->3".match(index_1.generateSchemeRegexp("major.minor[->build]"));
let match = "1.2->3".match(utils_1.generateSchemeRegexp("major.minor[->build]"));
expect(match).not.toBe(null);
expect(match[0]).toBe("1.2->3");
});
test("multiple seperators with optionals -> 1.2->3<-4", () => {
let match = "1.2->3<-4".match(index_1.generateSchemeRegexp("major.minor[->build][<-tag]"));
let match = "1.2->3<-4".match(utils_1.generateSchemeRegexp("major.minor[->build][<-tag]"));
expect(match).not.toBe(null);
expect(match[0]).toBe("1.2->3<-4");
});
test("multiple seperators with compound optionals -> 1.2->3<-4", () => {
let match = "1.2->3<-4".match(index_1.generateSchemeRegexp("major.minor[->build[<-tag]]"));
let match = "1.2->3<-4".match(utils_1.generateSchemeRegexp("major.minor[->build[<-tag]]"));
expect(match).not.toBe(null);
expect(match[0]).toBe("1.2->3<-4");
});
Expand Down
134 changes: 134 additions & 0 deletions dist/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (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.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());
});
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateSchemeRegexp = exports.getCurrentVersion = exports.getActionOptions = exports.test = void 0;
const core = __importStar(require("@actions/core"));
const fs = __importStar(require("fs"));
const readline = __importStar(require("readline"));
function test() {
return __awaiter(this, void 0, void 0, function* () {
const options = getActionOptions();
Object.freeze(options);
const schemeRegExp = generateSchemeRegexp(options.schema);
const version = yield getCurrentVersion(options, schemeRegExp);
console.info(`[SUCCESS] - found version ${version}`);
return version;
});
}
exports.test = test;
function getActionOptions() {
const schema = core.getInput('schema', { required: true });
const versionFile = core.getInput('version-file', { required: true });
const versionLine = parseInt(core.getInput('version-line')) || undefined;
return {
schema,
versionFile,
versionLine,
};
}
exports.getActionOptions = getActionOptions;
function getCurrentVersion(options, regExp) {
var e_1, _a;
return __awaiter(this, void 0, void 0, function* () {
const { versionFile: path, versionLine: line } = options;
// verify the path actually corresponds to a file
if (!fs.existsSync(path))
throw new Error(`Version file with path ${path} does not exist.`);
const rl = readline.createInterface({ input: fs.createReadStream(path), crlfDelay: Infinity });
let counter = 1, initialMatch;
try {
for (var rl_1 = __asyncValues(rl), rl_1_1; rl_1_1 = yield rl_1.next(), !rl_1_1.done;) {
const ln = rl_1_1.value;
const match = ln.match(regExp);
if (!initialMatch && match !== null)
initialMatch = match[0]; // set the initial match
if (!line && initialMatch) { // return straight away if line is not specified
console.log(`Match found line ${counter} -> ${initialMatch}`);
return initialMatch;
}
// if the user has specified a line number we go all the way to it
if (line && counter === line) {
if (match !== null) {
console.log(`Found scheme match line ${counter} -> ${match[0]}`);
return match[0];
}
else {
console.log(`No match found for specified scheme on specified line ${line}.`);
if (initialMatch) {
console.log(`Using previous found match: ${initialMatch}`);
return initialMatch;
}
else
console.log(`No match found previously. Continuing file search.`);
}
}
else if (line && counter > line && initialMatch) {
console.log(`Match found line ${counter} -> ${initialMatch}`);
return initialMatch;
}
counter++; // increment line counter
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (rl_1_1 && !rl_1_1.done && (_a = rl_1.return)) yield _a.call(rl_1);
}
finally { if (e_1) throw e_1.error; }
}
throw new Error(`No match found in file. Unable to identify current version number.`);
});
}
exports.getCurrentVersion = getCurrentVersion;
/**
* scheme must be of form <tag><seperator>[<tag><seperator>]
* tag will be used to generate commands
* - strstatus is a reserved tag that inserts the status as a string, also mapped to the status command
* seperators are used to seperate tags. allowed seperators are: .,;-_><
* brackets define optional tags. they wont be displayed if there are no tags after them and if they are = to 0
* generated regex will identify the scheme in the passed options file
* @param scheme
*/
function generateSchemeRegexp(scheme) {
let seperators = new Set(scheme.match(/[.,;:\-_><]+/gm) || []), tags = new Set(scheme.split(/[.,;:\-_><\]\[]+/g).filter((tag) => tag !== "")),
// regExp = scheme.replace(/[\[\]]/gm, "");
regExp = scheme.replace(/\[/gm, '(').replace(/\]/gm, ')?');
seperators.forEach((sep) => regExp = regExp.replace(new RegExp('\\' + sep.split('').join('\\'), 'g'), '\\' + sep.split('').join('\\')));
tags.forEach((tag) => regExp = regExp.replace(tag, '[0-9]+'));
return new RegExp(regExp);
}
exports.generateSchemeRegexp = generateSchemeRegexp;
8 changes: 8 additions & 0 deletions node_modules/gh-action-stats/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 612b1df

Please sign in to comment.