| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 49a521f commit 2f06e9d
14 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,3 +91,36 @@ jobs: | |||
| 91 | 91 | ||
| 92 | 92 | - name: Run simple code | |
| 93 | 93 | run: ${{ steps.setup-python.outputs.python-path }} -c 'import math; print(math.factorial(5))' | |
| 94 | + | ||
| 95 | + check-latest: | ||
| 96 | + runs-on: ${{ matrix.os }} | ||
| 97 | + strategy: | ||
| 98 | + fail-fast: false | ||
| 99 | + matrix: | ||
| 100 | + os: [ubuntu-latest, windows-latest, macos-latest] | ||
| 101 | + steps: | ||
| 102 | + - uses: actions/checkout@v3 | ||
| 103 | + - name: Setup PyPy and check latest | ||
| 104 | + uses: ./ | ||
| 105 | + with: | ||
| 106 | + python-version: 'pypy-3.7-v7.3.x' | ||
| 107 | + check-latest: true | ||
| 108 | + - name: PyPy and Python version | ||
| 109 | + run: python --version | ||
| 110 | + | ||
| 111 | + - name: Run simple code | ||
| 112 | + run: python -c 'import math; print(math.factorial(5))' | ||
| 113 | + | ||
| 114 | + - name: Assert PyPy is running | ||
| 115 | + run: | | ||
| 116 | + import platform | ||
| 117 | + assert platform.python_implementation().lower() == "pypy" | ||
| 118 | + shell: python | ||
| 119 | + | ||
| 120 | + - name: Assert expected binaries (or symlinks) are present | ||
| 121 | + run: | | ||
| 122 | + EXECUTABLE="pypy-3.7-v7.3.x" | ||
| 123 | + EXECUTABLE=${EXECUTABLE/-/} # remove the first '-' in "pypy-X.Y" -> "pypyX.Y" to match executable name | ||
| 124 | + EXECUTABLE=${EXECUTABLE%%-*} # remove any -* suffixe | ||
| 125 | + ${EXECUTABLE} --version | ||
| 126 | + shell: bash | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -172,3 +172,27 @@ jobs: | |||
| 172 | 172 | ||
| 173 | 173 | - name: Run simple code | |
| 174 | 174 | run: ${{ steps.setup-python.outputs.python-path }} -c 'import math; print(math.factorial(5))' | |
| 175 | + | ||
| 176 | + check-latest: | ||
| 177 | + runs-on: ${{ matrix.os }} | ||
| 178 | + strategy: | ||
| 179 | + fail-fast: false | ||
| 180 | + matrix: | ||
| 181 | + os: [ubuntu-latest, windows-latest, macos-latest] | ||
| 182 | + python-version: ["3.8", "3.9", "3.10"] | ||
| 183 | + steps: | ||
| 184 | + - uses: actions/checkout@v3 | ||
| 185 | + - name: Setup Python and check latest | ||
| 186 | + uses: ./ | ||
| 187 | + with: | ||
| 188 | + python-version: ${{ matrix.python-version }} | ||
| 189 | + check-latest: true | ||
| 190 | + - name: Validate version | ||
| 191 | + run: | | ||
| 192 | + $pythonVersion = (python --version) | ||
| 193 | + if ("$pythonVersion" -NotMatch "${{ matrix.python }}"){ | ||
| 194 | + Write-Host "The current version is $pythonVersion; expected version is ${{ matrix.python }}" | ||
| 195 | + exit 1 | ||
| 196 | + } | ||
| 197 | + $pythonVersion | ||
| 198 | + shell: pwsh | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -259,6 +259,24 @@ pypy3.7-nightly or pypy-3.7-nightly # Python 3.7 and nightly PyPy | |||
| 259 | 259 | ||
| 260 | 260 | Note: `pypy2` and `pypy3` have been removed in v3. Use the format above instead. | |
| 261 | 261 | ||
| 262 | + # Check latest version | ||
| 263 | + | ||
| 264 | + The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific `Python/PyPy` version is always used. | ||
| 265 | + | ||
| 266 | + If `check-latest` is set to `true`, the action first checks if the cached version is the latest one. If the locally cached version is not the most up-to-date, a `Python/PyPy` version will then be downloaded. Set `check-latest` to `true` if you want the most up-to-date `Python/PyPy` version to always be used. | ||
| 267 | + | ||
| 268 | + > Setting `check-latest` to `true` has performance implications as downloading `Python/PyPy` versions is slower than using cached versions. | ||
| 269 | + | ||
| 270 | + ```yaml | ||
| 271 | + steps: | ||
| 272 | + - uses: actions/checkout@v3 | ||
| 273 | + - uses: actions/setup-python@v3 | ||
| 274 | + with: | ||
| 275 | + python-version: '3.7' | ||
| 276 | + check-latest: true | ||
| 277 | + - run: python my_script.py | ||
| 278 | + ``` | ||
| 279 | + | ||
| 262 | 280 | # Caching packages dependencies | |
| 263 | 281 | ||
| 264 | 282 | The action has built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under the hood for caching dependencies but requires less configuration settings. Supported package managers are `pip`, `pipenv` and `poetry`. The `cache` input is optional, and caching is turned off by default. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,6 @@ import * as finder from '../src/find-pypy'; | |||
| 14 | 14 | import { | |
| 15 | 15 | IPyPyManifestRelease, | |
| 16 | 16 | IS_WINDOWS, | |
| 17 | - validateVersion, | ||
| 18 | 17 | getPyPyVersionFromPath | |
| 19 | 18 | } from '../src/utils'; | |
| 20 | 19 | ||
@@ -82,6 +81,12 @@ describe('findPyPyToolCache', () => { | |||
| 82 | 81 | const pypyPath = path.join('PyPy', actualPythonVersion, architecture); | |
| 83 | 82 | let tcFind: jest.SpyInstance; | |
| 84 | 83 | let spyReadExactPyPyVersion: jest.SpyInstance; | |
| 84 | + let infoSpy: jest.SpyInstance; | ||
| 85 | + let warningSpy: jest.SpyInstance; | ||
| 86 | + let debugSpy: jest.SpyInstance; | ||
| 87 | + let addPathSpy: jest.SpyInstance; | ||
| 88 | + let exportVariableSpy: jest.SpyInstance; | ||
| 89 | + let setOutputSpy: jest.SpyInstance; | ||
| 85 | 90 | ||
| 86 | 91 | beforeEach(() => { | |
| 87 | 92 | tcFind = jest.spyOn(tc, 'find'); | |
@@ -94,6 +99,24 @@ describe('findPyPyToolCache', () => { | |||
| 94 | 99 | ||
| 95 | 100 | spyReadExactPyPyVersion = jest.spyOn(utils, 'readExactPyPyVersionFile'); | |
| 96 | 101 | spyReadExactPyPyVersion.mockImplementation(() => actualPyPyVersion); | |
| 102 | + | ||
| 103 | + infoSpy = jest.spyOn(core, 'info'); | ||
| 104 | + infoSpy.mockImplementation(() => null); | ||
| 105 | + | ||
| 106 | + warningSpy = jest.spyOn(core, 'warning'); | ||
| 107 | + warningSpy.mockImplementation(() => null); | ||
| 108 | + | ||
| 109 | + debugSpy = jest.spyOn(core, 'debug'); | ||
| 110 | + debugSpy.mockImplementation(() => null); | ||
| 111 | + | ||
| 112 | + addPathSpy = jest.spyOn(core, 'addPath'); | ||
| 113 | + addPathSpy.mockImplementation(() => null); | ||
| 114 | + | ||
| 115 | + exportVariableSpy = jest.spyOn(core, 'exportVariable'); | ||
| 116 | + exportVariableSpy.mockImplementation(() => null); | ||
| 117 | + | ||
| 118 | + setOutputSpy = jest.spyOn(core, 'setOutput'); | ||
| 119 | + setOutputSpy.mockImplementation(() => null); | ||
| 97 | 120 | }); | |
| 98 | 121 | ||
| 99 | 122 | afterEach(() => { | |
@@ -136,6 +159,13 @@ describe('findPyPyToolCache', () => { | |||
| 136 | 159 | }); | |
| 137 | 160 | ||
| 138 | 161 | describe('findPyPyVersion', () => { | |
| 162 | + let getBooleanInputSpy: jest.SpyInstance; | ||
| 163 | + let warningSpy: jest.SpyInstance; | ||
| 164 | + let debugSpy: jest.SpyInstance; | ||
| 165 | + let infoSpy: jest.SpyInstance; | ||
| 166 | + let addPathSpy: jest.SpyInstance; | ||
| 167 | + let exportVariableSpy: jest.SpyInstance; | ||
| 168 | + let setOutputSpy: jest.SpyInstance; | ||
| 139 | 169 | let tcFind: jest.SpyInstance; | |
| 140 | 170 | let spyExtractZip: jest.SpyInstance; | |
| 141 | 171 | let spyExtractTar: jest.SpyInstance; | |
@@ -154,6 +184,27 @@ describe('findPyPyVersion', () => { | |||
| 154 | 184 | const env = process.env; | |
| 155 | 185 | ||
| 156 | 186 | beforeEach(() => { | |
| 187 | + getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput'); | ||
| 188 | + getBooleanInputSpy.mockImplementation(() => false); | ||
| 189 | + | ||
| 190 | + infoSpy = jest.spyOn(core, 'info'); | ||
| 191 | + infoSpy.mockImplementation(() => {}); | ||
| 192 | + | ||
| 193 | + warningSpy = jest.spyOn(core, 'warning'); | ||
| 194 | + warningSpy.mockImplementation(() => null); | ||
| 195 | + | ||
| 196 | + debugSpy = jest.spyOn(core, 'debug'); | ||
| 197 | + debugSpy.mockImplementation(() => null); | ||
| 198 | + | ||
| 199 | + addPathSpy = jest.spyOn(core, 'addPath'); | ||
| 200 | + addPathSpy.mockImplementation(() => null); | ||
| 201 | + | ||
| 202 | + exportVariableSpy = jest.spyOn(core, 'exportVariable'); | ||
| 203 | + exportVariableSpy.mockImplementation(() => null); | ||
| 204 | + | ||
| 205 | + setOutputSpy = jest.spyOn(core, 'setOutput'); | ||
| 206 | + setOutputSpy.mockImplementation(() => null); | ||
| 207 | + | ||
| 157 | 208 | jest.resetModules(); | |
| 158 | 209 | process.env = {...env}; | |
| 159 | 210 | tcFind = jest.spyOn(tc, 'find'); | |
@@ -222,7 +273,7 @@ describe('findPyPyVersion', () => { | |||
| 222 | 273 | ||
| 223 | 274 | it('found PyPy in toolcache', async () => { | |
| 224 | 275 | await expect( | |
| 225 | - finder.findPyPyVersion('pypy-3.6-v7.3.x', architecture, true) | ||
| 276 | + finder.findPyPyVersion('pypy-3.6-v7.3.x', architecture, true, false) | ||
| 226 | 277 | ).resolves.toEqual({ | |
| 227 | 278 | resolvedPythonVersion: '3.6.12', | |
| 228 | 279 | resolvedPyPyVersion: '7.3.3' | |
@@ -240,13 +291,13 @@ describe('findPyPyVersion', () => { | |||
| 240 | 291 | ||
| 241 | 292 | it('throw on invalid input format', async () => { | |
| 242 | 293 | await expect( | |
| 243 | - finder.findPyPyVersion('pypy3.7-v7.3.x', architecture, true) | ||
| 294 | + finder.findPyPyVersion('pypy3.7-v7.3.x', architecture, true, false) | ||
| 244 | 295 | ).rejects.toThrow(); | |
| 245 | 296 | }); | |
| 246 | 297 | ||
| 247 | 298 | it('throw on invalid input format pypy3.7-7.3.x', async () => { | |
| 248 | 299 | await expect( | |
| 249 | - finder.findPyPyVersion('pypy3.7-v7.3.x', architecture, true) | ||
| 300 | + finder.findPyPyVersion('pypy3.7-v7.3.x', architecture, true, false) | ||
| 250 | 301 | ).rejects.toThrow(); | |
| 251 | 302 | }); | |
| 252 | 303 | ||
@@ -258,7 +309,7 @@ describe('findPyPyVersion', () => { | |||
| 258 | 309 | spyChmodSync = jest.spyOn(fs, 'chmodSync'); | |
| 259 | 310 | spyChmodSync.mockImplementation(() => undefined); | |
| 260 | 311 | await expect( | |
| 261 | - finder.findPyPyVersion('pypy-3.7-v7.3.x', architecture, true) | ||
| 312 | + finder.findPyPyVersion('pypy-3.7-v7.3.x', architecture, true, false) | ||
| 262 | 313 | ).resolves.toEqual({ | |
| 263 | 314 | resolvedPythonVersion: '3.7.9', | |
| 264 | 315 | resolvedPyPyVersion: '7.3.3' | |
@@ -282,7 +333,7 @@ describe('findPyPyVersion', () => { | |||
| 282 | 333 | spyChmodSync = jest.spyOn(fs, 'chmodSync'); | |
| 283 | 334 | spyChmodSync.mockImplementation(() => undefined); | |
| 284 | 335 | await expect( | |
| 285 | - finder.findPyPyVersion('pypy-3.7-v7.3.x', architecture, false) | ||
| 336 | + finder.findPyPyVersion('pypy-3.7-v7.3.x', architecture, false, false) | ||
| 286 | 337 | ).resolves.toEqual({ | |
| 287 | 338 | resolvedPythonVersion: '3.7.9', | |
| 288 | 339 | resolvedPyPyVersion: '7.3.3' | |
@@ -293,9 +344,61 @@ describe('findPyPyVersion', () => { | |||
| 293 | 344 | ||
| 294 | 345 | it('throw if release is not found', async () => { | |
| 295 | 346 | await expect( | |
| 296 | - finder.findPyPyVersion('pypy-3.7-v7.5.x', architecture, true) | ||
| 347 | + finder.findPyPyVersion('pypy-3.7-v7.5.x', architecture, true, false) | ||
| 297 | 348 | ).rejects.toThrowError( | |
| 298 | 349 | `PyPy version 3.7 (v7.5.x) with arch ${architecture} not found` | |
| 299 | 350 | ); | |
| 300 | 351 | }); | |
| 352 | + | ||
| 353 | + it('check-latest enabled version found and used from toolcache', async () => { | ||
| 354 | + await expect( | ||
| 355 | + finder.findPyPyVersion('pypy-3.6-v7.3.x', architecture, false, true) | ||
| 356 | + ).resolves.toEqual({ | ||
| 357 | + resolvedPythonVersion: '3.6.12', | ||
| 358 | + resolvedPyPyVersion: '7.3.3' | ||
| 359 | + }); | ||
| 360 | + | ||
| 361 | + expect(infoSpy).toHaveBeenCalledWith( | ||
| 362 | + 'Resolved as PyPy 7.3.3 with Python (3.6.12)' | ||
| 363 | + ); | ||
| 364 | + }); | ||
| 365 | + | ||
| 366 | + it('check-latest enabled version found and install successfully', async () => { | ||
| 367 | + spyCacheDir = jest.spyOn(tc, 'cacheDir'); | ||
| 368 | + spyCacheDir.mockImplementation(() => | ||
| 369 | + path.join(toolDir, 'PyPy', '3.7.7', architecture) | ||
| 370 | + ); | ||
| 371 | + spyChmodSync = jest.spyOn(fs, 'chmodSync'); | ||
| 372 | + spyChmodSync.mockImplementation(() => undefined); | ||
| 373 | + await expect( | ||
| 374 | + finder.findPyPyVersion('pypy-3.7-v7.3.x', architecture, false, true) | ||
| 375 | + ).resolves.toEqual({ | ||
| 376 | + resolvedPythonVersion: '3.7.9', | ||
| 377 | + resolvedPyPyVersion: '7.3.3' | ||
| 378 | + }); | ||
| 379 | + expect(infoSpy).toHaveBeenCalledWith( | ||
| 380 | + 'Resolved as PyPy 7.3.3 with Python (3.7.9)' | ||
| 381 | + ); | ||
| 382 | + }); | ||
| 383 | + | ||
| 384 | + it('check-latest enabled version is not found and used from toolcache', async () => { | ||
| 385 | + tcFind.mockImplementationOnce((tool: string, version: string) => { | ||
| 386 | + const semverRange = new semver.Range(version); | ||
| 387 | + let pypyPath = ''; | ||
| 388 | + if (semver.satisfies('3.8.8', semverRange)) { | ||
| 389 | + pypyPath = path.join(toolDir, 'PyPy', '3.8.8', architecture); | ||
| 390 | + } | ||
| 391 | + return pypyPath; | ||
| 392 | + }); | ||
| 393 | + await expect( | ||
| 394 | + finder.findPyPyVersion('pypy-3.8-v7.3.x', architecture, false, true) | ||
| 395 | + ).resolves.toEqual({ | ||
| 396 | + resolvedPythonVersion: '3.8.8', | ||
| 397 | + resolvedPyPyVersion: '7.3.3' | ||
| 398 | + }); | ||
| 399 | + | ||
| 400 | + expect(infoSpy).toHaveBeenCalledWith( | ||
| 401 | + 'Failed to resolve PyPy v7.3.x with Python (3.8) from manifest' | ||
| 402 | + ); | ||
| 403 | + }); | ||
| 301 | 404 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments