Skip to content

Commit

Permalink
Enable to release update for previous major
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Sep 9, 2022
1 parent 6a267b7 commit 1b498f1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 21 deletions.
32 changes: 23 additions & 9 deletions dist/index.js
Expand Up @@ -7899,7 +7899,7 @@ function getLatestSemVersionedTagFactory(params) {
function getLatestSemVersionedTag(params) {
var e_1, _a;
return __awaiter(this, void 0, void 0, function* () {
const { owner, repo, beta } = params;
const { owner, repo, beta, major } = params;
const semVersionedTags = [];
const { listTags } = listTags_1.listTagsFactory({ octokit });
try {
Expand All @@ -7908,6 +7908,9 @@ function getLatestSemVersionedTagFactory(params) {
let version;
try {
version = NpmModuleVersion_1.NpmModuleVersion.parse(tag.replace(/^[vV]?/, ""));
if (major !== undefined && version.major !== major) {
continue;
}
}
catch (_d) {
continue;
Expand Down Expand Up @@ -9190,7 +9193,7 @@ function action(_actionName, params, core) {
const octokit = createOctokit_1.createOctokit({ github_token });
const { getCommitAhead } = getCommitAhead_1.getCommitAheadFactory({ octokit });
const { getLatestSemVersionedTag } = getLatestSemVersionedTag_1.getLatestSemVersionedTagFactory({ octokit });
const { tag: branchBehind } = (_a = (yield getLatestSemVersionedTag({ owner, repo, "beta": "IGNORE BETA" }))) !== null && _a !== void 0 ? _a : {};
const { tag: branchBehind } = (_a = (yield getLatestSemVersionedTag({ owner, repo, "beta": "IGNORE BETA", "major": undefined }))) !== null && _a !== void 0 ? _a : {};
if (branchBehind === undefined) {
core.warning(`It's the first release, not editing the CHANGELOG.md`);
return;
Expand Down Expand Up @@ -12413,13 +12416,24 @@ function action(_actionName, params, core) {
core.debug(`Version on ${owner}/${repo}#${branch} is ${NpmModuleVersion_1.NpmModuleVersion.stringify(to_version)}`);
const octokit = createOctokit_1.createOctokit({ github_token });
const { getLatestSemVersionedTag } = getLatestSemVersionedTag_1.getLatestSemVersionedTagFactory({ octokit });
const { version: from_version } = yield getLatestSemVersionedTag({
owner,
repo,
"beta": to_version.betaPreRelease !== undefined ?
"ONLY LOOK FOR BETA" : "IGNORE BETA"
})
.then(wrap => wrap === undefined ? { "version": NpmModuleVersion_1.NpmModuleVersion.parse("0.0.0") } : wrap);
const from_version = yield (() => __awaiter(this, void 0, void 0, function* () {
const getLatestSemVersionedTagParam = {
owner,
repo,
"beta": to_version.betaPreRelease !== undefined ?
"ONLY LOOK FOR BETA" : "IGNORE BETA",
"major": to_version.major
};
let wrap = yield getLatestSemVersionedTag(getLatestSemVersionedTagParam);
if (wrap !== undefined) {
return wrap.version;
}
wrap = yield getLatestSemVersionedTag(Object.assign(Object.assign({}, getLatestSemVersionedTagParam), { "major": undefined }));
if (wrap !== undefined) {
return wrap.version;
}
return NpmModuleVersion_1.NpmModuleVersion.parse("0.0.0");
}))();
core.debug(`Last version was ${NpmModuleVersion_1.NpmModuleVersion.stringify(from_version)}`);
const is_upgraded_version = NpmModuleVersion_1.NpmModuleVersion.compare(to_version, from_version) === 1 ? "true" : "false";
core.debug(`Is version upgraded: ${is_upgraded_version}`);
Expand Down
40 changes: 30 additions & 10 deletions src/is_package_json_version_upgraded.ts
Expand Up @@ -6,6 +6,8 @@ import { NpmModuleVersion } from "./tools/NpmModuleVersion";
import { getActionParamsFactory } from "./inputHelper";
import { createOctokit } from "./tools/createOctokit";
import { getLatestSemVersionedTagFactory } from "./tools/octokit-addons/getLatestSemVersionedTag";
import type { Param0 } from "tsafe";


export const { getActionParams } = getActionParamsFactory({
"inputNameSubset": [
Expand Down Expand Up @@ -52,13 +54,31 @@ export async function action(

const { getLatestSemVersionedTag } = getLatestSemVersionedTagFactory({ octokit });

const { version: from_version } = await getLatestSemVersionedTag({
owner,
repo,
"beta": to_version.betaPreRelease !== undefined ?
"ONLY LOOK FOR BETA" : "IGNORE BETA"
})
.then(wrap => wrap === undefined ? { "version": NpmModuleVersion.parse("0.0.0") } : wrap);
const from_version= await (async () => {

const getLatestSemVersionedTagParam: Param0<typeof getLatestSemVersionedTag> = {
owner,
repo,
"beta": to_version.betaPreRelease !== undefined ?
"ONLY LOOK FOR BETA" : "IGNORE BETA",
"major": to_version.major
};

let wrap = await getLatestSemVersionedTag(getLatestSemVersionedTagParam);

if( wrap !== undefined ){
return wrap.version;
}
wrap = await getLatestSemVersionedTag({ ...getLatestSemVersionedTagParam, "major": undefined });

if( wrap !== undefined ){
return wrap.version;
}

return NpmModuleVersion.parse("0.0.0");


})();

core.debug(`Last version was ${NpmModuleVersion.stringify(from_version)}`);

Expand All @@ -69,7 +89,7 @@ export async function action(

core.debug(`Is version upgraded: ${is_upgraded_version}`);

const is_release_beta= is_upgraded_version === "false" ? "false" : to_version.betaPreRelease !== undefined ? "true" : "false";
const is_release_beta = is_upgraded_version === "false" ? "false" : to_version.betaPreRelease !== undefined ? "true" : "false";

core.debug(`Is release beta: ${is_release_beta}`);

Expand Down Expand Up @@ -103,10 +123,10 @@ async function getPackageJsonVersion(params: {
.then(res => res.text())
.then(text => JSON.parse(text))
.then(({ version }) => version as string)
.catch(()=> undefined)
.catch(() => undefined)
;

if( version === undefined){
if (version === undefined) {
return undefined;
}

Expand Down
7 changes: 6 additions & 1 deletion src/tools/octokit-addons/getLatestSemVersionedTag.ts
Expand Up @@ -12,13 +12,14 @@ export function getLatestSemVersionedTagFactory(params: { octokit: Octokit; }) {
owner: string;
repo: string;
beta: "ONLY LOOK FOR BETA" | "IGNORE BETA" | "BETA OR REGULAR RELEASE";
major: number | undefined;
}
): Promise<{
tag: string;
version: NpmModuleVersion;
} | undefined> {

const { owner, repo, beta } = params;
const { owner, repo, beta, major } = params;

const semVersionedTags: { tag: string; version: NpmModuleVersion; }[] = [];

Expand All @@ -32,6 +33,10 @@ export function getLatestSemVersionedTagFactory(params: { octokit: Octokit; }) {

version = NpmModuleVersion.parse(tag.replace(/^[vV]?/, ""));

if (major !== undefined && version.major !== major) {
continue;
}

} catch {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/update_changelog.ts
Expand Up @@ -57,7 +57,7 @@ export async function action(

const { getLatestSemVersionedTag } = getLatestSemVersionedTagFactory({ octokit });

const { tag: branchBehind } = (await getLatestSemVersionedTag({ owner, repo, "beta": "IGNORE BETA" })) ?? {};
const { tag: branchBehind } = (await getLatestSemVersionedTag({ owner, repo, "beta": "IGNORE BETA", "major": undefined })) ?? {};

if( branchBehind === undefined ){

Expand Down

0 comments on commit 1b498f1

Please sign in to comment.