SYNERGY-999 Fix script that generates version number
This commit is contained in:
parent
6080b6937d
commit
c3f6ae708a
2 changed files with 86 additions and 50 deletions
62
.github/actions/build-number/build-number.js
vendored
62
.github/actions/build-number/build-number.js
vendored
|
|
@ -1,4 +1,5 @@
|
|||
const core = require('@actions/core');
|
||||
const { Octokit } = require("@octokit/core");
|
||||
const fs = require('fs');
|
||||
|
||||
function VersionPart(part) {
|
||||
|
|
@ -85,11 +86,17 @@ function Version(version) {
|
|||
m_build.toString());
|
||||
}
|
||||
|
||||
this.isEmpty = function(){
|
||||
return (!this.getMajor() && !this.getMinor() && !this.getPatch());
|
||||
}
|
||||
|
||||
this.nextBuild = function() {
|
||||
m_build.next();
|
||||
}
|
||||
|
||||
function init() {
|
||||
if (version)
|
||||
{
|
||||
let versionParts = version.split(PARTS_DELIMITER);
|
||||
|
||||
if (versionParts.length == 3) {
|
||||
|
|
@ -106,7 +113,8 @@ function Version(version) {
|
|||
m_build.setPart(versionParts[3]);
|
||||
}
|
||||
else {
|
||||
core.setFailed('ERROR: previous-build contains wrong version number <' + version + '>');
|
||||
core.setFailed('ERROR: wrong version number <' + version + '>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -129,8 +137,7 @@ function Version(version) {
|
|||
this.isSamePatch = function(version) {
|
||||
return (this.getMajor() == version.getMajor() &&
|
||||
this.getMinor() == version.getMinor() &&
|
||||
this.getPatch() == version.getPatch() &&
|
||||
this.getStage() == version.getStage());
|
||||
this.getPatch() == version.getPatch());
|
||||
}
|
||||
|
||||
init();
|
||||
|
|
@ -148,6 +155,34 @@ function getOptionValue(source, option) {
|
|||
}
|
||||
}
|
||||
|
||||
async function getVersionApi()
|
||||
{
|
||||
const octokit = new Octokit({});
|
||||
|
||||
let response = await octokit.request('GET /repos/{owner}/{repo}/releases?per_page=100', {
|
||||
owner: 'symless',
|
||||
repo: 'synergy-core'
|
||||
});
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function getVersionsFromGithub(cmakeVersion)
|
||||
{
|
||||
let gitVersion = new Version();
|
||||
let versions = await getVersionApi();
|
||||
|
||||
for (let i = 0; i < versions.length; ++i) {
|
||||
let version = new Version(versions[i].tag_name);
|
||||
if (version.isSamePatch(cmakeVersion)) {
|
||||
gitVersion = version;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return gitVersion;
|
||||
}
|
||||
|
||||
function getVersionFromFile(){
|
||||
let options = fs.readFileSync('cmake/Version.cmake');
|
||||
let major = getOptionValue(options, 'SYNERGY_VERSION_MAJOR');
|
||||
|
|
@ -155,23 +190,25 @@ function getVersionFromFile(){
|
|||
let patch = getOptionValue(options, 'SYNERGY_VERSION_PATCH');
|
||||
let stage = getOptionValue(options, 'SYNERGY_VERSION_STAGE');
|
||||
|
||||
return (major + '.' + minor + '.' + patch + '-' + stage);
|
||||
return new Version(major + '.' + minor + '.' + patch + '-' + stage);
|
||||
}
|
||||
|
||||
try {
|
||||
async function main()
|
||||
{
|
||||
try {
|
||||
let version = null;
|
||||
let gitVersion = new Version(core.getInput('previous-build'));
|
||||
let cmakeVersion = new Version(getVersionFromFile());
|
||||
let cmakeVersion = getVersionFromFile();
|
||||
let gitVersion = await getVersionsFromGithub(cmakeVersion);
|
||||
|
||||
console.log('INFO: Version from Git: <' + gitVersion.toString() + '>');
|
||||
console.log('INFO: Version from cmake: <' + cmakeVersion.toString() + '>');
|
||||
|
||||
if (cmakeVersion.isSamePatch(gitVersion)) {
|
||||
gitVersion.nextBuild();
|
||||
version = gitVersion;
|
||||
if (gitVersion.isEmpty()) {
|
||||
version = cmakeVersion;
|
||||
}
|
||||
else {
|
||||
version = cmakeVersion;
|
||||
gitVersion.nextBuild();
|
||||
version = gitVersion;
|
||||
}
|
||||
|
||||
console.log('INFO: Generate build version: <' + version.toString() + '>');
|
||||
|
|
@ -180,3 +217,6 @@ try {
|
|||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
main();
|
||||
10
.github/workflows/create-build.yml
vendored
10
.github/workflows/create-build.yml
vendored
|
|
@ -12,18 +12,14 @@ jobs:
|
|||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: 'Get Previous tag'
|
||||
id: previoustag
|
||||
uses: "WyriHaximus/github-action-get-previous-tag@master"
|
||||
|
||||
- name: 'Install git core'
|
||||
run: npm install @actions/core
|
||||
run: |
|
||||
npm install @actions/core
|
||||
npm install @octokit/core
|
||||
|
||||
- name: 'Generate next build number'
|
||||
id: build
|
||||
uses: "./.github/actions/build-number"
|
||||
with:
|
||||
previous-build: ${{ steps.previoustag.outputs.tag }}
|
||||
|
||||
- name: Create Release
|
||||
id: create_release
|
||||
|
|
|
|||
Loading…
Reference in a new issue