mirror of
https://code.forgejo.org/actions/setup-python
synced 2025-06-10 05:12:19 +02:00
feature: add update-environment
input (#411)
This option allows to specify if the action shall update environment variables (default) or not. This allows to use the setup-python action in a composite action without side effect (except downloading/installing python if version is missing).
This commit is contained in:
parent
ffcd00020c
commit
00a5248c77
16 changed files with 2083 additions and 1552 deletions
|
@ -5,6 +5,7 @@ import {HttpClient} from '@actions/http-client';
|
|||
import * as ifm from '@actions/http-client/interfaces';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
|
@ -148,6 +149,8 @@ describe('findPyPyVersion', () => {
|
|||
let spyWriteExactPyPyVersionFile: jest.SpyInstance;
|
||||
let spyCacheDir: jest.SpyInstance;
|
||||
let spyChmodSync: jest.SpyInstance;
|
||||
let spyCoreAddPath: jest.SpyInstance;
|
||||
let spyCoreExportVariable: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
tcFind = jest.spyOn(tc, 'find');
|
||||
|
@ -201,6 +204,10 @@ describe('findPyPyVersion', () => {
|
|||
|
||||
spyExistsSync = jest.spyOn(fs, 'existsSync');
|
||||
spyExistsSync.mockReturnValue(true);
|
||||
|
||||
spyCoreAddPath = jest.spyOn(core, 'addPath');
|
||||
|
||||
spyCoreExportVariable = jest.spyOn(core, 'exportVariable');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -211,22 +218,31 @@ describe('findPyPyVersion', () => {
|
|||
|
||||
it('found PyPy in toolcache', async () => {
|
||||
await expect(
|
||||
finder.findPyPyVersion('pypy-3.6-v7.3.x', architecture)
|
||||
finder.findPyPyVersion('pypy-3.6-v7.3.x', architecture, true)
|
||||
).resolves.toEqual({
|
||||
resolvedPythonVersion: '3.6.12',
|
||||
resolvedPyPyVersion: '7.3.3'
|
||||
});
|
||||
expect(spyCoreAddPath).toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).toHaveBeenCalledWith(
|
||||
'pythonLocation',
|
||||
expect.anything()
|
||||
);
|
||||
expect(spyCoreExportVariable).toHaveBeenCalledWith(
|
||||
'PKG_CONFIG_PATH',
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
||||
it('throw on invalid input format', async () => {
|
||||
await expect(
|
||||
finder.findPyPyVersion('pypy3.7-v7.3.x', architecture)
|
||||
finder.findPyPyVersion('pypy3.7-v7.3.x', architecture, true)
|
||||
).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('throw on invalid input format pypy3.7-7.3.x', async () => {
|
||||
await expect(
|
||||
finder.findPyPyVersion('pypy3.7-v7.3.x', architecture)
|
||||
finder.findPyPyVersion('pypy3.7-v7.3.x', architecture, true)
|
||||
).rejects.toThrow();
|
||||
});
|
||||
|
||||
|
@ -238,16 +254,42 @@ describe('findPyPyVersion', () => {
|
|||
spyChmodSync = jest.spyOn(fs, 'chmodSync');
|
||||
spyChmodSync.mockImplementation(() => undefined);
|
||||
await expect(
|
||||
finder.findPyPyVersion('pypy-3.7-v7.3.x', architecture)
|
||||
finder.findPyPyVersion('pypy-3.7-v7.3.x', architecture, true)
|
||||
).resolves.toEqual({
|
||||
resolvedPythonVersion: '3.7.9',
|
||||
resolvedPyPyVersion: '7.3.3'
|
||||
});
|
||||
expect(spyCoreAddPath).toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).toHaveBeenCalledWith(
|
||||
'pythonLocation',
|
||||
expect.anything()
|
||||
);
|
||||
expect(spyCoreExportVariable).toHaveBeenCalledWith(
|
||||
'PKG_CONFIG_PATH',
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
||||
it('found and install successfully without environment update', async () => {
|
||||
spyCacheDir = jest.spyOn(tc, 'cacheDir');
|
||||
spyCacheDir.mockImplementation(() =>
|
||||
path.join(toolDir, 'PyPy', '3.7.7', architecture)
|
||||
);
|
||||
spyChmodSync = jest.spyOn(fs, 'chmodSync');
|
||||
spyChmodSync.mockImplementation(() => undefined);
|
||||
await expect(
|
||||
finder.findPyPyVersion('pypy-3.7-v7.3.x', architecture, false)
|
||||
).resolves.toEqual({
|
||||
resolvedPythonVersion: '3.7.9',
|
||||
resolvedPyPyVersion: '7.3.3'
|
||||
});
|
||||
expect(spyCoreAddPath).not.toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('throw if release is not found', async () => {
|
||||
await expect(
|
||||
finder.findPyPyVersion('pypy-3.7-v7.5.x', architecture)
|
||||
finder.findPyPyVersion('pypy-3.7-v7.5.x', architecture, true)
|
||||
).rejects.toThrowError(
|
||||
`PyPy version 3.7 (v7.5.x) with arch ${architecture} not found`
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue