Skip to content

Commit 1f5e2e0

Browse files
committed
refactor
1 parent 57607c2 commit 1f5e2e0

3 files changed

Lines changed: 19 additions & 24 deletions

File tree

dist/index.js

Lines changed: 8 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/get-current-version.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@ export async function getCurrentVersion(token: string): Promise<string> {
1717
}
1818
);
1919

20+
const notFoundMessage =
21+
'No current version found. If this is not expected, check your org, package name and token.';
22+
2023
if (!response.ok) {
2124
if (response.status === 404) {
22-
console.log('No current version found');
25+
console.log(notFoundMessage);
2326
return '';
2427
}
2528
throw new Error(`Failed to get current version: ${response.statusText}`);
2629
}
2730

2831
const body: GithubPackageVersion[] = await response.json();
2932
if (body.length === 0) {
30-
console.log('No current version found');
33+
console.log(notFoundMessage);
3134
return '';
3235
}
3336

src/main.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import { getNextBetaVersion, getNextVersion } from './get-next-version';
33
import { getCurrentVersion } from './get-current-version';
44

55
function setFirstVersion(mainVersion: string, minorVersion: string) {
6-
const nextVersion = `${mainVersion}.${minorVersion}.0`;
7-
core.setOutput('version', nextVersion);
6+
core.setOutput('version', `${mainVersion}.${minorVersion}.0`);
87
}
98

109
function setFirstBetaVersion(mainVersion: string, minorVersion: string) {
11-
const nextVersion = `${mainVersion}.${minorVersion}.0`;
12-
core.setOutput('version', `${nextVersion}-beta.1`);
10+
core.setOutput('version', `${mainVersion}.${minorVersion}.0-beta.1`);
1311
}
1412

1513
/**
@@ -27,8 +25,7 @@ export async function run(): Promise<void> {
2725
}
2826
const minorVersion = core.getInput('minorVersion');
2927
const majorVersion = core.getInput('majorVersion');
30-
const publishBeta: boolean =
31-
core.getInput('publishBeta').toLowerCase() === 'true';
28+
const publishBeta = core.getInput('publishBeta').toLowerCase() === 'true';
3229

3330
const currentVersion = await getCurrentVersion(token);
3431

@@ -55,11 +52,9 @@ export async function run(): Promise<void> {
5552
return;
5653
}
5754

58-
if (publishBeta) {
59-
core.setOutput('version', getNextBetaVersion(currentVersion));
60-
return;
61-
}
62-
core.setOutput('version', getNextVersion(currentVersion));
55+
publishBeta
56+
? core.setOutput('version', getNextBetaVersion(currentVersion))
57+
: core.setOutput('version', getNextVersion(currentVersion));
6358
} catch (error) {
6459
// Fail the workflow run if an error occurs
6560
if (error instanceof Error) core.setFailed(error.message);

0 commit comments

Comments
 (0)