Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GitHub releases to download python versions #85

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Validate 'setup-python'
on:
push:
pull_request:
schedule:
- cron: 0 0 * * *

jobs:
default-version:
name: Setup default version
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-16.04, ubuntu-18.04]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: setup default python
uses: ./

- name: Validate version
run: python --version

- name: Run simple python code
run: python -c 'import math; print(math.factorial(5))'

setup-versions-from-manifest:
name: Setup ${{ matrix.python }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-16.04, ubuntu-18.04]
python: [3.5.3, 3.6.7, 3.7.5, 3.8.1]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: setup-python ${{ matrix.python }}
uses: ./
with:
python-version: ${{ matrix.python }}

- name: Validate version
run: |
$pythonVersion = (python --version)
if ("Python ${{ matrix.python }}" -ne "$pythonVersion"){
Write-Host "The current version is $pythonVersion; expected version is ${{ matrix.python }}"
exit 1
}
$pythonVersion
shell: pwsh

- name: Run simple code
run: python -c 'import math; print(math.factorial(5))'
13 changes: 13 additions & 0 deletions __tests__/data/python-release.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "1.2.3",
"stable": true,
"release_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6",
"files": [
{
"filename": "sometool-1.2.3-linux-x64.tar.gz",
"arch": "x64",
"platform": "linux",
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-linux-x64.tar.gz"
}
]
}
33 changes: 31 additions & 2 deletions __tests__/finder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,48 @@ const tempDir = path.join(
process.env['RUNNER_TOOL_CACHE'] = toolDir;
process.env['RUNNER_TEMP'] = tempDir;

import * as tc from '@actions/tool-cache';
import * as finder from '../src/find-python';
import * as installer from '../src/install-python';

const pythonRelease = require('./data/python-release.json');

describe('Finder tests', () => {
afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
});

it('Finds Python if it is installed', async () => {
const pythonDir: string = path.join(toolDir, 'Python', '3.0.0', 'x64');
await io.mkdirP(pythonDir);
fs.writeFileSync(`${pythonDir}.complete`, 'hello');
// This will throw if it doesn't find it in the cache (because no such version exists)
// This will throw if it doesn't find it in the cache and in the manifest (because no such version exists)
await finder.findPythonVersion('3.x', 'x64');
});

it('Finds Python if it is not installed, but exists in the manifest', async () => {
const findSpy: jest.SpyInstance = jest.spyOn(
installer,
'findReleaseFromManifest'
);
findSpy.mockImplementation(() => <tc.IToolRelease>pythonRelease);

const installSpy: jest.SpyInstance = jest.spyOn(
installer,
'installCpythonFromRelease'
);
installSpy.mockImplementation(async () => {
const pythonDir: string = path.join(toolDir, 'Python', '1.2.3', 'x64');
await io.mkdirP(pythonDir);
fs.writeFileSync(`${pythonDir}.complete`, 'hello');
});
// This will throw if it doesn't find it in the cache and in the manifest (because no such version exists)
await finder.findPythonVersion('1.2.3', 'x64');
});

it('Errors if Python is not installed', async () => {
// This will throw if it doesn't find it in the cache (because no such version exists)
// This will throw if it doesn't find it in the cache and in the manifest (because no such version exists)
let thrown = false;
try {
await finder.findPythonVersion('3.300000', 'x64');
Expand Down
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ inputs:
default: '3.x'
architecture:
description: 'The target architecture (x86, x64) of the Python interpreter.'
default: 'x64'
token:
description: Used to pull python distributions from actions/python-versions. Since there's a default, this is typically not supplied by the user.
default: ${{ github.token }}
outputs:
python-version:
description: "The installed python version. Useful when given a version range as input."
Expand Down
Loading