From 5c3e32d20056eb737212bd7331cc56ed4aa28e5c Mon Sep 17 00:00:00 2001 From: Philipp Horstenkamp Date: Tue, 28 May 2024 22:11:53 +0200 Subject: [PATCH] Added arguments. --- .gitea/workflows/tryActions.yaml | 3 + index.js | 113 ++++++++++-------- ...f51a62288b0ed1d148f635575b4d90c61cdcf.json | 1 + 3 files changed, 68 insertions(+), 49 deletions(-) create mode 100644 node_modules/.cache/prettier/.prettier-caches/706f51a62288b0ed1d148f635575b4d90c61cdcf.json diff --git a/.gitea/workflows/tryActions.yaml b/.gitea/workflows/tryActions.yaml index 540d3f8..738a5b2 100644 --- a/.gitea/workflows/tryActions.yaml +++ b/.gitea/workflows/tryActions.yaml @@ -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 diff --git a/index.js b/index.js index d8e3542..0e64798 100644 --- a/index.js +++ b/index.js @@ -1,65 +1,80 @@ 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; - var min = parseInt(arr[1]) || 0; - var patch = parseInt(arr[2]) || 0; - return { - major: maj, - minor: min, - patch: patch - } + // parse int or default to 0 + var maj = parseInt(arr[0]) || 0; + var min = parseInt(arr[1]) || 0; + var patch = parseInt(arr[2]) || 0; + return { + major: maj, + minor: min, + 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); - if (url_with_version == url_pattern) { - 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) - if (version_part == "minor") { - 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}`; - } else { - throw new Error('The url does not contain an {{VERSION}} marker!'); - } - } else { - return version - } + let test_vor_existence = version; + while (true) { + 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!"); } + 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); + if (version_part == "minor") { + 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 + }`; + } else { + throw new Error("The url does not contain an {{VERSION}} marker!"); + } + } else { + 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(){ - 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); - return current_version; - } catch (error) { - core.setFailed(`Action failed with error: ${error}`); - } +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); + return current_version; + } catch (error) { + core.setFailed(`Action failed with error: ${error}`); + } } main(); diff --git a/node_modules/.cache/prettier/.prettier-caches/706f51a62288b0ed1d148f635575b4d90c61cdcf.json b/node_modules/.cache/prettier/.prettier-caches/706f51a62288b0ed1d148f635575b4d90c61cdcf.json new file mode 100644 index 0000000..f70ba27 --- /dev/null +++ b/node_modules/.cache/prettier/.prettier-caches/706f51a62288b0ed1d148f635575b4d90c61cdcf.json @@ -0,0 +1 @@ +{"0a9cd11a33d0e683718dc953b18cd8ddd9b4087f":{"files":{"index.js":["eet1sBLWVjGy4Iu3o3sSkhGQCig=",true]},"modified":1716927105637}} \ No newline at end of file