Initiated the action. #1

Merged
Philipp merged 28 commits from philipp-patch-1 into main 2024-05-28 23:29:17 +02:00
3 changed files with 68 additions and 49 deletions
Showing only changes of commit 5c3e32d200 - Show all commits

View File

@ -15,3 +15,6 @@ jobs:
- run: echo Current branch ${{github.ref_name}}
- name: version-up
uses: https://git.horstenkamp.eu/Philipp/version-up-action.git@${{github.ref_name}}
with:
url-pattern: https://dl.gitea.com/act_runner/{{VERSION}}/act_runner-{{VERSION}}-linux-arm-7
start-version: 0.1.1

View File

@ -1,10 +1,11 @@
const core = require("@actions/core");
function parseVersion(str) {
if (typeof str != "string") {
return false;
}
function parseVersion(str){
if (typeof(str) != 'string') { return false; }
var arr = str.split('.');
var arr = str.split(".");
// parse int or default to 0
var maj = parseInt(arr[0]) || 0;
@ -13,49 +14,63 @@ function parseVersion(str){
return {
major: maj,
minor: min,
patch: patch
}
patch: patch,
};
}
async function increaseVersionPart(url_pattern, version, version_part) {
let test_vor_existence = version;
while (true) {
const url_with_version = url_pattern.replace(/{{VERSION}}/g, test_vor_existence);
const url_with_version = url_pattern.replace(
/{{VERSION}}/g,
test_vor_existence,
);
if (url_with_version == url_pattern) {
throw new Error('The url does not contain an {{VERSION}} marker!');
throw new Error("The url does not contain an {{VERSION}} marker!");
}
let status = await fetch(url_with_version, {
method: "GET",
}).then((response) => response.status);
if (status === 200) {
version = test_vor_existence;
const version_parsed = parseVersion(test_vor_existence)
const version_parsed = parseVersion(test_vor_existence);
if (version_part == "minor") {
test_vor_existence = `${version_parsed.major}.${version_parsed.minor + 1}.0`;
test_vor_existence = `${version_parsed.major}.${
version_parsed.minor + 1
}.0`;
} else if (version_part == "micro") {
test_vor_existence = `${version_parsed.major}.${version_parsed.minor}.${version_parsed.patch + 1}`;
test_vor_existence = `${version_parsed.major}.${version_parsed.minor}.${
version_parsed.patch + 1
}`;
} else {
throw new Error('The url does not contain an {{VERSION}} marker!');
throw new Error("The url does not contain an {{VERSION}} marker!");
}
} else {
return version
return version;
}
}
}
async function increaseVersion(url_pattern, version) {
let minor = await increaseVersionPart(url_pattern, version, version_part="minor");
return await increaseVersionPart(url_pattern, minor, version_part="micro");
let minor = await increaseVersionPart(
url_pattern,
version,
(version_part = "minor"),
);
return await increaseVersionPart(
url_pattern,
minor,
(version_part = "micro"),
);
}
async function main(){
async function main() {
try {
const url_pattern = core.getInput("url-pattern");
const start_version = core.getInput("start-version");
const current_version = await increaseVersion(url_pattern, start_version);
core.info(`The new version determend is ${current_version}`);
core.setOutput('max_version', current_version);
core.setOutput("max_version", current_version);
return current_version;
} catch (error) {
core.setFailed(`Action failed with error: ${error}`);

View File

@ -0,0 +1 @@
{"0a9cd11a33d0e683718dc953b18cd8ddd9b4087f":{"files":{"index.js":["eet1sBLWVjGy4Iu3o3sSkhGQCig=",true]},"modified":1716927105637}}