From 5db04be2cb9a71b53c001bec97170b3dbbf08991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Falc=C3=A3o?= Date: Tue, 7 Nov 2023 23:35:50 +0000 Subject: [PATCH] annotates the build with error when user does not define the `default' input refs #435 --- README.rst | 5 ++--- __tests__/installer.test.ts | 8 +++++++- __tests__/parsedinputs.test.ts | 20 ++++++++++++++++++++ dist/index.js | 3 +++ src/engine.ts | 3 +++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 68da85b5e..367be478b 100644 --- a/README.rst +++ b/README.rst @@ -29,7 +29,6 @@ Features: Usage ===== - Example ------- @@ -37,7 +36,6 @@ Installs python versions 3.8.16 and 3.9 with pyenv, upgrade pip for each of them and run pytest. - .. code:: yaml name: Using @@ -110,8 +108,9 @@ Inputs The default python version to install and set with ``pyenv local `` -Must be a valid python version supported by ``pyenv install `` +MUST be a valid python version supported by ``pyenv install `` +**MUST** be defined Example: diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 2f829757a..7757b0fd5 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -28,12 +28,18 @@ https: describe('PyEnvInstaller', () => { process.env['RUNNER_TOOL_CACHE'] = toolDir; process.env['RUNNER_TEMP'] = tempDir; }, 100000); - it('Can download and cache the archive', async () => { + it('Can download default version and cache the archive', async () => { const installer = new engine.PyEnvInstaller(defaults.PYENV_VERSION); const archive_path = await installer.downloadArchive(); expect(fs.existsSync(archive_path)).toBeTruthy(); }); + it('Can download specified version and cache the archive', async () => { + const installer = new engine.PyEnvInstaller("2.3.25"); + const archive_path = await installer.downloadArchive(); + expect(fs.existsSync(archive_path)).toBeTruthy(); + }); + it('Throws error if required pyenv version could not be downloaded', async () => { const installer = new engine.PyEnvInstaller('0.0.0'); diff --git a/__tests__/parsedinputs.test.ts b/__tests__/parsedinputs.test.ts index 962d45bb1..ad4eecded 100644 --- a/__tests__/parsedinputs.test.ts +++ b/__tests__/parsedinputs.test.ts @@ -1,3 +1,14 @@ +jest.mock('@actions/core', () => { + const originalModule = jest.requireActual('@actions/core'); + return { + __esModule: true, + ...originalModule, + error: jest.fn(), + exportVariable: jest.fn(), + setOutput: jest.fn(), + }; +}); +const core = require('@actions/core'); import * as engine from '../src/engine'; describe('ParsedInputs', () => { @@ -5,6 +16,15 @@ describe('ParsedInputs', () => { const inputs = new engine.ParsedInputs(); expect(inputs.versions).toEqual([]); }); + it("annotates the build with error when user does not define the `default' input", () => { + + process.env['INPUT_DEFAULT'] = ''; + process.env['INPUT_VERSIONS'] = ''; + + const inputs = new engine.ParsedInputs(); + expect(core.error.mock.calls).toHaveLength(1); + expect(core.error.mock.calls[0]).toEqual(["the `default' input appears to be undefined or empty"]); + }); it('list versions when only default is provided', () => { // Given that the input "default: 3.7.2" process.env['INPUT_DEFAULT'] = '3.7.2'; diff --git a/dist/index.js b/dist/index.js index 89c55490c..ee4217c7c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13533,6 +13533,9 @@ class ParsedInputs { this.default_version = core.getInput('default'); this.command = core.getInput('command') || ''; this.explicit_versions = utils.splitcommas(core.getInput('versions')); + if (this.default_version === undefined || `${this.default_version}`.trim().length === 0) { + core.error("the `default' input appears to be undefined or empty"); + } } get versions() { const values = utils.unique(this.explicit_versions); diff --git a/src/engine.ts b/src/engine.ts index 7bdecf11c..cbdfc764c 100644 --- a/src/engine.ts +++ b/src/engine.ts @@ -23,6 +23,9 @@ export class ParsedInputs { this.default_version = core.getInput('default'); this.command = core.getInput('command') || ''; this.explicit_versions = utils.splitcommas(core.getInput('versions')); + if (this.default_version === undefined || `${this.default_version}`.trim().length === 0) { + core.error("the `default' input appears to be undefined or empty") + } } get versions() { const values = utils.unique(this.explicit_versions);