Skip to content

Commit

Permalink
test if version upgraded: Beta release independent from regular release
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Aug 2, 2022
1 parent 66b83c9 commit 6a267b7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
25 changes: 20 additions & 5 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, doIgnoreBeta } = params;
const { owner, repo, beta } = params;
const semVersionedTags = [];
const { listTags } = listTags_1.listTagsFactory({ octokit });
try {
Expand All @@ -7912,8 +7912,18 @@ function getLatestSemVersionedTagFactory(params) {
catch (_d) {
continue;
}
if (doIgnoreBeta && version.betaPreRelease !== undefined) {
continue;
switch (beta) {
case "IGNORE BETA":
if (version.betaPreRelease !== undefined) {
continue;
}
break;
case "ONLY LOOK FOR BETA":
if (version.betaPreRelease === undefined) {
continue;
}
case "BETA OR REGULAR RELEASE":
break;
}
semVersionedTags.push({ tag, version });
}
Expand Down Expand Up @@ -9180,7 +9190,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, "doIgnoreBeta": true }))) !== null && _a !== void 0 ? _a : {};
const { tag: branchBehind } = (_a = (yield getLatestSemVersionedTag({ owner, repo, "beta": "IGNORE BETA" }))) !== 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 @@ -12403,7 +12413,12 @@ 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, "doIgnoreBeta": false })
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);
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";
Expand Down
10 changes: 8 additions & 2 deletions src/is_package_json_version_upgraded.ts
Expand Up @@ -45,13 +45,19 @@ export async function action(
throw new Error(`No version in package.json on ${owner}/${repo}#${branch} (or repo is private)`);
}


core.debug(`Version on ${owner}/${repo}#${branch} is ${NpmModuleVersion.stringify(to_version)}`);

const octokit = createOctokit({ github_token });

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

const { version: from_version } = await getLatestSemVersionedTag({ owner, repo, "doIgnoreBeta": false })
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);

core.debug(`Last version was ${NpmModuleVersion.stringify(from_version)}`);
Expand Down
36 changes: 23 additions & 13 deletions src/tools/octokit-addons/getLatestSemVersionedTag.ts
@@ -1,24 +1,24 @@

import { listTagsFactory } from "./listTags";
import type { Octokit } from "@octokit/rest";
import { NpmModuleVersion } from "../NpmModuleVersion";
import { NpmModuleVersion } from "../NpmModuleVersion";

export function getLatestSemVersionedTagFactory(params: { octokit: Octokit; }) {

const { octokit } = params;

async function getLatestSemVersionedTag(
params: {
owner: string;
repo: string;
doIgnoreBeta: boolean;
params: {
owner: string;
repo: string;
beta: "ONLY LOOK FOR BETA" | "IGNORE BETA" | "BETA OR REGULAR RELEASE";
}
): Promise<{
tag: string;
version: NpmModuleVersion;
): Promise<{
tag: string;
version: NpmModuleVersion;
} | undefined> {

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

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

Expand All @@ -28,16 +28,26 @@ export function getLatestSemVersionedTagFactory(params: { octokit: Octokit; }) {

let version: NpmModuleVersion;

try{
try {

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

}catch{
} catch {
continue;
}

if( doIgnoreBeta && version.betaPreRelease !== undefined ){
continue;
switch (beta) {
case "IGNORE BETA":
if (version.betaPreRelease !== undefined) {
continue;
}
break;
case "ONLY LOOK FOR BETA":
if (version.betaPreRelease === undefined) {
continue;
}
case "BETA OR REGULAR RELEASE":
break;
}

semVersionedTags.push({ tag, version });
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, "doIgnoreBeta": true })) ?? {};
const { tag: branchBehind } = (await getLatestSemVersionedTag({ owner, repo, "beta": "IGNORE BETA" })) ?? {};

if( branchBehind === undefined ){

Expand Down

0 comments on commit 6a267b7

Please sign in to comment.