Skip to content

Commit

Permalink
Updated input param name
Browse files Browse the repository at this point in the history
Changed INPUT_UPDATE_TYPE to INPUT_RELEASE_TYPE for consistency
  • Loading branch information
ben-v committed Sep 22, 2023
1 parent cf42955 commit d5dad9c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
12 changes: 6 additions & 6 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('action', () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case 'INPUT_UPDATE_TYPE':
case 'INPUT_RELEASE_TYPE':
return 'MAJOR'
case 'INPUT_VERSION_JSON':
return '{"major":31,"minor":1,"patch":0,"build":457,"revision":0,"versionSuffix":"alpha"}'
Expand All @@ -42,7 +42,7 @@ describe('action', () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case 'INPUT_UPDATE_TYPE':
case 'INPUT_RELEASE_TYPE':
return 'MAJOR'
case 'INPUT_VERSION_JSON':
return '{"major":31,"minor":1,"patch":0,"build":457,"revision":0,"versionSuffix":"alpha"}'
Expand All @@ -59,7 +59,7 @@ describe('action', () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case 'INPUT_UPDATE_TYPE':
case 'INPUT_RELEASE_TYPE':
return 'MINOR'
case 'INPUT_VERSION_JSON':
return '{"major":31,"minor":1,"patch":0,"build":457,"revision":0,"versionSuffix":"alpha"}'
Expand All @@ -76,7 +76,7 @@ describe('action', () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case 'INPUT_UPDATE_TYPE':
case 'INPUT_RELEASE_TYPE':
return 'PATCH'
case 'INPUT_VERSION_JSON':
return '{"major":31,"minor":1,"patch":0,"build":457,"revision":0,"versionSuffix":"alpha"}'
Expand All @@ -93,7 +93,7 @@ describe('action', () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case 'INPUT_UPDATE_TYPE':
case 'INPUT_RELEASE_TYPE':
return 'invalid'
case 'INPUT_VERSION_JSON':
return '{"major":31,"minor":1,"patch":0,"build":457,"revision":0,"versionSuffix":"alpha"}'
Expand All @@ -116,7 +116,7 @@ describe('action', () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case 'INPUT_UPDATE_TYPE':
case 'INPUT_RELEASE_TYPE':
return 'MAJOR'
case 'INPUT_VERSION_JSON':
return 'this is not valid version json'
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ author: "Teq Bench"

# Define your inputs here.
inputs:
INPUT_UPDATE_TYPE:
INPUT_RELEASE_TYPE:
description: "Type of version update. Options: MAJOR, MINOR, PATCH."
required: true
INPUT_VERSION_JSON:
Expand Down
20 changes: 10 additions & 10 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import * as core from '@actions/core'

enum VersionUpdateType {
interface Version {
major: number
minor: number
patch: number
build: number
revision: number
suffix: string
}

enum VersionReleaseType {
MAJOR = 'MAJOR',
MINOR = 'MINOR',
PATCH = 'PATCH'
Expand All @@ -16,9 +25,9 @@ export async function run(): Promise<void> {
// error when trying to cast a string to the enum.
// Per https://thoughtbot.com/blog/the-trouble-with-typescript-enums, what's implemented below
// seems to be the best workaround
const updateType: VersionUpdateType | undefined = Object.values(
VersionUpdateType
).find(x => x === core.getInput('INPUT_UPDATE_TYPE'))
const updateType: VersionReleaseType | undefined = Object.values(
VersionReleaseType
).find(x => x === core.getInput('INPUT_RELEASE_TYPE'))

if (updateType === undefined) {
throw new Error('Update type is undefined')
Expand All @@ -38,23 +47,14 @@ export async function run(): Promise<void> {
}

async function processVersionJson(
updateType: VersionUpdateType
updateType: VersionReleaseType
): Promise<void> {
interface Version {
major: number
minor: number
patch: number
build: number
revision: number
suffix: string
}

try {
const version: Version = JSON.parse(core.getInput('INPUT_VERSION_JSON'))

// NOTE: for Trading Toolbox, patch and reversion are the same.
switch (updateType) {
case VersionUpdateType.MAJOR: {
case VersionReleaseType.MAJOR: {
// Increment major version component is unchanged.
// Reset minor, patch/revision to 0.

Expand All @@ -64,7 +64,7 @@ async function processVersionJson(

break
}
case VersionUpdateType.MINOR: {
case VersionReleaseType.MINOR: {
// Major version component is unchanged.
// Increment minor version component.
// Reset patch/revision to 0.
Expand All @@ -74,7 +74,7 @@ async function processVersionJson(

break
}
case VersionUpdateType.PATCH: {
case VersionReleaseType.PATCH: {
// Major version component is unchanged.
// Minor version component is unchanged.
// Incremment patch/revision.
Expand Down

0 comments on commit d5dad9c

Please sign in to comment.