| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ffcd000 commit 00a5248
16 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,3 +65,29 @@ jobs: | |||
| 65 | 65 | EXECUTABLE=${EXECUTABLE%%-*} # remove any -* suffixe | |
| 66 | 66 | ${EXECUTABLE} --version | |
| 67 | 67 | shell: bash | |
| 68 | + | ||
| 69 | + setup-pypy-noenv: | ||
| 70 | + name: Setup PyPy ${{ matrix.pypy }} ${{ matrix.os }} (noenv) | ||
| 71 | + runs-on: ${{ matrix.os }} | ||
| 72 | + strategy: | ||
| 73 | + fail-fast: false | ||
| 74 | + matrix: | ||
| 75 | + os: [macos-latest, windows-latest, ubuntu-18.04, ubuntu-latest] | ||
| 76 | + pypy: ['pypy2.7', 'pypy3.7', 'pypy3.8', 'pypy3.9-nightly'] | ||
| 77 | + | ||
| 78 | + steps: | ||
| 79 | + - name: Checkout | ||
| 80 | + uses: actions/checkout@v3 | ||
| 81 | + | ||
| 82 | + - name: setup-python ${{ matrix.pypy }} | ||
| 83 | + id: setup-python | ||
| 84 | + uses: ./ | ||
| 85 | + with: | ||
| 86 | + python-version: ${{ matrix.pypy }} | ||
| 87 | + update-environment: false | ||
| 88 | + | ||
| 89 | + - name: PyPy and Python version | ||
| 90 | + run: ${{ steps.setup-python.outputs.python-path }} --version | ||
| 91 | + | ||
| 92 | + - name: Run simple code | ||
| 93 | + run: ${{ steps.setup-python.outputs.python-path }} -c 'import math; print(math.factorial(5))' | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,3 +147,28 @@ jobs: | |||
| 147 | 147 | ||
| 148 | 148 | - name: Run simple code | |
| 149 | 149 | run: python -c 'import math; print(math.factorial(5))' | |
| 150 | + | ||
| 151 | + setup-versions-noenv: | ||
| 152 | + name: Setup ${{ matrix.python }} ${{ matrix.os }} (noenv) | ||
| 153 | + runs-on: ${{ matrix.os }} | ||
| 154 | + strategy: | ||
| 155 | + fail-fast: false | ||
| 156 | + matrix: | ||
| 157 | + os: [macos-latest, windows-latest, ubuntu-18.04, ubuntu-20.04] | ||
| 158 | + python: ["3.7", "3.8", "3.9", "3.10"] | ||
| 159 | + steps: | ||
| 160 | + - name: Checkout | ||
| 161 | + uses: actions/checkout@v3 | ||
| 162 | + | ||
| 163 | + - name: setup-python ${{ matrix.python }} | ||
| 164 | + id: setup-python | ||
| 165 | + uses: ./ | ||
| 166 | + with: | ||
| 167 | + python-version: ${{ matrix.python }} | ||
| 168 | + update-environment: false | ||
| 169 | + | ||
| 170 | + - name: Python version | ||
| 171 | + run: ${{ steps.setup-python.outputs.python-path }} --version | ||
| 172 | + | ||
| 173 | + - name: Run simple code | ||
| 174 | + run: ${{ steps.setup-python.outputs.python-path }} -c 'import math; print(math.factorial(5))' | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -320,6 +320,26 @@ steps: | |||
| 320 | 320 | - run: pipenv install | |
| 321 | 321 | ``` | |
| 322 | 322 | ||
| 323 | + # Environment variables | ||
| 324 | + | ||
| 325 | + The `update-environment` flag defaults to `true`. | ||
| 326 | + With this setting, the action will add/update environment variables (e.g. `PATH`, `PKG_CONFIG_PATH`, `pythonLocation`) for `python` to just work out of the box. | ||
| 327 | + | ||
| 328 | + If `update-environment` is set to `false`, the action will not add/update environment variables. | ||
| 329 | + This can prove useful if you want the only side-effect to be to ensure python is installed and rely on the `python-path` output to run python. | ||
| 330 | + Such a requirement on side-effect could be because you don't want your composite action messing with your user's workflows. | ||
| 331 | + | ||
| 332 | + ```yaml | ||
| 333 | + steps: | ||
| 334 | + - uses: actions/checkout@v3 | ||
| 335 | + - uses: actions/setup-python@v4 | ||
| 336 | + id: cp310 | ||
| 337 | + with: | ||
| 338 | + python-version: '3.10' | ||
| 339 | + update-environment: false | ||
| 340 | + - run: ${{ steps.cp310.outputs.python-path }} my_script.py | ||
| 341 | + ``` | ||
| 342 | + | ||
| 323 | 343 | # Using `setup-python` with a self hosted runner | |
| 324 | 344 | ||
| 325 | 345 | Python distributions are only available for the same [environments](https://github.com/actions/virtual-environments#available-environments) that GitHub Actions hosted environments are available for. If you are using an unsupported version of Ubuntu such as `19.04` or another Linux distribution such as Fedora, `setup-python` will not work. If you have a supported self-hosted runner and you would like to use `setup-python`, there are a few extra things you need to make sure are set up so that new versions of Python can be downloaded and configured on your runner. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ import {HttpClient} from '@actions/http-client'; | |||
| 5 | 5 | import * as ifm from '@actions/http-client/interfaces'; | |
| 6 | 6 | import * as tc from '@actions/tool-cache'; | |
| 7 | 7 | import * as exec from '@actions/exec'; | |
| 8 | + import * as core from '@actions/core'; | ||
| 8 | 9 | ||
| 9 | 10 | import * as path from 'path'; | |
| 10 | 11 | import * as semver from 'semver'; | |
@@ -148,6 +149,8 @@ describe('findPyPyVersion', () => { | |||
| 148 | 149 | let spyWriteExactPyPyVersionFile: jest.SpyInstance; | |
| 149 | 150 | let spyCacheDir: jest.SpyInstance; | |
| 150 | 151 | let spyChmodSync: jest.SpyInstance; | |
| 152 | + let spyCoreAddPath: jest.SpyInstance; | ||
| 153 | + let spyCoreExportVariable: jest.SpyInstance; | ||
| 151 | 154 | ||
| 152 | 155 | beforeEach(() => { | |
| 153 | 156 | tcFind = jest.spyOn(tc, 'find'); | |
@@ -201,6 +204,10 @@ describe('findPyPyVersion', () => { | |||
| 201 | 204 | ||
| 202 | 205 | spyExistsSync = jest.spyOn(fs, 'existsSync'); | |
| 203 | 206 | spyExistsSync.mockReturnValue(true); | |
| 207 | + | ||
| 208 | + spyCoreAddPath = jest.spyOn(core, 'addPath'); | ||
| 209 | + | ||
| 210 | + spyCoreExportVariable = jest.spyOn(core, 'exportVariable'); | ||
| 204 | 211 | }); | |
| 205 | 212 | ||
| 206 | 213 | afterEach(() => { | |
@@ -211,22 +218,31 @@ describe('findPyPyVersion', () => { | |||
| 211 | 218 | ||
| 212 | 219 | it('found PyPy in toolcache', async () => { | |
| 213 | 220 | await expect( | |
| 214 | - finder.findPyPyVersion('pypy-3.6-v7.3.x', architecture) | ||
| 221 | + finder.findPyPyVersion('pypy-3.6-v7.3.x', architecture, true) | ||
| 215 | 222 | ).resolves.toEqual({ | |
| 216 | 223 | resolvedPythonVersion: '3.6.12', | |
| 217 | 224 | resolvedPyPyVersion: '7.3.3' | |
| 218 | 225 | }); | |
| 226 | + expect(spyCoreAddPath).toHaveBeenCalled(); | ||
| 227 | + expect(spyCoreExportVariable).toHaveBeenCalledWith( | ||
| 228 | + 'pythonLocation', | ||
| 229 | + expect.anything() | ||
| 230 | + ); | ||
| 231 | + expect(spyCoreExportVariable).toHaveBeenCalledWith( | ||
| 232 | + 'PKG_CONFIG_PATH', | ||
| 233 | + expect.anything() | ||
| 234 | + ); | ||
| 219 | 235 | }); | |
| 220 | 236 | ||
| 221 | 237 | it('throw on invalid input format', async () => { | |
| 222 | 238 | await expect( | |
| 223 | - finder.findPyPyVersion('pypy3.7-v7.3.x', architecture) | ||
| 239 | + finder.findPyPyVersion('pypy3.7-v7.3.x', architecture, true) | ||
| 224 | 240 | ).rejects.toThrow(); | |
| 225 | 241 | }); | |
| 226 | 242 | ||
| 227 | 243 | it('throw on invalid input format pypy3.7-7.3.x', async () => { | |
| 228 | 244 | await expect( | |
| 229 | - finder.findPyPyVersion('pypy3.7-v7.3.x', architecture) | ||
| 245 | + finder.findPyPyVersion('pypy3.7-v7.3.x', architecture, true) | ||
| 230 | 246 | ).rejects.toThrow(); | |
| 231 | 247 | }); | |
| 232 | 248 | ||
@@ -238,16 +254,42 @@ describe('findPyPyVersion', () => { | |||
| 238 | 254 | spyChmodSync = jest.spyOn(fs, 'chmodSync'); | |
| 239 | 255 | spyChmodSync.mockImplementation(() => undefined); | |
| 240 | 256 | await expect( | |
| 241 | - finder.findPyPyVersion('pypy-3.7-v7.3.x', architecture) | ||
| 257 | + finder.findPyPyVersion('pypy-3.7-v7.3.x', architecture, true) | ||
| 258 | + ).resolves.toEqual({ | ||
| 259 | + resolvedPythonVersion: '3.7.9', | ||
| 260 | + resolvedPyPyVersion: '7.3.3' | ||
| 261 | + }); | ||
| 262 | + expect(spyCoreAddPath).toHaveBeenCalled(); | ||
| 263 | + expect(spyCoreExportVariable).toHaveBeenCalledWith( | ||
| 264 | + 'pythonLocation', | ||
| 265 | + expect.anything() | ||
| 266 | + ); | ||
| 267 | + expect(spyCoreExportVariable).toHaveBeenCalledWith( | ||
| 268 | + 'PKG_CONFIG_PATH', | ||
| 269 | + expect.anything() | ||
| 270 | + ); | ||
| 271 | + }); | ||
| 272 | + | ||
| 273 | + it('found and install successfully without environment update', async () => { | ||
| 274 | + spyCacheDir = jest.spyOn(tc, 'cacheDir'); | ||
| 275 | + spyCacheDir.mockImplementation(() => | ||
| 276 | + path.join(toolDir, 'PyPy', '3.7.7', architecture) | ||
| 277 | + ); | ||
| 278 | + spyChmodSync = jest.spyOn(fs, 'chmodSync'); | ||
| 279 | + spyChmodSync.mockImplementation(() => undefined); | ||
| 280 | + await expect( | ||
| 281 | + finder.findPyPyVersion('pypy-3.7-v7.3.x', architecture, false) | ||
| 242 | 282 | ).resolves.toEqual({ | |
| 243 | 283 | resolvedPythonVersion: '3.7.9', | |
| 244 | 284 | resolvedPyPyVersion: '7.3.3' | |
| 245 | 285 | }); | |
| 286 | + expect(spyCoreAddPath).not.toHaveBeenCalled(); | ||
| 287 | + expect(spyCoreExportVariable).not.toHaveBeenCalled(); | ||
| 246 | 288 | }); | |
| 247 | 289 | ||
| 248 | 290 | it('throw if release is not found', async () => { | |
| 249 | 291 | await expect( | |
| 250 | - finder.findPyPyVersion('pypy-3.7-v7.5.x', architecture) | ||
| 292 | + finder.findPyPyVersion('pypy-3.7-v7.5.x', architecture, true) | ||
| 251 | 293 | ).rejects.toThrowError( | |
| 252 | 294 | `PyPy version 3.7 (v7.5.x) with arch ${architecture} not found` | |
| 253 | 295 | ); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,23 +19,54 @@ process.env['RUNNER_TOOL_CACHE'] = toolDir; | |||
| 19 | 19 | process.env['RUNNER_TEMP'] = tempDir; | |
| 20 | 20 | ||
| 21 | 21 | import * as tc from '@actions/tool-cache'; | |
| 22 | + import * as core from '@actions/core'; | ||
| 22 | 23 | import * as finder from '../src/find-python'; | |
| 23 | 24 | import * as installer from '../src/install-python'; | |
| 24 | 25 | ||
| 25 | 26 | const manifestData = require('./data/versions-manifest.json'); | |
| 26 | 27 | ||
| 27 | 28 | describe('Finder tests', () => { | |
| 29 | + let spyCoreAddPath: jest.SpyInstance; | ||
| 30 | + let spyCoreExportVariable: jest.SpyInstance; | ||
| 31 | + | ||
| 32 | + beforeEach(() => { | ||
| 33 | + spyCoreAddPath = jest.spyOn(core, 'addPath'); | ||
| 34 | + | ||
| 35 | + spyCoreExportVariable = jest.spyOn(core, 'exportVariable'); | ||
| 36 | + }); | ||
| 37 | + | ||
| 28 | 38 | afterEach(() => { | |
| 29 | 39 | jest.resetAllMocks(); | |
| 30 | 40 | jest.clearAllMocks(); | |
| 41 | + jest.restoreAllMocks(); | ||
| 31 | 42 | }); | |
| 32 | 43 | ||
| 33 | 44 | it('Finds Python if it is installed', async () => { | |
| 34 | 45 | const pythonDir: string = path.join(toolDir, 'Python', '3.0.0', 'x64'); | |
| 35 | 46 | await io.mkdirP(pythonDir); | |
| 36 | 47 | fs.writeFileSync(`${pythonDir}.complete`, 'hello'); | |
| 37 | 48 | // This will throw if it doesn't find it in the cache and in the manifest (because no such version exists) | |
| 38 | - await finder.useCpythonVersion('3.x', 'x64'); | ||
| 49 | + await finder.useCpythonVersion('3.x', 'x64', true); | ||
| 50 | + expect(spyCoreAddPath).toHaveBeenCalled(); | ||
| 51 | + expect(spyCoreExportVariable).toHaveBeenCalledWith( | ||
| 52 | + 'pythonLocation', | ||
| 53 | + expect.anything() | ||
| 54 | + ); | ||
| 55 | + expect(spyCoreExportVariable).toHaveBeenCalledWith( | ||
| 56 | + 'PKG_CONFIG_PATH', | ||
| 57 | + expect.anything() | ||
| 58 | + ); | ||
| 59 | + }); | ||
| 60 | + | ||
| 61 | + it('Finds Python if it is installed without environment update', async () => { | ||
| 62 | + const pythonDir: string = path.join(toolDir, 'Python', '3.0.0', 'x64'); | ||
| 63 | + await io.mkdirP(pythonDir); | ||
| 64 | + fs.writeFileSync(`${pythonDir}.complete`, 'hello'); | ||
| 65 | + // This will throw if it doesn't find it in the cache and in the manifest (because no such version exists) | ||
| 66 | + await finder.useCpythonVersion('3.x', 'x64', false); | ||
| 67 | + expect(spyCoreAddPath).not.toHaveBeenCalled(); | ||
| 68 | + expect(spyCoreExportVariable).not.toHaveBeenCalled(); | ||
| 69 | + expect(spyCoreExportVariable).not.toHaveBeenCalled(); | ||
| 39 | 70 | }); | |
| 40 | 71 | ||
| 41 | 72 | it('Finds stable Python version if it is not installed, but exists in the manifest', async () => { | |
@@ -52,7 +83,16 @@ describe('Finder tests', () => { | |||
| 52 | 83 | fs.writeFileSync(`${pythonDir}.complete`, 'hello'); | |
| 53 | 84 | }); | |
| 54 | 85 | // This will throw if it doesn't find it in the cache and in the manifest (because no such version exists) | |
| 55 | - await finder.useCpythonVersion('1.2.3', 'x64'); | ||
| 86 | + await finder.useCpythonVersion('1.2.3', 'x64', true); | ||
| 87 | + expect(spyCoreAddPath).toHaveBeenCalled(); | ||
| 88 | + expect(spyCoreExportVariable).toHaveBeenCalledWith( | ||
| 89 | + 'pythonLocation', | ||
| 90 | + expect.anything() | ||
| 91 | + ); | ||
| 92 | + expect(spyCoreExportVariable).toHaveBeenCalledWith( | ||
| 93 | + 'PKG_CONFIG_PATH', | ||
| 94 | + expect.anything() | ||
| 95 | + ); | ||
| 56 | 96 | }); | |
| 57 | 97 | ||
| 58 | 98 | it('Finds pre-release Python version in the manifest', async () => { | |
@@ -74,17 +114,28 @@ describe('Finder tests', () => { | |||
| 74 | 114 | fs.writeFileSync(`${pythonDir}.complete`, 'hello'); | |
| 75 | 115 | }); | |
| 76 | 116 | // This will throw if it doesn't find it in the manifest (because no such version exists) | |
| 77 | - await finder.useCpythonVersion('1.2.3-beta.2', 'x64'); | ||
| 117 | + await finder.useCpythonVersion('1.2.3-beta.2', 'x64', true); | ||
| 118 | + expect(spyCoreAddPath).toHaveBeenCalled(); | ||
| 119 | + expect(spyCoreExportVariable).toHaveBeenCalledWith( | ||
| 120 | + 'pythonLocation', | ||
| 121 | + expect.anything() | ||
| 122 | + ); | ||
| 123 | + expect(spyCoreExportVariable).toHaveBeenCalledWith( | ||
| 124 | + 'PKG_CONFIG_PATH', | ||
| 125 | + expect.anything() | ||
| 126 | + ); | ||
| 78 | 127 | }); | |
| 79 | 128 | ||
| 80 | 129 | it('Errors if Python is not installed', async () => { | |
| 81 | 130 | // This will throw if it doesn't find it in the cache and in the manifest (because no such version exists) | |
| 82 | 131 | let thrown = false; | |
| 83 | 132 | try { | |
| 84 | - await finder.useCpythonVersion('3.300000', 'x64'); | ||
| 133 | + await finder.useCpythonVersion('3.300000', 'x64', true); | ||
| 85 | 134 | } catch { | |
| 86 | 135 | thrown = true; | |
| 87 | 136 | } | |
| 88 | 137 | expect(thrown).toBeTruthy(); | |
| 138 | + expect(spyCoreAddPath).not.toHaveBeenCalled(); | ||
| 139 | + expect(spyCoreExportVariable).not.toHaveBeenCalled(); | ||
| 89 | 140 | }); | |
| 90 | 141 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,9 @@ inputs: | |||
| 17 | 17 | default: ${{ github.token }} | |
| 18 | 18 | cache-dependency-path: | |
| 19 | 19 | description: 'Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies.' | |
| 20 | + update-environment: | ||
| 21 | + description: 'Set this option if you want the action to update environment variables.' | ||
| 22 | + default: true | ||
| 20 | 23 | outputs: | |
| 21 | 24 | python-version: | |
| 22 | 25 | description: "The installed python version. Useful when given a version range as input." | |
| Back | FazBrowse Home | New Git URL |
0 commit comments