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}} - run: echo Current branch ${{github.ref_name}}
- name: version-up - name: version-up
uses: https://git.horstenkamp.eu/Philipp/version-up-action.git@${{github.ref_name}} 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"); const core = require("@actions/core");
function parseVersion(str) { function parseVersion(str) {
if (typeof(str) != 'string') { return false; } if (typeof str != "string") {
return false;
}
var arr = str.split('.'); var arr = str.split(".");
// parse int or default to 0 // parse int or default to 0
var maj = parseInt(arr[0]) || 0; var maj = parseInt(arr[0]) || 0;
@ -13,40 +14,54 @@ function parseVersion(str){
return { return {
major: maj, major: maj,
minor: min, minor: min,
patch: patch patch: patch,
};
} }
}
async function increaseVersionPart(url_pattern, version, version_part) { async function increaseVersionPart(url_pattern, version, version_part) {
let test_vor_existence = version; let test_vor_existence = version;
while (true) { 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) { 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, { let status = await fetch(url_with_version, {
method: "GET", method: "GET",
}).then((response) => response.status); }).then((response) => response.status);
if (status === 200) { if (status === 200) {
version = test_vor_existence; version = test_vor_existence;
const version_parsed = parseVersion(test_vor_existence) const version_parsed = parseVersion(test_vor_existence);
if (version_part == "minor") { 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") { } 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 { } else {
throw new Error('The url does not contain an {{VERSION}} marker!'); throw new Error("The url does not contain an {{VERSION}} marker!");
} }
} else { } else {
return version return version;
} }
} }
} }
async function increaseVersion(url_pattern, version) { async function increaseVersion(url_pattern, version) {
let minor = await increaseVersionPart(url_pattern, version, version_part="minor"); let minor = await increaseVersionPart(
return await increaseVersionPart(url_pattern, minor, version_part="micro"); url_pattern,
version,
(version_part = "minor"),
);
return await increaseVersionPart(
url_pattern,
minor,
(version_part = "micro"),
);
} }
async function main() { async function main() {
@ -55,7 +70,7 @@ async function main(){
const start_version = core.getInput("start-version"); const start_version = core.getInput("start-version");
const current_version = await increaseVersion(url_pattern, start_version); const current_version = await increaseVersion(url_pattern, start_version);
core.info(`The new version determend is ${current_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; return current_version;
} catch (error) { } catch (error) {
core.setFailed(`Action failed with error: ${error}`); core.setFailed(`Action failed with error: ${error}`);

View File

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