From 4716e8263d2ff56e5fd1896711a96702bf483ef0 Mon Sep 17 00:00:00 2001 From: lucasarchina Date: Wed, 18 Jan 2023 18:42:28 -0300 Subject: [PATCH] feat: add micro support. deprecate set-output. update nodeversion --- action.yml | 2 +- dist/index.js | 76 ++++++++++++++++++++------------------------------- index.js | 76 ++++++++++++++++++++------------------------------- 3 files changed, 59 insertions(+), 95 deletions(-) diff --git a/action.yml b/action.yml index 7beeae2..ca65213 100644 --- a/action.yml +++ b/action.yml @@ -18,5 +18,5 @@ outputs: version: description: "Date version" runs: - using: "node12" + using: "node16" main: "dist/index.js" diff --git a/dist/index.js b/dist/index.js index 4ce4f3b..4321aed 100644 --- a/dist/index.js +++ b/dist/index.js @@ -10087,7 +10087,7 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. (() => { // Heavily based on https://github.com/mydea/action-tag-date-version with some changes to the date and added prefix -const { setFailed, getInput, setOutput } = __nccwpck_require__(3494); +const { setFailed, getInput } = __nccwpck_require__(3494); const { context } = __nccwpck_require__(4464); const { exec } = __nccwpck_require__(5420); const semver = __nccwpck_require__(6585); @@ -10098,15 +10098,19 @@ async function run() { const prefix = getInput("prefix"); const outputOnly = getInput("output-only", { required: false }) === "true"; - const currentVersionTag = await getCurrentTag(); + // const currentVersionTag = await getCurrentTag(); - if (currentVersionTag) { - console.log(`Already at version ${currentVersionTag}, skipping...`); - setOutput("version", currentVersionTag); - return; - } + // if (currentVersionTag) { + // console.log(`Already at version ${currentVersionTag}, skipping...`); + // `version=${currentVersionTag}` >> $GITHUB_OUTPUT; + // return; + // } - const nextVersion = await getNextVersionTag(prefix, prerelease); + let nextVersion = await getNextVersionTag(prefix, prerelease); + + //Update to format yyyy.mm.dd_micro + let nextVersionArray = nextVersion.split("."); + nextVersion = `${nextVersionArray[0]}.${nextVersionArray[1]}.${nextVersionArray[2]}_${nextVersionArray[3]}`; console.log(`Next version: ${nextVersion}`); @@ -10137,8 +10141,7 @@ async function run() { `Only outputting version because output-only is set to ${outputOnly}` ); } - - setOutput("version", nextVersion); + `version=${nextVersion}` >> $GITHUB_OUTPUT; } catch (error) { setFailed(error.message); } @@ -10172,23 +10175,17 @@ async function getNextVersionTag(prefix, prerelease) { function getNextDateVersion(previousVersionTags) { const { year, month, day } = getDateParts(); - const newVersionParts = [ - `${year}`, - `${month}`, - `${day}`, - previousVersionTags.split("_")[1], - ]; - console.log(`This is previousVersionTags ${previousVersionTags}`); - if (_tagExists(newVersionParts, previousVersionTags)) { + const newVersionParts = [`${year}`, `${month}`, `${day}`, 0]; + while (_tagExists(newVersionParts, previousVersionTags)) { newVersionParts[3]++; } - return joinParts(newVersionParts); + return newVersionParts.join("."); } function getPrereleaseVersion(previousVersionTags, prerelease) { const nextVersion = getNextDateVersion(previousVersionTags); - const nextVersionParts = splitParts(nextVersion); + const nextVersionParts = nextVersion.split("."); let prereleaseVersion = 0; while ( @@ -10204,8 +10201,8 @@ function getPrereleaseVersion(previousVersionTags, prerelease) { } function _tagExists(tagParts, previousVersionTags, prereleaseParts) { - let newTag = joinParts(tagParts); - newTag = newTag.split("_")[0]; + let newTag = tagParts.join("."); + if (prereleaseParts) { const [prerelease, prereleaseVersion] = prereleaseParts; newTag = `${newTag}-${prerelease}.${prereleaseVersion}`; @@ -10215,21 +10212,24 @@ function _tagExists(tagParts, previousVersionTags, prereleaseParts) { } function processVersion(version) { - version = version.split("_")[0]; - + versionSplitted = version.replace("_", ".").split("."); + version = `${versionSplitted[0]}.${versionSplitted[1]}.${versionSplitted[2]}`; if (!semver.valid(version)) { return false; } - const { major, minor, version: parsedVersion } = semver.parse(version); + const { major, minor, patch, version: parsedVersion } = semver.parse(version); - const { year: currentYear, month: currentMonth } = getDateParts(); + const { + year: currentYear, + month: currentMonth, + day: currentDay, + } = getDateParts(); - if (major !== currentYear || minor !== currentMonth) { + if (major !== currentYear || minor !== currentMonth || patch !== currentDay) { return false; } - - return parsedVersion; + return `${parsedVersion}.${versionSplitted[3]}`; } function getDateParts() { @@ -10241,24 +10241,6 @@ function getDateParts() { return { year, month, day }; } -function joinParts(parts) { - return `${parts[0]}.${parts[1]}.${parts[2]}_${parts[3]}`; -} - -function splitParts(version) { - let verRet = []; - - verRet = version.split("."); - - const day = verRet[2].split("_")[0]; - const micro = verRet[2].split("_")[1]; - - verRet[2] = day; - verRet[3] = micro; - - return verRet; -} - async function execGetOutput(command) { let collectedOutput = []; let collectedErrorOutput = []; diff --git a/index.js b/index.js index 0e8db42..dbd596b 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ // Heavily based on https://github.com/mydea/action-tag-date-version with some changes to the date and added prefix -const { setFailed, getInput, setOutput } = require("@actions/core"); +const { setFailed, getInput } = require("@actions/core"); const { context } = require("@actions/github"); const { exec } = require("@actions/exec"); const semver = require("semver"); @@ -10,15 +10,19 @@ async function run() { const prefix = getInput("prefix"); const outputOnly = getInput("output-only", { required: false }) === "true"; - const currentVersionTag = await getCurrentTag(); + // const currentVersionTag = await getCurrentTag(); - if (currentVersionTag) { - console.log(`Already at version ${currentVersionTag}, skipping...`); - setOutput("version", currentVersionTag); - return; - } + // if (currentVersionTag) { + // console.log(`Already at version ${currentVersionTag}, skipping...`); + // `version=${currentVersionTag}` >> $GITHUB_OUTPUT; + // return; + // } + + let nextVersion = await getNextVersionTag(prefix, prerelease); - const nextVersion = await getNextVersionTag(prefix, prerelease); + //Update to format yyyy.mm.dd_micro + let nextVersionArray = nextVersion.split("."); + nextVersion = `${nextVersionArray[0]}.${nextVersionArray[1]}.${nextVersionArray[2]}_${nextVersionArray[3]}`; console.log(`Next version: ${nextVersion}`); @@ -49,8 +53,7 @@ async function run() { `Only outputting version because output-only is set to ${outputOnly}` ); } - - setOutput("version", nextVersion); + `version=${nextVersion}` >> $GITHUB_OUTPUT; } catch (error) { setFailed(error.message); } @@ -84,23 +87,17 @@ async function getNextVersionTag(prefix, prerelease) { function getNextDateVersion(previousVersionTags) { const { year, month, day } = getDateParts(); - const newVersionParts = [ - `${year}`, - `${month}`, - `${day}`, - previousVersionTags.split("_")[1], - ]; - console.log(`This is previousVersionTags ${previousVersionTags}`); - if (_tagExists(newVersionParts, previousVersionTags)) { + const newVersionParts = [`${year}`, `${month}`, `${day}`, 0]; + while (_tagExists(newVersionParts, previousVersionTags)) { newVersionParts[3]++; } - return joinParts(newVersionParts); + return newVersionParts.join("."); } function getPrereleaseVersion(previousVersionTags, prerelease) { const nextVersion = getNextDateVersion(previousVersionTags); - const nextVersionParts = splitParts(nextVersion); + const nextVersionParts = nextVersion.split("."); let prereleaseVersion = 0; while ( @@ -116,8 +113,8 @@ function getPrereleaseVersion(previousVersionTags, prerelease) { } function _tagExists(tagParts, previousVersionTags, prereleaseParts) { - let newTag = joinParts(tagParts); - newTag = newTag.split("_")[0]; + let newTag = tagParts.join("."); + if (prereleaseParts) { const [prerelease, prereleaseVersion] = prereleaseParts; newTag = `${newTag}-${prerelease}.${prereleaseVersion}`; @@ -127,21 +124,24 @@ function _tagExists(tagParts, previousVersionTags, prereleaseParts) { } function processVersion(version) { - version = version.split("_")[0]; - + versionSplitted = version.replace("_", ".").split("."); + version = `${versionSplitted[0]}.${versionSplitted[1]}.${versionSplitted[2]}`; if (!semver.valid(version)) { return false; } - const { major, minor, version: parsedVersion } = semver.parse(version); + const { major, minor, patch, version: parsedVersion } = semver.parse(version); - const { year: currentYear, month: currentMonth } = getDateParts(); + const { + year: currentYear, + month: currentMonth, + day: currentDay, + } = getDateParts(); - if (major !== currentYear || minor !== currentMonth) { + if (major !== currentYear || minor !== currentMonth || patch !== currentDay) { return false; } - - return parsedVersion; + return `${parsedVersion}.${versionSplitted[3]}`; } function getDateParts() { @@ -153,24 +153,6 @@ function getDateParts() { return { year, month, day }; } -function joinParts(parts) { - return `${parts[0]}.${parts[1]}.${parts[2]}_${parts[3]}`; -} - -function splitParts(version) { - let verRet = []; - - verRet = version.split("."); - - const day = verRet[2].split("_")[0]; - const micro = verRet[2].split("_")[1]; - - verRet[2] = day; - verRet[3] = micro; - - return verRet; -} - async function execGetOutput(command) { let collectedOutput = []; let collectedErrorOutput = [];