Skip to content

Commit

Permalink
Merge pull request #2 from lucasarchina/update-features
Browse files Browse the repository at this point in the history
feat: add micro support. deprecate set-output. update nodeversion
  • Loading branch information
lucasarchina authored Jan 18, 2023
2 parents 92b1958 + 4716e82 commit 22b0bdc
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 95 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ outputs:
version:
description: "Date version"
runs:
using: "node12"
using: "node16"
main: "dist/index.js"
76 changes: 29 additions & 47 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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}`);

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 (
Expand All @@ -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}`;
Expand All @@ -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() {
Expand All @@ -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 = [];
Expand Down
76 changes: 29 additions & 47 deletions index.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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}`);

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 (
Expand All @@ -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}`;
Expand All @@ -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() {
Expand All @@ -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 = [];
Expand Down

0 comments on commit 22b0bdc

Please sign in to comment.