mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-27 04:58:17 +00:00
Initial Commit
This commit is contained in:
commit
1492f3f1e2
10 changed files with 6849 additions and 0 deletions
26
.github/workflows/test.yml
vendored
Normal file
26
.github/workflows/test.yml
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
name: "test-local"
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- "releases/*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
- name: NPM Install
|
||||||
|
run: npm ci
|
||||||
|
- name: Test
|
||||||
|
run: npm test
|
||||||
|
- name: Package
|
||||||
|
run: npm run package
|
||||||
|
- name: Run Action
|
||||||
|
uses: ./
|
||||||
|
id: run
|
||||||
|
with:
|
||||||
|
main-branch: master
|
||||||
|
release-branch: release
|
||||||
65
.gitignore
vendored
Normal file
65
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Editors
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Other Dependency directories
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# TypeScript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
|
|
||||||
|
# next.js build output
|
||||||
|
.next
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2019 Paul Hatcherian
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
37
action.yml
Normal file
37
action.yml
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
name: "Semantic Version"
|
||||||
|
description: "Determines version of a repo"
|
||||||
|
branding:
|
||||||
|
icon: "layers"
|
||||||
|
color: "blue"
|
||||||
|
inputs:
|
||||||
|
main_branch:
|
||||||
|
description: "main branch"
|
||||||
|
required: true
|
||||||
|
default: "master"
|
||||||
|
release_branch:
|
||||||
|
description: "the release branch pattern which be be used as a prefix for release branches"
|
||||||
|
required: true
|
||||||
|
default: "release"
|
||||||
|
major_pattern:
|
||||||
|
description: "a string which, if present in a git commit, indicates that a change represents a major (breaking) change"
|
||||||
|
required: true
|
||||||
|
default: "(MAJOR)"
|
||||||
|
minor_pattern:
|
||||||
|
description: "a string which, if present in a git commit, indicates that a change represents a minor (feature) change"
|
||||||
|
required: true
|
||||||
|
default: "(MINOR)"
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
major:
|
||||||
|
description: "Current major number"
|
||||||
|
minor:
|
||||||
|
description: "Current minor number"
|
||||||
|
patch:
|
||||||
|
description: "Current patch number"
|
||||||
|
increment:
|
||||||
|
description: "An additional value indicating the number of commits for the current version"
|
||||||
|
version:
|
||||||
|
description: "The version result, in the format {major}.{minor}.{patch}"
|
||||||
|
runs:
|
||||||
|
using: "node12"
|
||||||
|
main: "dist/index.js"
|
||||||
1068
dist/index.js
vendored
Normal file
1068
dist/index.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
87
index.js
Normal file
87
index.js
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
const core = require('@actions/core');
|
||||||
|
const exec = require("@actions/exec");
|
||||||
|
const eol = require('os').EOL;
|
||||||
|
|
||||||
|
const cmd = async (command, ...args) => {
|
||||||
|
let output = '';
|
||||||
|
const options = {};
|
||||||
|
options.listeners = {
|
||||||
|
silent: true,
|
||||||
|
stdout: (data) => { output += data.toString(); }
|
||||||
|
};
|
||||||
|
await exec.exec(command, args, options)
|
||||||
|
.catch(err => core.error(err));
|
||||||
|
return output;
|
||||||
|
};
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
try {
|
||||||
|
const remotePrefix = 'origin/';
|
||||||
|
|
||||||
|
const releasePattern = `${remotePrefix}${core.getInput('release_branch', { required: true })}/*`;
|
||||||
|
const majorPattern = core.getInput('major_pattern', { required: true });
|
||||||
|
const minorPattern = core.getInput('minor_pattern', { required: true });
|
||||||
|
const mainBranch = `${remotePrefix}${core.getInput('main_branch', { required: true })}`;
|
||||||
|
|
||||||
|
let major = 0, minor = 0, patch = 0;
|
||||||
|
|
||||||
|
let branches = await cmd(
|
||||||
|
'git',
|
||||||
|
`branch`,
|
||||||
|
`-r`,
|
||||||
|
`--list`,
|
||||||
|
`--format='%(refname:short)'`,
|
||||||
|
`--sort=-committerdate`,
|
||||||
|
releasePattern
|
||||||
|
);
|
||||||
|
|
||||||
|
var root;
|
||||||
|
if (branches === '') {
|
||||||
|
// no release branches yet, use the initial commit as the root
|
||||||
|
root = await cmd('git', `rev-list`, `--max-parents=0`, mainBranch);
|
||||||
|
} else {
|
||||||
|
// find the merge base between the last
|
||||||
|
var releaseBranch = branches.split(eol)[0];
|
||||||
|
var versionValues = releaseBranch.split('/')[1].split('.');
|
||||||
|
major = parseInt(versionValues[0]);
|
||||||
|
minor = parseInt(versionValues[1]);
|
||||||
|
patch = parseInt(versionValues[2]);
|
||||||
|
|
||||||
|
root = await cmd('git', `merge-base`, releaseBranch, mainBranch);
|
||||||
|
}
|
||||||
|
root = root.trim();
|
||||||
|
|
||||||
|
let history = (await cmd('git', 'log', '--pretty="%s"', root, mainBranch)).split(eol);
|
||||||
|
|
||||||
|
patch++;
|
||||||
|
var increment = history.length;
|
||||||
|
for (var i = 0; i < history.length; i++) {
|
||||||
|
if (history[i].indexOf(majorPattern) !== -1) {
|
||||||
|
major++;
|
||||||
|
minor = 0;
|
||||||
|
patch = 0;
|
||||||
|
increment = i + 1;
|
||||||
|
break;
|
||||||
|
} else if (history[i].indexOf(minorPattern) !== -1) {
|
||||||
|
minor++;
|
||||||
|
patch = 0;
|
||||||
|
increment = i + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let version = `${major}.${minor}.${patch}`;
|
||||||
|
core.info(`Version is ${version}+${increment}`);
|
||||||
|
core.setOutput("version", version);
|
||||||
|
core.setOutput("major", major);
|
||||||
|
core.setOutput("minor", minor);
|
||||||
|
core.setOutput("patch", patch);
|
||||||
|
core.setOutput("increment", increment);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
core.setFailed(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
22
index.test.js
Normal file
22
index.test.js
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*global test */
|
||||||
|
const cp = require('child_process');
|
||||||
|
const path = require('path');
|
||||||
|
const process = require('process');
|
||||||
|
|
||||||
|
// shows how the runner will run a javascript action with env / stdout protocol
|
||||||
|
test('test runs', () => {
|
||||||
|
process.env['INPUT_MAIN_BRANCH'] = "master";
|
||||||
|
process.env['INPUT_RELEASE_BRANCH'] = "release";
|
||||||
|
process.env['INPUT_MAJOR_PATTERN'] = "(MAJOR)";
|
||||||
|
process.env['INPUT_MINOR_PATTERN'] = "(MINOR)";
|
||||||
|
|
||||||
|
const ip = path.join(__dirname, 'index.js');
|
||||||
|
try {
|
||||||
|
console.log(cp.execSync(`node ${ip}`, { env: process.env }).toString());
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error(String(e.stdout));
|
||||||
|
console.error(String(e.stderr));
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
})
|
||||||
5463
package-lock.json
generated
Normal file
5463
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
35
package.json
Normal file
35
package.json
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"name": "semantic-version",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Semantic Version GitHub Action",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"lint": "eslint index.js",
|
||||||
|
"package": "ncc build index.js -o dist",
|
||||||
|
"test": "eslint index.js && jest"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/paulhatch/semantic-version.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"GitHub",
|
||||||
|
"Actions",
|
||||||
|
"JavaScript"
|
||||||
|
],
|
||||||
|
"author": "Paul Hatcherian",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/paulhatch/semantic-version/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/paulhatch/semantic-version#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/core": "^1.1.1",
|
||||||
|
"@actions/exec": "^1.0.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@zeit/ncc": "^0.20.5",
|
||||||
|
"eslint": "^6.3.0",
|
||||||
|
"jest": "^24.9.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
25
readme.md
Normal file
25
readme.md
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://github.com/paulhatch/semantic-version"><img alt="GitHub Actions status" src="https://github.com/paulhatch/semantic-version/workflows/test-local/badge.svg"></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
# Git-Based Semantic Versioning
|
||||||
|
|
||||||
|
This action produces a [semantic version](https://semver.org) for a repository
|
||||||
|
using the repositories git history.
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
<!-- start usage -->
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: paulhatch/semantic-version@v1
|
||||||
|
with:
|
||||||
|
#
|
||||||
|
main_branch: "master"
|
||||||
|
# The release branch pattern which be be used as a prefix for release branches
|
||||||
|
release_branch: "release"
|
||||||
|
# A string which, if present in a git commit, indicates that a change represents a major (breaking) change
|
||||||
|
major_pattern: "(MAJOR)"
|
||||||
|
# Same as above except indicating a minor change
|
||||||
|
minor_pattern: "(MINOR)"
|
||||||
|
```
|
||||||
Loading…
Reference in a new issue