diff --git a/deploy/package.json b/deploy/package.json index fa7c31b..81e1323 100644 --- a/deploy/package.json +++ b/deploy/package.json @@ -14,12 +14,14 @@ "@actions/core": "1.2.5", "semver": "7.3.4", "latest-version": "5.1.0", - "lodash.set": "4.3.2" + "lodash.set": "4.3.2", + "lodash.isempty": "4.4.0" }, "devDependencies": { "@types/semver": "7.3.4", "@types/lodash.omit": "4.5.6", "@types/lodash.set": "4.3.6", + "@types/lodash.isempty": "4.4.6", "jest": "26.6.3", "ts-jest": "26.5.1", "lodash.omit": "4.5.0", diff --git a/deploy/src/main.ts b/deploy/src/main.ts index 1c716df..e8fe96b 100644 --- a/deploy/src/main.ts +++ b/deploy/src/main.ts @@ -2,6 +2,7 @@ import { URL } from 'url' import * as path from 'path' import * as core from '@actions/core' import setByPath from 'lodash.set' +import isEmpty from 'lodash.isempty' import { execSync } from 'child_process' import { readFileSync, writeFileSync } from 'fs' import latestVersion from 'latest-version' @@ -36,8 +37,9 @@ export const main = async (): Promise => { } const specificCliVersion = core.getInput('cli_version') - const cliVersion = - specificCliVersion ?? (await latestVersion('resolve-cloud')) + const cliVersion = isEmpty(specificCliVersion) + ? await latestVersion('resolve-cloud') + : specificCliVersion core.debug(`setting cloud CLI version to (${cliVersion})`) setByPath(pkg, 'devDependencies.resolve-cloud', cliVersion) @@ -77,10 +79,13 @@ export const main = async (): Promise => { : (val) => val const inputAppName = core.getInput('name') - let targetAppName = randomizer(inputAppName ?? readPackage(pkgFile).name) + core.debug(`input app name: ${inputAppName}`) - core.debug(`target application path: ${appDir}`) + const targetAppName = randomizer( + isEmpty(inputAppName) ? readPackage(pkgFile).name : inputAppName + ) core.debug(`target application name: ${targetAppName}`) + core.debug(`target application path: ${appDir}`) if (!parseBoolean(core.getInput('local_run'))) { writeResolveRc( diff --git a/deploy/test/main.test.ts b/deploy/test/main.test.ts index f8f07a9..809c116 100644 --- a/deploy/test/main.test.ts +++ b/deploy/test/main.test.ts @@ -142,6 +142,17 @@ test('cloud cli version patched to latest available', async () => { ) }) +test('cloud cli version patched to latest available (specific version is empty string)', async () => { + actionInput.cli_version = '' + + await main() + + expect(mLatestVersion).toHaveBeenCalledWith('resolve-cloud') + expect(getPackageContent()?.devDependencies?.['resolve-cloud']).toEqual( + '1.2.3' + ) +}) + test('cloud cli version patched to specific version', async () => { actionInput.cli_version = '5.4.3' @@ -271,6 +282,18 @@ test('app name from package.json', async () => { ) }) +test('app name from package.json (input is empty string)', async () => { + actionInput.name = '' + actionInput.randomize_name = 'false' + + await main() + + expect(mCLI).toHaveBeenCalledWith( + expect.stringContaining(`--name package`), + expect.anything() + ) +}) + test('randomized app name from package.json', async () => { actionInput.randomize_name = 'true'