Skip to content

Commit

Permalink
annotates the build with error when user does not define the `default…
Browse files Browse the repository at this point in the history
…' input

refs #435
  • Loading branch information
gabrielfalcao committed Nov 7, 2023
1 parent 35841bc commit 5db04be
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ Features:
Usage
=====


Example
-------

Installs python versions 3.8.16 and 3.9 with pyenv, upgrade pip for
each of them and run pytest.



.. code:: yaml
name: Using
Expand Down Expand Up @@ -110,8 +108,9 @@ Inputs

The default python version to install and set with ``pyenv local <version>``

Must be a valid python version supported by ``pyenv install <version>``
MUST be a valid python version supported by ``pyenv install <version>``

**MUST** be defined

Example:

Expand Down
8 changes: 7 additions & 1 deletion __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
20 changes: 20 additions & 0 deletions __tests__/parsedinputs.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
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', () => {
it('list versions when no inputs were provided', () => {
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';
Expand Down
3 changes: 3 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5db04be

Please sign in to comment.