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 1 commit
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
2 changes: 2 additions & 0 deletions commit-regex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//This is a common source of truth for both the actual action and unit tests
module.exports = "^v?(\\d+\\.\\d+\\.\\d+(?:-(?:alpha|beta)\\.\\d+)?)$";
Copy link
Owner

@pascalgn pascalgn Jul 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could make more sense to have a method matchCommitMessage or so, exported in index.js, and then call that method in the test. Then there would be no need for this file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pascalgn Sorry about that. I've now exported an object containing commitRegex to reduce future changes should the need arise to export additional objects.

4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node

const commitRegex = require("./commit-regex.js");
const process = require("process");
const { join } = require("path");
const { spawn } = require("child_process");
Expand All @@ -24,8 +25,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
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("./commit-regex.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