Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SiqiLu committed Aug 12, 2022
1 parent aa20a56 commit 8ce81f6
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 49 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ jobs:
## Test cases
- [ ] 1.0.0.0 => 1.0.0.1
- [ ] 2.3.4.5 => 2.3.5.0
- [ ] 2.3.4.5 => 3.0.0.0
- [ ] 2.3.4.5 => 3.0.5.0
- [ ] 2.3.4 => 2.4.0
- [ ] 2.3.4 => 3.0.0
- [ ] 2.3 => 2.4
- [ ] 2.3 => 3.0
- [ ] 2 => 3
- [ ] 2.3.4.5 => 2.3.4.${{ github.run_number }}
- [ ] 2.3.4.5 => 2.3.4.Alpha
- [ ] 2.3 => 2.${{ github.run_number }}
- [ ] 2.3.4.5 => 3.Alpha.5..${{ github.run_number }}
- [x] 1.0.0.0 => 1.0.0.1
- [x] 2.3.4.5 => 2.3.5.0
- [x] 2.3.4.5 => 3.0.0.0
- [x] 2.3.4.5 => 3.0.5.0
- [x] 2.3.4 => 2.4.0
- [x] 2.3.4 => 3.0.0
- [x] 2.3 => 2.4
- [x] 2.3 => 3.0
- [x] 2 => 3
- [x] 2.3.4.5 => 2.3.4.${{ github.run_number }}
- [x] 2.3.4.5 => 2.3.4.Alpha
- [x] 2.3 => 2.${{ github.run_number }}
- [x] 2.3.4.5 => 3.Alpha.5.${{ github.run_number }}
## License
Expand Down
46 changes: 30 additions & 16 deletions lib/Bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ class Bump {
this._bumpOptionFromCommitMessage = this._getBumpOptionFromCommitMessage();
}
get bumpMajor() {
return (!this._inputs.overwriteMajor && (this._bumpOptionFromCommitMessage === "major" || this._inputs.bumpMajor));
return (!this._inputs.overwriteMajor &&
(this._bumpOptionFromCommitMessage.includes("major") || this._inputs.bumpMajor));
}
get bumpMinor() {
return (!this._inputs.overwriteMinor && (this._bumpOptionFromCommitMessage === "minor" || this._inputs.bumpMinor));
return (!this._inputs.overwriteMinor &&
(this._bumpOptionFromCommitMessage.includes("minor") || this._inputs.bumpMinor));
}
get bumpPatch() {
return (!this._inputs.overwritePatch && (this._bumpOptionFromCommitMessage === "patch" || this._inputs.bumpPatch));
return (!this._inputs.overwritePatch &&
(this._bumpOptionFromCommitMessage.includes("patch") || this._inputs.bumpPatch));
}
get bumpBuild() {
return (!this._inputs.overwriteBuild && (this._bumpOptionFromCommitMessage === "build" || this._inputs.bumpBuild));
return (!this._inputs.overwriteBuild &&
(this._bumpOptionFromCommitMessage.includes("build") || this._inputs.bumpBuild));
}
get overwriteMajor() {
return this._inputs.overwriteMajor;
Expand Down Expand Up @@ -117,15 +121,17 @@ class Bump {
Bump._versions.forEach((v, k) => {
const versionMatches = v.exec(bumppedContent);
core.debug(`Bump.bump versionMatches: ${JSON.stringify(versionMatches)}`);
if (versionMatches && versionMatches.length >= 2) {
if (versionMatches && versionMatches.length == 6) {
const originVersion = versionMatches[1].toString();
core.debug(`Bump.bump ${k}.originVersion: ${originVersion}`);
let hasBumped = false;
let major = null;
let minor = null;
let patch = null;
let build = null;
if (versionMatches.length >= 3) {
const majorMatch = versionMatches[2];
core.debug(`Bump.bump ${k}.majorMatch: ${majorMatch}`);
if (majorMatch && majorMatch.length > 0) {
// version has major part
const majorPart = versionMatches[2].toString();
core.debug(`Bump.bump version majorPart: ${majorPart}`);
Expand All @@ -140,7 +146,9 @@ class Bump {
major = bumpResult.version;
core.debug(`Bump.bump version modifiedMajorPart: ${major !== null && major !== void 0 ? major : "null"}`);
}
if (versionMatches.length >= 4) {
const minorMatch = versionMatches[3];
core.debug(`Bump.bump ${k}.minorMatch: ${minorMatch}`);
if (minorMatch && minorMatch.length > 0) {
// version has minor part
const minorPart = versionMatches[3].toString();
core.debug(`Bump.bump version minorPart: ${minorPart}`);
Expand All @@ -151,11 +159,13 @@ class Bump {
core.debug(`bumpMinor: ${this.bumpMinor.toString()}`);
core.debug(`hasBumped: ${hasBumped.toString()}`);
let bumpResult = Bump._bumpVersionPart(minorPart, this.overwriteMinor, this.overwriteMinorString, this.bumpMinor, hasBumped);
hasBumped = bumpResult.bumped;
hasBumped = hasBumped || bumpResult.bumped;
minor = bumpResult.version;
core.debug(`Bump.bump version modifiedMinorPart: ${minor !== null && minor !== void 0 ? minor : "null"}`);
}
if (versionMatches.length >= 5) {
const patchMatch = versionMatches[4];
core.debug(`Bump.bump ${k}.patchMatch: ${patchMatch}`);
if (patchMatch && patchMatch.length > 0) {
// version has patch part
const patchPart = versionMatches[4].toString();
core.debug(`Bump.bump version patchPart: ${patchPart}`);
Expand All @@ -166,11 +176,13 @@ class Bump {
core.debug(`bumpPatch: ${this.bumpPatch.toString()}`);
core.debug(`hasBumped: ${hasBumped.toString()}`);
let bumpResult = Bump._bumpVersionPart(patchPart, this.overwritePatch, this.overwritePatchString, this.bumpPatch, hasBumped);
hasBumped = bumpResult.bumped;
hasBumped = hasBumped || bumpResult.bumped;
patch = bumpResult.version;
core.debug(`Bump.bump version modifiedPatchPart: ${patch !== null && patch !== void 0 ? patch : "null"}`);
}
if (versionMatches.length >= 6) {
const buildMatch = versionMatches[5];
core.debug(`Bump.bump ${k}.buildMatch: ${buildMatch}`);
if (buildMatch && buildMatch.length > 0) {
// version has build part
const buildPart = versionMatches[5].toString();
core.debug(`Bump.bump version buildPart: ${buildPart}`);
Expand All @@ -181,7 +193,7 @@ class Bump {
core.debug(`bumpBuild: ${this.bumpBuild.toString()}`);
core.debug(`hasBumped: ${hasBumped.toString()}`);
let bumpResult = Bump._bumpVersionPart(buildPart, this.overwriteBuild, this.overwriteBuildString, this.bumpBuild, hasBumped);
hasBumped = bumpResult.bumped;
hasBumped = hasBumped || bumpResult.bumped;
build = bumpResult.version;
core.debug(`Bump.bump version modifiedBuildPart: ${build !== null && build !== void 0 ? build : "null"}`);
}
Expand All @@ -202,7 +214,7 @@ class Bump {
}
}
else {
core.info(`Can not find ${k} from "${this._file}".`);
core.info(`Can not find ${k} from "${this._file}" or the format of the version number is incorrect.`);
}
});
core.debug(`Bump.bump fileModified: ${fileModified.toString()}`);
Expand All @@ -218,13 +230,15 @@ class Bump {
return fileModified;
}
_getBumpOptionFromCommitMessage() {
let options = "none";
// ["--major","--major",major,null,null,null]
// ["--patch","--patch",null,null,"patch",null]
let options = [];
const optionsMatches = Bump._optionsRex.exec(this._commitMessage);
core.debug(`Bump._getBumpOptionFromCommitMessage optionsMatches: ${JSON.stringify(optionsMatches)}`);
if (optionsMatches && optionsMatches.length >= 3) {
options = optionsMatches[1].toString();
options = optionsMatches.filter((v, i) => v && v.length > 0 && i >= 2).map(v => v.toString());
}
core.debug(`Bump._getBumpOptionFromCommitMessage options: ${options}`);
core.debug(`Bump._getBumpOptionFromCommitMessage options: ${JSON.stringify(options)}`);
return options;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Inputs {
this._overwriteMajorRex = /^([^\.\s]*)\.[^\.\s]*\.[^\.\s]*\.[^\.\s]*$/;
this._overwriteMinorRex = /^[^\.\s]*\.([^\.\s]*)\.[^\.\s]*\.[^\.\s]*$/;
this._overwritePatchRex = /^[^\.\s]*\.[^\.\s]*\.([^\.\s]*)\.[^\.\s]*$/;
this._overwriteBuildRex = /^[^\.\s]*\.[^\.\s]*\.[^\.\s]*\.([^\.\s])*$/;
this._overwriteBuildRex = /^[^\.\s]*\.[^\.\s]*\.[^\.\s]*\.([^\.\s]*)$/;
this._overwriteMajor = null;
this._overwriteMinor = null;
this._overwritePatch = null;
Expand Down
51 changes: 33 additions & 18 deletions src/Bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Bump {

private readonly _inputs: Inputs;

private readonly _bumpOptionFromCommitMessage: string;
private readonly _bumpOptionFromCommitMessage: string[];

constructor(file: string, commitMessage: string, inputs: Inputs) {
this._file = file;
Expand All @@ -51,25 +51,29 @@ export class Bump {

public get bumpMajor(): boolean {
return (
!this._inputs.overwriteMajor && (this._bumpOptionFromCommitMessage === "major" || this._inputs.bumpMajor)
!this._inputs.overwriteMajor &&
(this._bumpOptionFromCommitMessage.includes("major") || this._inputs.bumpMajor)
);
}

public get bumpMinor(): boolean {
return (
!this._inputs.overwriteMinor && (this._bumpOptionFromCommitMessage === "minor" || this._inputs.bumpMinor)
!this._inputs.overwriteMinor &&
(this._bumpOptionFromCommitMessage.includes("minor") || this._inputs.bumpMinor)
);
}

public get bumpPatch(): boolean {
return (
!this._inputs.overwritePatch && (this._bumpOptionFromCommitMessage === "patch" || this._inputs.bumpPatch)
!this._inputs.overwritePatch &&
(this._bumpOptionFromCommitMessage.includes("patch") || this._inputs.bumpPatch)
);
}

public get bumpBuild(): boolean {
return (
!this._inputs.overwriteBuild && (this._bumpOptionFromCommitMessage === "build" || this._inputs.bumpBuild)
!this._inputs.overwriteBuild &&
(this._bumpOptionFromCommitMessage.includes("build") || this._inputs.bumpBuild)
);
}

Expand Down Expand Up @@ -171,7 +175,7 @@ export class Bump {
const versionMatches = v.exec(bumppedContent);
core.debug(`Bump.bump versionMatches: ${JSON.stringify(versionMatches)}`);

if (versionMatches && versionMatches.length >= 2) {
if (versionMatches && versionMatches.length == 6) {
const originVersion = versionMatches[1].toString();
core.debug(`Bump.bump ${k}.originVersion: ${originVersion}`);

Expand All @@ -181,7 +185,9 @@ export class Bump {
let patch: string | null = null;
let build: string | null = null;

if (versionMatches.length >= 3) {
const majorMatch = versionMatches[2];
core.debug(`Bump.bump ${k}.majorMatch: ${majorMatch}`);
if (majorMatch && majorMatch.length > 0) {
// version has major part
const majorPart = versionMatches[2].toString();
core.debug(`Bump.bump version majorPart: ${majorPart}`);
Expand All @@ -205,7 +211,9 @@ export class Bump {
core.debug(`Bump.bump version modifiedMajorPart: ${major ?? "null"}`);
}

if (versionMatches.length >= 4) {
const minorMatch = versionMatches[3];
core.debug(`Bump.bump ${k}.minorMatch: ${minorMatch}`);
if (minorMatch && minorMatch.length > 0) {
// version has minor part
const minorPart = versionMatches[3].toString();
core.debug(`Bump.bump version minorPart: ${minorPart}`);
Expand All @@ -223,13 +231,15 @@ export class Bump {
this.bumpMinor,
hasBumped
);
hasBumped = bumpResult.bumped;
hasBumped = hasBumped || bumpResult.bumped;
minor = bumpResult.version;

core.debug(`Bump.bump version modifiedMinorPart: ${minor ?? "null"}`);
}

if (versionMatches.length >= 5) {
const patchMatch = versionMatches[4];
core.debug(`Bump.bump ${k}.patchMatch: ${patchMatch}`);
if (patchMatch && patchMatch.length > 0) {
// version has patch part
const patchPart = versionMatches[4].toString();
core.debug(`Bump.bump version patchPart: ${patchPart}`);
Expand All @@ -247,13 +257,15 @@ export class Bump {
this.bumpPatch,
hasBumped
);
hasBumped = bumpResult.bumped;
hasBumped = hasBumped || bumpResult.bumped;
patch = bumpResult.version;

core.debug(`Bump.bump version modifiedPatchPart: ${patch ?? "null"}`);
}

if (versionMatches.length >= 6) {
const buildMatch = versionMatches[5];
core.debug(`Bump.bump ${k}.buildMatch: ${buildMatch}`);
if (buildMatch && buildMatch.length > 0) {
// version has build part
const buildPart = versionMatches[5].toString();
core.debug(`Bump.bump version buildPart: ${buildPart}`);
Expand All @@ -271,7 +283,7 @@ export class Bump {
this.bumpBuild,
hasBumped
);
hasBumped = bumpResult.bumped;
hasBumped = hasBumped || bumpResult.bumped;
build = bumpResult.version;

core.debug(`Bump.bump version modifiedBuildPart: ${build ?? "null"}`);
Expand All @@ -296,7 +308,7 @@ export class Bump {
core.info(`"${this._file}" ${k} "${originVersion}" is unbumped.`);
}
} else {
core.info(`Can not find ${k} from "${this._file}".`);
core.info(`Can not find ${k} from "${this._file}" or the format of the version number is incorrect.`);
}
});

Expand All @@ -314,16 +326,19 @@ export class Bump {
return fileModified;
}

private _getBumpOptionFromCommitMessage(): string {
let options = "none";
private _getBumpOptionFromCommitMessage(): string[] {
// ["--major","--major",major,null,null,null]
// ["--patch","--patch",null,null,"patch",null]

let options: string[] = [];
const optionsMatches = Bump._optionsRex.exec(this._commitMessage);
core.debug(`Bump._getBumpOptionFromCommitMessage optionsMatches: ${JSON.stringify(optionsMatches)}`);

if (optionsMatches && optionsMatches.length >= 3) {
options = optionsMatches[1].toString();
options = optionsMatches.filter((v, i) => v && v.length > 0 && i >= 2).map(v => v.toString());
}

core.debug(`Bump._getBumpOptionFromCommitMessage options: ${options}`);
core.debug(`Bump._getBumpOptionFromCommitMessage options: ${JSON.stringify(options)}`);

return options;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Inputs {

private readonly _overwritePatchRex: RegExp = /^[^\.\s]*\.[^\.\s]*\.([^\.\s]*)\.[^\.\s]*$/;

private readonly _overwriteBuildRex: RegExp = /^[^\.\s]*\.[^\.\s]*\.[^\.\s]*\.([^\.\s])*$/;
private readonly _overwriteBuildRex: RegExp = /^[^\.\s]*\.[^\.\s]*\.[^\.\s]*\.([^\.\s]*)$/;

private _overwriteMajor: boolean | null = null;

Expand Down

0 comments on commit 8ce81f6

Please sign in to comment.