mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-27 13:08:17 +00:00
Merge pull request #7 from PaulHatch/feature/quote-match
Windows support + fix for commits with tags
This commit is contained in:
commit
1f05445eed
4 changed files with 125 additions and 47 deletions
27
.github/workflows/test.yml
vendored
27
.github/workflows/test.yml
vendored
|
|
@ -4,15 +4,34 @@ on:
|
|||
push:
|
||||
branches:
|
||||
- master
|
||||
- "releases/*"
|
||||
- "feature/*"
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: "Test and Run"
|
||||
test-linux:
|
||||
name: "Test and Run, Linux"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: NPM Install
|
||||
run: npm ci
|
||||
- name: Test
|
||||
run: npm test
|
||||
- name: Package
|
||||
run: npm run package
|
||||
- name: Run Action
|
||||
uses: ./
|
||||
id: run
|
||||
test-windows:
|
||||
name: "Test and Run, Windows"
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: NPM Install
|
||||
run: npm ci
|
||||
- name: Test
|
||||
|
|
|
|||
54
dist/index.js
vendored
54
dist/index.js
vendored
|
|
@ -1021,9 +1021,10 @@ exports.issueCommand = issueCommand;
|
|||
|
||||
const core = __webpack_require__(470);
|
||||
const exec = __webpack_require__(986);
|
||||
const eol = __webpack_require__(87).EOL;
|
||||
const eol = '\n';
|
||||
|
||||
const tagPrefix = core.getInput('tag_prefix') || '';
|
||||
const namespace = core.getInput('namespace') || '';
|
||||
|
||||
const cmd = async (command, ...args) => {
|
||||
let output = '', errors = '';
|
||||
|
|
@ -1032,7 +1033,9 @@ const cmd = async (command, ...args) => {
|
|||
};
|
||||
options.listeners = {
|
||||
stdout: (data) => { output += data.toString(); },
|
||||
stderr: (data) => { errors += data.toString(); }
|
||||
stderr: (data) => { errors += data.toString(); },
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
};
|
||||
|
||||
await exec.exec(command, args, options)
|
||||
|
|
@ -1088,6 +1091,26 @@ const setOutput = (major, minor, patch, increment, changed, branch, namespace) =
|
|||
|
||||
};
|
||||
|
||||
const parseVersion = (tag) => {
|
||||
|
||||
console.log(tag);
|
||||
let tagParts = tag.split('/');
|
||||
let versionValues = tagParts[tagParts.length - 1]
|
||||
.substr(tagPrefix.length)
|
||||
.slice(0, namespace === '' ? 999 : -(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];
|
||||
};
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const remote = await cmd('git', 'remote');
|
||||
|
|
@ -1098,7 +1121,6 @@ async function run() {
|
|||
const majorPattern = core.getInput('major_pattern', { required: true });
|
||||
const minorPattern = core.getInput('minor_pattern', { required: true });
|
||||
const changePath = core.getInput('change_path') || '';
|
||||
const namespace = core.getInput('namespace') || '';
|
||||
|
||||
const releasePattern = namespace === '' ? `${tagPrefix}*[0-9.]` : `${tagPrefix}*[0-9.]-${namespace}`;
|
||||
let major = 0, minor = 0, patch = 0, increment = 0;
|
||||
|
|
@ -1112,7 +1134,15 @@ async function run() {
|
|||
return;
|
||||
}
|
||||
|
||||
//let commit = (await cmd('git', 'rev-parse', 'HEAD')).trim();
|
||||
let currentTag = (await cmd(
|
||||
`git tag --points-at ${branch} ${releasePattern}`
|
||||
)).trim();
|
||||
|
||||
if (currentTag) {
|
||||
[major, minor, patch] = parseVersion(currentTag);
|
||||
setOutput(major, minor, patch, 0, false, branch, namespace);
|
||||
return;
|
||||
}
|
||||
|
||||
let tag = '';
|
||||
try {
|
||||
|
|
@ -1138,20 +1168,7 @@ async function run() {
|
|||
root = '';
|
||||
} else {
|
||||
// parse the version tag
|
||||
let tagParts = tag.split('/');
|
||||
let versionValues = tagParts[tagParts.length - 1]
|
||||
.substr(tagPrefix.length)
|
||||
.slice(0, namespace === '' ? 999 : -(namespace.length + 1))
|
||||
.split('.');
|
||||
|
||||
major = parseInt(versionValues[0]);
|
||||
minor = versionValues.length > 1 ? parseInt(versionValues[1]) : 0;
|
||||
patch = versionValues.length > 2 ? parseInt(versionValues[2]) : 0;
|
||||
|
||||
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
||||
core.setFailed(`Invalid tag ${tag} (${versionValues})`);
|
||||
return;
|
||||
}
|
||||
[major, minor, patch] = parseVersion(tag);
|
||||
|
||||
root = await cmd('git', `merge-base`, tag, branch);
|
||||
}
|
||||
|
|
@ -1211,6 +1228,7 @@ async function run() {
|
|||
run();
|
||||
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 129:
|
||||
|
|
|
|||
54
index.js
54
index.js
|
|
@ -1,8 +1,9 @@
|
|||
const core = require('@actions/core');
|
||||
const exec = require("@actions/exec");
|
||||
const eol = require('os').EOL;
|
||||
const eol = '\n';
|
||||
|
||||
const tagPrefix = core.getInput('tag_prefix') || '';
|
||||
const namespace = core.getInput('namespace') || '';
|
||||
|
||||
const cmd = async (command, ...args) => {
|
||||
let output = '', errors = '';
|
||||
|
|
@ -11,7 +12,9 @@ const cmd = async (command, ...args) => {
|
|||
};
|
||||
options.listeners = {
|
||||
stdout: (data) => { output += data.toString(); },
|
||||
stderr: (data) => { errors += data.toString(); }
|
||||
stderr: (data) => { errors += data.toString(); },
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
};
|
||||
|
||||
await exec.exec(command, args, options)
|
||||
|
|
@ -67,6 +70,26 @@ const setOutput = (major, minor, patch, increment, changed, branch, namespace) =
|
|||
|
||||
};
|
||||
|
||||
const parseVersion = (tag) => {
|
||||
|
||||
console.log(tag);
|
||||
let tagParts = tag.split('/');
|
||||
let versionValues = tagParts[tagParts.length - 1]
|
||||
.substr(tagPrefix.length)
|
||||
.slice(0, namespace === '' ? 999 : -(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];
|
||||
};
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const remote = await cmd('git', 'remote');
|
||||
|
|
@ -77,7 +100,6 @@ async function run() {
|
|||
const majorPattern = core.getInput('major_pattern', { required: true });
|
||||
const minorPattern = core.getInput('minor_pattern', { required: true });
|
||||
const changePath = core.getInput('change_path') || '';
|
||||
const namespace = core.getInput('namespace') || '';
|
||||
|
||||
const releasePattern = namespace === '' ? `${tagPrefix}*[0-9.]` : `${tagPrefix}*[0-9.]-${namespace}`;
|
||||
let major = 0, minor = 0, patch = 0, increment = 0;
|
||||
|
|
@ -91,7 +113,15 @@ async function run() {
|
|||
return;
|
||||
}
|
||||
|
||||
//let commit = (await cmd('git', 'rev-parse', 'HEAD')).trim();
|
||||
let currentTag = (await cmd(
|
||||
`git tag --points-at ${branch} ${releasePattern}`
|
||||
)).trim();
|
||||
|
||||
if (currentTag) {
|
||||
[major, minor, patch] = parseVersion(currentTag);
|
||||
setOutput(major, minor, patch, 0, false, branch, namespace);
|
||||
return;
|
||||
}
|
||||
|
||||
let tag = '';
|
||||
try {
|
||||
|
|
@ -117,20 +147,7 @@ async function run() {
|
|||
root = '';
|
||||
} else {
|
||||
// parse the version tag
|
||||
let tagParts = tag.split('/');
|
||||
let versionValues = tagParts[tagParts.length - 1]
|
||||
.substr(tagPrefix.length)
|
||||
.slice(0, namespace === '' ? 999 : -(namespace.length + 1))
|
||||
.split('.');
|
||||
|
||||
major = parseInt(versionValues[0]);
|
||||
minor = versionValues.length > 1 ? parseInt(versionValues[1]) : 0;
|
||||
patch = versionValues.length > 2 ? parseInt(versionValues[2]) : 0;
|
||||
|
||||
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
||||
core.setFailed(`Invalid tag ${tag} (${versionValues})`);
|
||||
return;
|
||||
}
|
||||
[major, minor, patch] = parseVersion(tag);
|
||||
|
||||
root = await cmd('git', `merge-base`, tag, branch);
|
||||
}
|
||||
|
|
@ -188,3 +205,4 @@ async function run() {
|
|||
}
|
||||
|
||||
run();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
const cp = require('child_process');
|
||||
const path = require('path');
|
||||
const process = require('process');
|
||||
const os = require('os');
|
||||
const windows = process.platform === "win32";
|
||||
|
||||
// Action input variables
|
||||
const defaultInputs = {
|
||||
|
|
@ -13,8 +15,9 @@ const defaultInputs = {
|
|||
|
||||
// Creates a randomly named git repository and returns a function to execute commands in it
|
||||
const createTestRepo = (inputs) => {
|
||||
const repoDirectory = `/tmp/test${Math.random().toString(36).substring(2, 15)}`;
|
||||
cp.execSync(`mkdir ${repoDirectory} && git init ${repoDirectory}`);
|
||||
const repoDirectory = path.join(os.tmpdir(), `test${Math.random().toString(36).substring(2, 15)}`);
|
||||
cp.execSync(`mkdir ${repoDirectory}`);
|
||||
cp.execSync(`git init ${repoDirectory}`);
|
||||
|
||||
const run = (command, extraInputs) => {
|
||||
const allInputs = Object.assign({ ...defaultInputs }, inputs, extraInputs);
|
||||
|
|
@ -32,11 +35,15 @@ const createTestRepo = (inputs) => {
|
|||
let i = 1;
|
||||
|
||||
return {
|
||||
clean: () => execute('/tmp', `rm -rf ${repoDirectory}`),
|
||||
clean: () => execute(os.tmpdir(), windows ? `rmdir /s /q ${repoDirectory}` : `rm -rf ${repoDirectory}`),
|
||||
makeCommit: (msg, path) => {
|
||||
run(`touch ${path !== undefined ? path.trim('/') + '/' : ''}test${i++}`);
|
||||
if (windows) {
|
||||
run(`fsutil file createnew ${path !== undefined ? path.trim('/') + '/' : ''}test${i++} 0`);
|
||||
} else {
|
||||
run(`touch ${path !== undefined ? path.trim('/') + '/' : ''}test${i++}`);
|
||||
}
|
||||
run(`git add --all`);
|
||||
run(`git commit -m '${msg}'`);
|
||||
run(`git commit -m "${msg}"`);
|
||||
},
|
||||
runAction: (inputs) => run(`node ${path.join(__dirname, 'index.js')}`, inputs),
|
||||
exec: run
|
||||
|
|
@ -84,7 +91,7 @@ test('Tagging does not break version', () => {
|
|||
repo.exec('git tag v0.0.1')
|
||||
const result = repo.runAction();
|
||||
|
||||
expect(result).toMatch('Version is 0.0.1+1');
|
||||
expect(result).toMatch('Version is 0.0.1+0');
|
||||
|
||||
repo.clean();
|
||||
});
|
||||
|
|
@ -276,7 +283,8 @@ test('Tag order comes from commit order, not tag create order', () => {
|
|||
repo.makeCommit('Second Commit'); // 0.0.1+1
|
||||
repo.makeCommit('Third Commit'); // 0.0.1+2
|
||||
repo.exec('git tag v2.0.0');
|
||||
repo.exec('sleep 2');
|
||||
// Can't timeout in this context on Windows, ping localhost to delay
|
||||
repo.exec(windows ? 'ping 127.0.0.1 -n 2' : 'sleep 2');
|
||||
repo.exec('git tag v1.0.0 HEAD~1');
|
||||
repo.makeCommit('Fourth Commit'); // 0.0.1+2
|
||||
|
||||
|
|
@ -422,5 +430,20 @@ test('Commits inside path are counted', () => {
|
|||
|
||||
expect(result).toMatch('Version is 0.0.1+2');
|
||||
|
||||
repo.clean();
|
||||
});
|
||||
|
||||
test('Current tag is used', () => {
|
||||
const repo = createTestRepo({ tag_prefix: '' }); // 0.0.0
|
||||
|
||||
repo.makeCommit('Initial Commit');
|
||||
repo.makeCommit('Second Commit');
|
||||
repo.makeCommit('Third Commit');
|
||||
repo.exec('git tag 7.6.5');
|
||||
|
||||
const result = repo.runAction();
|
||||
|
||||
expect(result).toMatch('Version is 7.6.5+0');
|
||||
|
||||
repo.clean();
|
||||
});
|
||||
Loading…
Reference in a new issue