Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit pattern upgrade #17

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const { join } = require("path");
const { spawn } = require("child_process");
const { readFile } = require("fs");

//This is a common source of truth for both the actual action and unit tests
const commitRegex = "^v?(\\d+\\.\\d+\\.\\d+(?:-(?:alpha|beta)\\.\\d+)?)$";

async function main() {
const dir =
process.env.WORKSPACE ||
Expand All @@ -24,8 +27,7 @@ async function main() {
throw new NeutralExitError();
}

const commitPattern =
getEnv("COMMIT_PATTERN") || "^(?:Release|Version) (\\S+)";
const commitPattern = getEnv("COMMIT_PATTERN") || commitRegex;

const { name, email } = eventObj.repository.owner;

Expand Down Expand Up @@ -191,3 +193,7 @@ if (require.main === module) {
}
});
}

module.exports = {
commitRegex
};
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
"npm-publish-action": "./index.js"
},
"scripts": {
"lint": "eslint ."
"lint": "eslint .",
"test": "mocha tests.js"
},
"devDependencies": {
"eslint": "^7.5.0"
"chai": "^4.2.0",
"eslint": "^7.5.0",
"mocha": "^8.0.1"
},
"eslintConfig": {
"parserOptions": {
Expand Down
75 changes: 75 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const { commitRegex } = require("./index.js");
const { expect } = require("chai");

const regex = new RegExp(commitRegex);

describe("commit regex", () => {
it("will accept single digit semantic versions", () => {
expect("1.2.3".match(regex)).to.have.length(2);
expect("1.2.3".match(regex)[1]).to.equal("1.2.3");

expect("v1.2.3".match(regex)).to.have.length(2);
expect("v1.2.3".match(regex)[1]).to.equal("1.2.3");
});

it("will accept multi digit semantic versions", () => {
expect("10.11.12".match(regex)).to.have.length(2);
expect("10.11.12".match(regex)[1]).to.equal("10.11.12");

expect("v10.11.12".match(regex)).to.have.length(2);
expect("v10.11.12".match(regex)[1]).to.equal("10.11.12");
});

it("will accept single digit semantic versions with prerelease suffixes", () => {
expect("1.2.3-alpha.0".match(regex)).to.have.length(2);
expect("1.2.3-alpha.0".match(regex)[1]).to.equal("1.2.3-alpha.0");

expect("1.2.3-beta.0".match(regex)).to.have.length(2);
expect("1.2.3-beta.0".match(regex)[1]).to.equal("1.2.3-beta.0");

expect("v1.2.3-alpha.0".match(regex)).to.have.length(2);
expect("v1.2.3-alpha.0".match(regex)[1]).to.equal("1.2.3-alpha.0");

expect("v1.2.3-beta.0".match(regex)).to.have.length(2);
expect("v1.2.3-beta.0".match(regex)[1]).to.equal("1.2.3-beta.0");
});

it("will accept multi digit semantic versions with prerelease suffixes", () => {
expect("10.11.12-alpha.0".match(regex)).to.have.length(2);
expect("10.11.12-alpha.0".match(regex)[1]).to.equal("10.11.12-alpha.0");

expect("10.11.12-beta.0".match(regex)).to.have.length(2);
expect("10.11.12-beta.0".match(regex)[1]).to.equal("10.11.12-beta.0");

expect("v10.11.12-alpha.0".match(regex)).to.have.length(2);
expect("v10.11.12-alpha.0".match(regex)[1]).to.equal("10.11.12-alpha.0");

expect("v10.11.12-beta.0".match(regex)).to.have.length(2);
expect("v10.11.12-beta.0".match(regex)[1]).to.equal("10.11.12-beta.0");
});

it('will not accept non "v" prefixes', () => {
expect("x1.2.3".match(regex)).to.be.null;
expect("x10.11.12".match(regex)).to.be.null;
});

it("will not accept unknown prerelease suffixes", () => {
expect("1.2.3-gamma.0".match(regex)).to.be.null;

expect("v1.2.3-gamma.0".match(regex)).to.be.null;

expect("10.11.12-gamma.0".match(regex)).to.be.null;

expect("v10.11.12-gamma.0".match(regex)).to.be.null;
});

it("will not accept invalid prerelease suffixes", () => {
expect("1.2.3-alpha".match(regex)).to.be.null;

expect("v1.2.3-alpha".match(regex)).to.be.null;

expect("10.11.12-alpha".match(regex)).to.be.null;

expect("v10.11.12-alpha".match(regex)).to.be.null;
});
});
Loading