Compare commits

..

135 Commits

Author SHA1 Message Date
b55428b188 Merge pull request #472 from IvanZosimov/ReadmeUpdate
Updated README.md in setup-python
2022-08-02 13:10:35 +02:00
e084fcae44 Merge branch 'main' into ReadmeUpdate 2022-08-01 16:46:54 +02:00
789730b666 Fix broken links in the text body 2022-08-01 16:44:50 +02:00
c4e98b741b Fix broken links 2022-08-01 16:33:59 +02:00
cfcafa57ec Fix review points 2022-08-01 16:23:57 +02:00
c318b92fd6 Fix review points 2022-07-28 09:38:24 +02:00
a93d5412cb Merge pull request #466 from techman83/fix/tool_path
Fix Tool Path handling for self-hosted runners
2022-07-26 15:20:04 +02:00
72394d1a3e Fix typo 2022-07-26 15:04:50 +02:00
fe396d3941 Revert changes 2022-07-26 15:03:33 +02:00
853c012a3c Change advanced-usage.md 2022-07-26 14:59:35 +02:00
fd6f59db22 Change contents to make them more readable 2022-07-26 14:56:14 +02:00
c6e66a7681 Fix typo 2022-07-26 14:51:59 +02:00
81cda82fb0 Fix review points 2022-07-26 14:47:59 +02:00
7e39d25e3f refactor: Debug message for Python installation path 2022-07-26 20:40:49 +08:00
d5d67707d2 docs: Mac Tool Path
Ensure that the path requirements and reasoning is clear, to reduce
confusion when using self-hosted, or attempting to set an
'AGENT_TOOLSDIRECTORY' environment variable.
2022-07-26 19:40:29 +08:00
bc8ee42330 fix: Mac Toolpath
Shared libraries for the Mac python builds are not configured with the
relocatable flag, thus must always be configured with the hosted path.

Relates #459
2022-07-26 19:40:29 +08:00
467a981225 feat: Add 'IS_MAC' util 2022-07-26 19:38:18 +08:00
9f1915a970 fix: Self-Hosted Tool Cache
This fixes the tool cache path for self-hosted runners, along
with handling AGENT_TOOLSDIRECTORY for both hosted + self-hosted.

    Fixes actions#459
2022-07-26 19:37:39 +08:00
10b840936c docs: Agent Tool Cache
This updates and simplies the tool cache documentation to match the implementation in
both  and

  Relates #459
2022-07-26 19:36:13 +08:00
b152b04c28 Fix typo in advanced-usage.md 2022-07-26 11:49:26 +02:00
a624f1f4bc Fix grammar in both documents 2022-07-26 11:32:45 +02:00
5df6377e9d Merge pull request #471 from scooby/main
Recommend using pip for simple poetry projects
2022-07-26 11:30:23 +02:00
dd40245e5b Fix merge artifacts 2022-07-26 11:06:43 +02:00
1f0a39a525 Sync with Main branch 2022-07-26 11:05:09 +02:00
b2241a4754 Change yml and rebuild action 2022-07-26 11:01:07 +02:00
0d94a5d71e Fix typo 2022-07-26 10:47:51 +02:00
e147df2e90 Update README.md
Add a section to advise using only pip instead of poetry.
2022-07-25 14:22:13 -04:00
889226ae9a Fix typo 2022-07-25 19:44:22 +02:00
00d9c42868 Change part with realted to self-hosted runners 2022-07-25 19:42:15 +02:00
2f06e9da25 Add check-latest functionality (#406) 2022-07-25 16:54:04 +02:00
49a521fa06 Fix poetry version (#445) 2022-07-25 15:02:06 +02:00
592a7a7a45 Add linux os release info to primary key (#467) 2022-07-19 14:20:19 +02:00
aba6f4ba7b Merge pull request #465 from IvanZosimov/pythonversionfile
Fixed resolveVersionInput() logic
2022-07-19 09:48:33 +02:00
5517d5f7b5 Fix documentation
Docs were updated to incorporate changes regarding tool cache folder
on the self-hosted runner and changes in resolveVersionInput()
2022-07-18 14:33:42 +02:00
b88a682917 Fix resolveVersionInput() logic 2022-07-15 16:52:20 +02:00
c474c82340 Merge pull request #454 from wrt54g/update
Update actions
2022-07-14 09:58:29 +02:00
799afeb796 Fix action.yml file 2022-07-13 13:43:28 +02:00
386e4eaaed Fix review points 2022-07-13 13:34:22 +02:00
61fb4e42ab Fix review points 2022-07-13 12:17:04 +02:00
09086ccd46 Update action.yml file 2022-07-13 11:27:41 +02:00
746f28a2d3 Update REAMDE.md and advanced-usage.md 2022-07-13 11:15:35 +02:00
6dd8ff72eb Change tool cache wording 2022-07-12 17:32:40 +02:00
9a40041e25 Rearrange README.md, add advanced-usage.md 2022-07-12 16:38:54 +02:00
c4e89fac7e Improve readme for 3.x and 3.11-dev style python-version (#441) 2022-07-07 23:34:44 +02:00
0ad0f6a0a5 Merge pull request #452 from mayeut/fix-env
Remove duplicate code introduced in #440
2022-07-06 16:11:51 +02:00
f0bcf8be03 Merge pull request #456 from akx/patch-1
doc: Add multiple wildcards example to readme
2022-07-05 08:23:25 +02:00
af97157ae6 doc: Add multiple wildcards example to readme
Based on https://www.npmjs.com/package/@actions/glob (the library used for cache file globbing), newline-separating multiple patterns is accepted.
2022-07-04 12:24:58 +03:00
364e819741 Merge pull request #394 from akv-platform/v-sedoli/set-env-by-default
Assign default value of AGENT_TOOLSDIRECTORY if not set
2022-07-04 10:35:46 +02:00
782f81b91d Merge pull request #450 from IvanZosimov/ResolveVersionFix
Rearranged logic of the ResolveVersionInput()
2022-07-04 08:20:42 +02:00
b318cecd93 Update actions/checkout to v3 2022-07-03 20:15:21 +02:00
4a7ca55b40 Update actions 2022-07-03 20:14:29 +02:00
d08a9d79f1 Update actions 2022-07-03 20:13:56 +02:00
7d9c63da1b Update actions/checkout to v3 2022-07-03 20:13:21 +02:00
5a1dd6b34d Update actions 2022-07-03 20:11:27 +02:00
f4b85ae24e Update actions 2022-07-03 20:10:08 +02:00
2c9de4ed41 Remove duplicate code introduced in #440
#440 duplicated a block of code outside of `if (updateEnvironment) {` condition. This was probably an oversight when merging `main` back on the PR branch. The tests should have seen that `core.exportVariable` was being called and should have failed.
2022-07-02 11:50:48 +02:00
412091c1e0 Fix tests for update-environment==false 2022-07-02 11:50:48 +02:00
78a2330b92 Merge pull request #451 from dmitry-shibanov/fx-pipenv-python-version
Fx pipenv python version
2022-07-01 16:57:38 +02:00
96f494e18c trigger checks 2022-07-01 10:28:46 +02:00
099ed898be Optimize code 2022-06-30 18:42:04 +02:00
ccb7da8ae9 Change warning handler to default 2022-06-30 18:28:17 +02:00
5fbb819407 Optimize logic, rebuild action 2022-06-30 17:32:12 +02:00
82eddc4023 Add warning in case the versionFile isn't found 2022-06-30 16:34:29 +02:00
d97b6edda3 Fix typos 2022-06-30 16:25:46 +02:00
a6b01c4e40 Rebuild action with new changes 2022-06-30 16:22:51 +02:00
84087f5301 Rearrange logic 2022-06-30 16:21:14 +02:00
56f6060254 Fix naming 2022-06-30 14:41:09 +02:00
e29a7c89f6 Merge branch 'main' into ResolveVersionFix 2022-06-30 14:40:24 +02:00
5407bf6e69 Merge pull request #448 from IvanZosimov/CacheLibVersionUpdate
Add support for the @actions/cache library 3.0.0
2022-06-30 14:38:10 +02:00
41b91104ea Rebuild action 2022-06-30 14:26:40 +02:00
08116500d0 Rebuild action 2022-06-30 14:19:36 +02:00
161c3a68f0 Merge branch 'main' into CacheLibVersionUpdate 2022-06-30 14:18:06 +02:00
6733fc44ec Fix typo 2022-06-30 13:44:10 +02:00
afd3e72a25 Fix bug in resolveVersionInput() 2022-06-30 13:38:43 +02:00
ab6deb310f Merge pull request #440 from akv-platform/v-sdolin/issue-231
Add CMake hints
2022-06-30 08:56:04 +02:00
e629242ad4 Fix failed check 2022-06-30 07:56:08 +02:00
63086c6ded rebase main 2022-06-30 07:46:53 +02:00
69b94463f5 Add CMake hints 2022-06-30 07:43:57 +02:00
d7db8259d9 update pypy versions 2022-06-29 23:41:39 +02:00
27091d50ca minor fix 2022-06-29 20:38:02 +02:00
d358f9e3d7 fix check 2022-06-29 20:28:20 +02:00
1e52de40a4 fixing pipenv 2022-06-29 20:16:07 +02:00
2a20d9b5e0 add --python 3 2022-06-29 19:36:35 +02:00
766e8c6088 Fixing pipenv CI (#444)
* work on fixing pipenv

* change installation of pipenv to curl

* add different logs

* regenerate pipefile.lock

* change pipenv ci
2022-06-29 13:09:14 -04:00
00a5248c77 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).
2022-06-29 11:00:51 -04:00
9c76df2a90 Build after rebase 2022-06-29 11:24:02 +02:00
958897304a Exclude windows from the fix 2022-06-29 11:22:07 +02:00
5d9fdcab75 Handle each OS in its own way 2022-06-29 11:22:07 +02:00
7199395312 Fix dist folder 2022-06-29 11:22:06 +02:00
5ad79022bc Change README 2022-06-29 11:21:25 +02:00
a8da2a66aa Use /opt/hostedtoolcache as default value AGENT_TOOLSDIRECTORY 2022-06-29 11:21:21 +02:00
c61bc3d08e Update licenses 2022-06-28 15:40:29 +02:00
01408cef88 Update cache-save.ts to support @actions/cache v3.0.0 lib
Made package.json and package-lock.json to use @actions/cache v3.0.0,
updated logic of the cache-save operation and added unit-tests
2022-06-28 15:17:50 +02:00
ffcd00020c Allow python-version-file to be a relative path (#431) 2022-06-20 16:04:59 +02:00
cf86e08a31 Revert "Pass the token input through on GHES (#427)" (#437)
This reverts commit 7e4abae443.
2022-06-16 11:08:06 -04:00
8fb4cbf7c8 README: Document pypy2 and pypy3 are deprecated (#265) 2022-06-15 14:03:21 +02:00
7e4abae443 Pass the token input through on GHES (#427)
* Pass the`token` input through on GHES

* Update the description for `token`

* Fix dist files

* Update package-lock.json

* Update README

* Fix indent level in YAML snippet

* secret names can't start with GITHUB_
2022-06-13 14:55:47 -04:00
813f9b1556 Merge pull request #423 from vsafonkin/v-vsafonkin/update-docs-v4
Update docs to v4 version
2022-06-09 10:56:24 +02:00
775367df99 Update docs to v4 version 2022-06-09 09:54:52 +02:00
d09bd5e600 fix: 3.x-dev can install a 3.y version (#417)
* fix: 3.x-dev can install a 3.y version

* Update README section for `-dev`
2022-06-08 14:58:05 +02:00
f72db171ab Made env.var pythonLocation consistent for Python and PyPy (#418)
* Change find-pypy.ts to redefine pythonLocaction environment variable

* Change README.md in order to add sentence about pythonLocation envvar

* Change sentence about pythonLocation envvar in README.md

* Rephrase the definition of pythonLocation env.var
2022-06-08 14:57:23 +02:00
53e15292cd add support for python-version-file (#336)
* add support for python-version-file

* Update action.yml

* update to v4, remove python-version default

* python-version overrides python-version-file, like setup-node
* checks '.python-version' by default if nothing else specified

* update tests, update to checkout@v3

* update build

* appease the linter

* remove old test for default python version

* revert readme changes

* update build
2022-06-02 16:37:57 +02:00
3f82819745 Fix output for prerelease version of poetry (#409) 2022-05-31 15:48:54 +02:00
397252c582 Update zeit/ncc to vercel/ncc (#393) 2022-05-31 12:56:29 +02:00
de977ad132 Merge pull request #412 from vsafonkin/v-vsafonkin/fix-poetry-cache-test
Fix e2e test for poetry cache and PyPy-3.7
2022-05-31 09:41:08 +02:00
22c6af91ce Change PyPy version to rebuild cache 2022-05-30 15:02:04 +02:00
081a3cf1a5 Merge pull request #405 from mayeut/interpreter-path
feature: add a `python-path` output
2022-05-25 11:02:46 +02:00
ff706563d7 feature: add a python-path output
Expose a `python-path` output containing the chosen Python executable path.
2022-05-24 21:02:03 +02:00
fff15a21cc Use pypyX.Y for PyPy python-version input (#349)
This versioning scheme is consistent with other
tools in the python ecosystem so it feels more natural
and allows better interaction with other tools.

fixes #346
2022-05-18 15:20:53 +02:00
c57f79353b Merge pull request #318 from neutrinoceros/document_dev_sugar
DOC: document -dev syntactic sugar
2022-05-06 13:03:34 +02:00
fd8f0a9fb8 Merge pull request #396 from akv-platform/v-sedoli/issue-241
Add warning if python version set to empty value
2022-05-04 15:21:43 +02:00
ae11205ec6 Merge pull request #400 from akv-platform/v-sedoli/pkg-config
set PKG_CONFIG_PATH environment var
2022-05-04 09:56:28 +02:00
8f73c1495f Formatting 2022-05-04 12:55:36 +05:00
e31727ce0a Improve warning message
Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com>
2022-05-04 12:43:58 +05:00
a69041ca9f Successfully set up (#399) 2022-05-03 08:43:53 -04:00
5e1e05c694 set PKG_CONFIG_PATH environment var 2022-05-03 16:04:39 +05:00
0b56b76337 Improve wording 2022-04-29 12:49:49 +05:00
22daa094b8 Add generated files 2022-04-29 09:29:36 +05:00
ac4e858835 Add warning if python version set to empty value 2022-04-29 09:14:59 +05:00
1ce308808a Create missing pypyX.Y symlinks (#347)
`pypyX.Y.exe` executables are missing from PyPy archives on Windows before v7.3.9 (X.Y < 3.9)
`pypy2.7` symlinks are also missing from macOS/Linux PyPy archives before v7.3.9

relates to #346
2022-04-28 09:26:17 -04:00
c36dc43e7b Fix conflicts (#389) 2022-04-26 16:50:29 +02:00
4e6b5f40fc Merge pull request #384 from akv-platform/main
Add CODE_OF_CONDUCT
2022-04-21 08:59:12 +02:00
bcc31375e1 Throw exe on empty python-version 2022-04-21 08:19:23 +05:00
85a7430316 Merge branch 'actions:main' into main 2022-04-21 08:16:01 +05:00
6a4c6c1309 adjust documentation for python versions (#388) 2022-04-20 14:48:22 +02:00
3a63f5d525 Merge branch 'actions:main' into main 2022-04-20 12:09:38 +05:00
4a33d3c467 Merge pull request #387 from vsafonkin/v-vsafonkin/fix-readme-outdated-links
Fix virtual-env toolcache outdated links
2022-04-19 17:06:22 +03:00
abfd16b121 Fix virtual-env toolcache links 2022-04-19 15:21:09 +02:00
4176166af9 Add CODE_OF_CONDUCT 2022-04-18 16:04:39 +05:00
91712e11bb Merge pull request #338 from akv-demo/main
Force TOOLCACHE_ROOT to be equal AGENT_TOOLSDIRECTORY
2022-04-15 09:54:33 +02:00
f4b66dec00 Merge branch 'actions:main' into main 2022-04-06 12:51:31 +05:00
65fe6a82c7 Use template literals instead of string concatenation 2022-02-21 05:26:51 +00:00
011c443f81 prettier 2022-02-17 19:21:13 +00:00
3250b5373c Force RUNNER_TOOL_CACHE to be equal AGENT_TOOLSDIRECTORY 2022-02-17 18:35:19 +00:00
0bcf8ef2ba DOC: document -dev syntactic sugar 2022-01-12 10:35:17 +01:00
39 changed files with 71688 additions and 63100 deletions

View File

@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Set Node.js 16.x - name: Set Node.js 16.x
uses: actions/setup-node@v3 uses: actions/setup-node@v3
@ -45,7 +45,7 @@ jobs:
id: diff id: diff
# If index.js was different than expected, upload the expected version as an artifact # If index.js was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v3
if: ${{ failure() && steps.diff.conclusion == 'failure' }} if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with: with:
name: dist name: dist

View File

@ -18,11 +18,11 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@v1 uses: github/codeql-action/init@v2
# Override language selection by uncommenting this and choosing your languages # Override language selection by uncommenting this and choosing your languages
# with: # with:
# languages: go, javascript, csharp, python, cpp, java # languages: go, javascript, csharp, python, cpp, java
@ -30,7 +30,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below) # If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@v1 uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell. # Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl # 📚 https://git.io/JvXDl
@ -44,4 +44,4 @@ jobs:
# make release # make release
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1 uses: github/codeql-action/analyze@v2

View File

@ -39,7 +39,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.9', 'pypy-3.7-v7.x'] python-version: ['3.9', 'pypy-3.9-v7.x']
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup Python - name: Setup Python
@ -48,11 +48,17 @@ jobs:
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}
cache: 'pipenv' cache: 'pipenv'
- name: Install pipenv - name: Install pipenv
run: pipx install pipenv run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python
- name: Install dependencies - name: Install dependencies
shell: pwsh
run: | run: |
cd __tests__/data mv ./__tests__/data/Pipfile.lock .
pipenv install --verbose mv ./__tests__/data/Pipfile .
if ("${{ matrix.python-version }}" -Match "pypy") {
pipenv install --keep-outdated --python pypy
} else {
pipenv install --keep-outdated --python ${{ matrix.python-version }}
}
python-poetry-dependencies-caching: python-poetry-dependencies-caching:
name: Test poetry (Python ${{ matrix.python-version}}, ${{ matrix.os }}) name: Test poetry (Python ${{ matrix.python-version}}, ${{ matrix.os }})
@ -61,20 +67,20 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.9', 'pypy-3.7-v7.x'] python-version: ['3.9', 'pypy-3.8']
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Install poetry - name: Install poetry
run: pipx install poetry run: pipx install poetry
- name: Init pyproject.toml
run: mv ./__tests__/data/pyproject.toml .
- name: Setup Python - name: Setup Python
uses: ./ uses: ./
with: with:
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}
cache: 'poetry' cache: 'poetry'
- name: Init pyproject.toml
run: poetry init -n
- name: Install dependencies - name: Install dependencies
run: poetry add flake8 run: poetry install
python-pip-dependencies-caching-path: python-pip-dependencies-caching-path:
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }}) name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }})
@ -102,7 +108,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.9', 'pypy-3.7-v7.x'] python-version: ['3.9', 'pypy-3.9-v7.x']
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup Python - name: Setup Python
@ -112,8 +118,14 @@ jobs:
cache: 'pipenv' cache: 'pipenv'
cache-dependency-path: '**/pipenv-requirements.txt' cache-dependency-path: '**/pipenv-requirements.txt'
- name: Install pipenv - name: Install pipenv
run: pipx install pipenv run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python
- name: Install dependencies - name: Install dependencies
shell: pwsh
run: | run: |
cd __tests__/data mv ./__tests__/data/Pipfile.lock .
pipenv install --verbose mv ./__tests__/data/Pipfile .
if ("${{ matrix.python-version }}" -Match "pypy") {
pipenv install --keep-outdated --python pypy
} else {
pipenv install --keep-outdated --python ${{ matrix.python-version }}
}

View File

@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Check licenses name: Check licenses
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Set Node.js 16.x - name: Set Node.js 16.x
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:

View File

@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Update the ${{ env.TAG_NAME }} tag - name: Update the ${{ env.TAG_NAME }} tag
uses: actions/publish-action@v0.1.0 uses: actions/publish-action@v0.2.0
with: with:
source-tag: ${{ env.TAG_NAME }} source-tag: ${{ env.TAG_NAME }}
slack-webhook: ${{ secrets.SLACK_WEBHOOK }} slack-webhook: ${{ secrets.SLACK_WEBHOOK }}

View File

@ -18,10 +18,11 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [macos-latest, windows-latest, ubuntu-latest] os: [macos-latest, windows-latest, ubuntu-18.04, ubuntu-latest]
pypy: pypy:
- 'pypy-2.7' - 'pypy-2.7'
- 'pypy-3.7' - 'pypy-3.7'
- 'pypy3.9'
- 'pypy-2.7-v7.3.4' - 'pypy-2.7-v7.3.4'
- 'pypy-3.7-v7.3.5' - 'pypy-3.7-v7.3.5'
- 'pypy-3.7-v7.3.4' - 'pypy-3.7-v7.3.4'
@ -29,18 +30,97 @@ jobs:
- 'pypy-3.7-v7.x' - 'pypy-3.7-v7.x'
- 'pypy-2.7-v7.3.4rc1' - 'pypy-2.7-v7.3.4rc1'
- 'pypy-3.7-nightly' - 'pypy-3.7-nightly'
- 'pypy3.8-v7.3.7'
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v3
- name: setup-python ${{ matrix.pypy }} - name: setup-python ${{ matrix.pypy }}
id: setup-python
uses: ./ uses: ./
with: with:
python-version: ${{ matrix.pypy }} python-version: ${{ matrix.pypy }}
- name: Check python-path
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
shell: bash
- name: PyPy and Python version - name: PyPy and Python version
run: python --version run: python --version
- name: Run simple code - name: Run simple code
run: python -c 'import math; print(math.factorial(5))' run: python -c 'import math; print(math.factorial(5))'
- name: Assert PyPy is running
run: |
import platform
assert platform.python_implementation().lower() == "pypy"
shell: python
- name: Assert expected binaries (or symlinks) are present
run: |
EXECUTABLE=${{ matrix.pypy }}
EXECUTABLE=${EXECUTABLE/pypy-/pypy} # remove the first '-' in "pypy-X.Y" -> "pypyX.Y" to match executable name
EXECUTABLE=${EXECUTABLE%%-*} # remove any -* suffixe
${EXECUTABLE} --version
shell: bash
setup-pypy-noenv:
name: Setup PyPy ${{ matrix.pypy }} ${{ matrix.os }} (noenv)
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-18.04, ubuntu-latest]
pypy: ['pypy2.7', 'pypy3.7', 'pypy3.8', 'pypy3.9-nightly']
steps:
- name: Checkout
uses: actions/checkout@v3
- name: setup-python ${{ matrix.pypy }}
id: setup-python
uses: ./
with:
python-version: ${{ matrix.pypy }}
update-environment: false
- name: PyPy and Python version
run: ${{ steps.setup-python.outputs.python-path }} --version
- name: Run simple code
run: ${{ steps.setup-python.outputs.python-path }} -c 'import math; print(math.factorial(5))'
check-latest:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- name: Setup PyPy and check latest
uses: ./
with:
python-version: 'pypy-3.7-v7.3.x'
check-latest: true
- name: PyPy and Python version
run: python --version
- name: Run simple code
run: python -c 'import math; print(math.factorial(5))'
- name: Assert PyPy is running
run: |
import platform
assert platform.python_implementation().lower() == "pypy"
shell: python
- name: Assert expected binaries (or symlinks) are present
run: |
EXECUTABLE="pypy-3.7-v7.3.x"
EXECUTABLE=${EXECUTABLE/-/} # remove the first '-' in "pypy-X.Y" -> "pypyX.Y" to match executable name
EXECUTABLE=${EXECUTABLE%%-*} # remove any -* suffixe
${EXECUTABLE} --version
shell: bash

View File

@ -1,5 +1,5 @@
name: Validate Python e2e name: Validate Python e2e
on: on:
push: push:
branches: branches:
- main - main
@ -10,45 +10,69 @@ on:
- '**.md' - '**.md'
schedule: schedule:
- cron: 30 3 * * * - cron: 30 3 * * *
workflow_dispatch:
jobs: jobs:
default-version:
name: Setup default version
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-20.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: setup-versions-from-manifest:
name: Setup ${{ matrix.python }} ${{ matrix.os }} name: Setup ${{ matrix.python }} ${{ matrix.os }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [macos-latest, windows-latest, ubuntu-20.04] os: [macos-latest, windows-latest, ubuntu-18.04, ubuntu-20.04]
python: [3.5.4, 3.6.7, 3.7.5, 3.8.1] python: [3.5.4, 3.6.7, 3.7.5, 3.8.1]
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v3
- name: setup-python ${{ matrix.python }} - name: setup-python ${{ matrix.python }}
id: setup-python
uses: ./ uses: ./
with: with:
python-version: ${{ matrix.python }} python-version: ${{ matrix.python }}
- name: Check python-path
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
shell: bash
- 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))'
setup-versions-from-file:
name: Setup ${{ matrix.python }} ${{ matrix.os }} version file
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-18.04, ubuntu-20.04]
python: [3.5.4, 3.6.7, 3.7.5, 3.8.1]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: build-version-file ${{ matrix.python }}
run: echo ${{ matrix.python }} > .python-version
- name: setup-python ${{ matrix.python }}
id: setup-python
uses: ./
with:
python-version-file: '.python-version'
- name: Check python-path
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
shell: bash
- name: Validate version - name: Validate version
run: | run: |
$pythonVersion = (python --version) $pythonVersion = (python --version)
@ -68,16 +92,21 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [macos-latest, windows-latest, ubuntu-20.04] os: [macos-latest, windows-latest, ubuntu-18.04, ubuntu-20.04]
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v3
- name: setup-python 3.9.0-beta.4 - name: setup-python 3.9.0-beta.4
id: setup-python
uses: ./ uses: ./
with: with:
python-version: '3.9.0-beta.4' python-version: '3.9.0-beta.4'
- name: Check python-path
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
shell: bash
- name: Validate version - name: Validate version
run: | run: |
$pythonVersion = (python --version) $pythonVersion = (python --version)
@ -91,3 +120,79 @@ jobs:
- name: Run simple code - name: Run simple code
run: python -c 'import math; print(math.factorial(5))' run: python -c 'import math; print(math.factorial(5))'
setup-dev-version:
name: Setup 3.9-dev ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: setup-python 3.9-dev
id: setup-python
uses: ./
with:
python-version: '3.9-dev'
- name: Check python-path
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
shell: bash
- name: Validate version
run: ${{ startsWith(steps.setup-python.outputs.python-version, '3.9.') }}
shell: bash
- name: Run simple code
run: python -c 'import math; print(math.factorial(5))'
setup-versions-noenv:
name: Setup ${{ matrix.python }} ${{ matrix.os }} (noenv)
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-18.04, ubuntu-20.04]
python: ["3.7", "3.8", "3.9", "3.10"]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: setup-python ${{ matrix.python }}
id: setup-python
uses: ./
with:
python-version: ${{ matrix.python }}
update-environment: false
- name: Python version
run: ${{ steps.setup-python.outputs.python-path }} --version
- name: Run simple code
run: ${{ steps.setup-python.outputs.python-path }} -c 'import math; print(math.factorial(5))'
check-latest:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Setup Python and check latest
uses: ./
with:
python-version: ${{ matrix.python-version }}
check-latest: true
- name: Validate version
run: |
$pythonVersion = (python --version)
if ("$pythonVersion" -NotMatch "${{ matrix.python }}"){
Write-Host "The current version is $pythonVersion; expected version is ${{ matrix.python }}"
exit 1
}
$pythonVersion
shell: pwsh

View File

@ -14,10 +14,10 @@ jobs:
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
strategy: strategy:
matrix: matrix:
operating-system: [ubuntu-20.04, windows-latest] operating-system: [ubuntu-latest, windows-latest]
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v3
- name: Set Node.js 16.x - name: Set Node.js 16.x
uses: actions/setup-node@v3 uses: actions/setup-node@v3
@ -89,3 +89,13 @@ jobs:
python-version: 3.8.1 python-version: 3.8.1
- name: Verify 3.8.1 - name: Verify 3.8.1
run: python __tests__/verify-python.py 3.8.1 run: python __tests__/verify-python.py 3.8.1
- name: Run with setup-python 3.10
id: cp310
uses: ./
with:
python-version: "3.10"
- name: Verify 3.10
run: python __tests__/verify-python.py 3.10
- name: Run python-path sample 3.10
run: pipx run --python '${{ steps.cp310.outputs.python-path }}' nox --version

View File

@ -1,6 +1,6 @@
--- ---
name: "@actions/cache" name: "@actions/cache"
version: 2.0.2 version: 3.0.0
type: npm type: npm
summary: Actions cache lib summary: Actions cache lib
homepage: https://github.com/actions/toolkit/tree/main/packages/cache homepage: https://github.com/actions/toolkit/tree/main/packages/cache

View File

@ -1,6 +1,6 @@
--- ---
name: "@actions/core" name: "@actions/core"
version: 1.10.0 version: 1.7.0
type: npm type: npm
summary: Actions core lib summary: Actions core lib
homepage: https://github.com/actions/toolkit/tree/main/packages/core homepage: https://github.com/actions/toolkit/tree/main/packages/core

View File

@ -1,6 +1,6 @@
--- ---
name: "@actions/http-client" name: "@actions/http-client"
version: 1.0.8 version: 2.0.1
type: npm type: npm
summary: Actions Http Client summary: Actions Http Client
homepage: https://github.com/actions/http-client#readme homepage: https://github.com/actions/http-client#readme

View File

@ -1,32 +0,0 @@
---
name: "@actions/http-client"
version: 2.1.0
type: npm
summary: Actions Http Client
homepage: https://github.com/actions/toolkit/tree/main/packages/http-client
license: mit
licenses:
- sources: LICENSE
text: |
Actions Http Client for Node.js
Copyright (c) GitHub, Inc.
All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
notices: []

76
CODE_OF_CONDUCT.md Normal file
View File

@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies within all project spaces, and it also applies when
an individual is representing the project or its community in public spaces.
Examples of representing a project or community include using an official
project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at opensource+actions/setup-python@github.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

336
README.md
View File

@ -1,345 +1,95 @@
# setup-python V3 # setup-python
<p align="left"> <p align="left">
<a href="https://github.com/actions/setup-python"><img alt="GitHub Actions status" src="https://github.com/actions/setup-python/workflows/Main%20workflow/badge.svg"></a> <a href="https://github.com/actions/setup-python"><img alt="GitHub Actions status" src="https://github.com/actions/setup-python/workflows/Main%20workflow/badge.svg"></a>
</p> </p>
This action sets up a Python environment for use in actions by: This action provides the following functionality for GitHub Actions users:
- optionally installing and adding to PATH a version of Python that is already installed in the tools cache. - Installing a version of Python or PyPy and (by default) adding it to the PATH
- downloading, installing and adding to PATH an available version of Python from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)) if a specific version is not available in the tools cache. - Optionally caching dependencies for pip, pipenv and poetry
- failing if a specific version of Python is not preinstalled or available for download. - Registering problem matchers for error output
- optionally caching dependencies for pip, pipenv and poetry.
- registering problem matchers for error output.
# What's new ## Basic usage
- Ability to download, install and set up Python packages from `actions/python-versions` that do not come preinstalled on runners.
- Allows for pinning to a specific patch version of Python without the worry of it ever being removed or changed.
- Automatic setup and download of Python packages if using a self-hosted runner.
- Support for pre-release versions of Python.
- Support for installing any version of PyPy on-flight
- Support for built-in caching of pip, pipenv and poetry dependencies
# Usage
See [action.yml](action.yml) See [action.yml](action.yml)
Basic: **Python**
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: actions/setup-python@v3 - uses: actions/setup-python@v4
with: with:
python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax python-version: '3.10'
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
- run: python my_script.py - run: python my_script.py
``` ```
Matrix Testing: **PyPy**
```yaml
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '2.x', '3.x', 'pypy-2.7', 'pypy-3.7', 'pypy-3.8' ]
name: Python ${{ matrix.python-version }} sample
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: python my_script.py
```
Exclude a specific Python version:
```yaml
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['2.7', '3.7', '3.8', '3.9', '3.10', 'pypy-2.7', 'pypy-3.8']
exclude:
- os: macos-latest
python-version: '3.8'
- os: windows-latest
python-version: '3.6'
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python --version
```
Download and set up a version of Python that does not come preinstalled on an image:
```yaml
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
# in this example, there is a newer version already installed, 3.7.7, so the older version will be downloaded
python-version: ['3.7.4', '3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- run: python my_script.py
```
Download and set up an accurate pre-release version of Python:
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: actions/setup-python@v3 - uses: actions/setup-python@v4
with: with:
python-version: '3.11.0-alpha.1' python-version: 'pypy3.9'
- run: python my_script.py - run: python my_script.py
``` ```
The `python-version` input is optional. If not supplied, the action will try to resolve the version from the default `.python-version` file. If the `.python-version` file doesn't exist Python or PyPy version from the PATH will be used. The default version of Python or PyPy in PATH varies between runners and can be changed unexpectedly so we recommend always using `setup-python`.
Download and set up the latest available version of Python (includes both pre-release and stable versions): The action will first check the local [tool cache](docs/advanced-usage.md#hosted-tool-cache) for a [semver](https://github.com/npm/node-semver#versions) match. If unable to find a specific version in the tool cache, the action will attempt to download a version of Python from [GitHub Releases](https://github.com/actions/python-versions/releases) and for PyPy from the official [PyPy's dist](https://downloads.python.org/pypy/).
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '3.11.0-alpha - 3.11.0' # SemVer's version range syntax
- run: python my_script.py
```
Download and set up PyPy: For information regarding locally cached versions of Python or PyPy on GitHub hosted runners, check out [GitHub Actions Virtual Environments](https://github.com/actions/virtual-environments).
```yaml ## Supported version syntax
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- 'pypy-3.7' # the latest available version of PyPy that supports Python 3.7
- 'pypy-3.7-v7.3.3' # Python 3.7 and PyPy 7.3.3
- 'pypy-3.8' # the latest available version of PyPy that supports Python 3.8
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- run: python my_script.py
```
More details on PyPy syntax and examples of using preview / nightly versions of PyPy can be found in the [Available versions of PyPy](#available-versions-of-pypy) section.
# Getting started with Python + Actions The `python-version` input supports the [Semantic Versioning Specification](https://semver.org/) and some special version notations (e.g. `semver ranges`, `x.y-dev syntax`, etc.), for detailed examples please refer to the section: [Using python-version input](docs/advanced-usage.md#using-the-python-version-input) of the [Advanced usage](docs/advanced-usage.md) guide.
Check out our detailed guide on using [Python with GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-python-with-github-actions). ## Supported architectures
# Available versions of Python Using `architecture` input it is possible to specify the required Python or PyPy interpreter architecture: `x86` or `x64`. If the input is not specified the architecture defaults to `x64`.
`setup-python` is able to configure Python from two sources: ## Caching packages dependencies
- Preinstalled versions of Python in the tools cache on GitHub-hosted runners. The action has built-in functionality for caching and restoring dependencies. It uses [toolkit/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.
- For detailed information regarding the available versions of Python that are installed, see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software).
- For every minor version of Python, expect only the latest patch to be preinstalled.
- If `3.8.1` is installed for example, and `3.8.2` is released, expect `3.8.1` to be removed and replaced by `3.8.2` in the tools cache.
- If the exact patch version doesn't matter to you, specifying just the major and minor version will get you the latest preinstalled patch version. In the previous example, the version spec `3.8` will use the `3.8.2` Python version found in the cache.
- Downloadable Python versions from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)).
- All available versions are listed in the [version-manifest.json](https://github.com/actions/python-versions/blob/main/versions-manifest.json) file.
- If there is a specific version of Python that is not available, you can open an issue here
# Available versions of PyPy The action defaults to searching for a dependency file (`requirements.txt` for pip, `Pipfile.lock` for pipenv or `poetry.lock` for poetry) in the repository, and uses its hash as a part of the cache key. Input `cache-dependency-path` is used for cases when multiple dependency files are used, they are located in different subdirectories or different files for the hash that want to be used.
`setup-python` is able to configure PyPy from two sources: - For `pip`, the action will cache the global cache directory
- For `pipenv`, the action will cache virtualenv directory
- Preinstalled versions of PyPy in the tools cache on GitHub-hosted runners - For `poetry`, the action will cache virtualenv directory
- For detailed information regarding the available versions of PyPy that are installed, see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software).
- For the latest PyPy release, all versions of Python are cached.
- Cache is updated with a 1-2 week delay. If you specify the PyPy version as `pypy-3.7`, the cached version will be used although a newer version is available. If you need to start using the recently released version right after release, you should specify the exact PyPy version using `pypy-3.7-v7.3.3`.
- Downloadable PyPy versions from the [official PyPy site](https://downloads.python.org/pypy/).
- All available versions that we can download are listed in [versions.json](https://downloads.python.org/pypy/versions.json) file.
- PyPy < 7.3.3 are not available to install on-flight.
- If some versions are not available, you can open an issue in https://foss.heptapod.net/pypy/pypy/
# Hosted Tool Cache
GitHub hosted runners have a tools cache that comes with a few versions of Python + PyPy already installed. This tools cache helps speed up runs and tool setup by not requiring any new downloads. There is an environment variable called `RUNNER_TOOL_CACHE` on each runner that describes the location of this tools cache and there is where you will find Python and PyPy installed. `setup-python` works by taking a specific version of Python or PyPy in this tools cache and adding it to PATH.
|| Location |
|------|-------|
|**Tool Cache Directory** |`RUNNER_TOOL_CACHE`|
|**Python Tool Cache**|`RUNNER_TOOL_CACHE/Python/*`|
|**PyPy Tool Cache**|`RUNNER_TOOL_CACHE/PyPy/*`|
GitHub virtual environments are setup in [actions/virtual-environments](https://github.com/actions/virtual-environments). During the setup, the available versions of Python and PyPy are automatically downloaded, setup and documented.
- [Tools cache setup for Ubuntu](https://github.com/actions/virtual-environments/blob/main/images/linux/scripts/installers/hosted-tool-cache.sh)
- [Tools cache setup for Windows](https://github.com/actions/virtual-environments/blob/main/images/win/scripts/Installers/Download-ToolCache.ps1)
# Specifying a Python version
If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the exact major, minor, and patch version (such as `3.7.5`)
- The only downside to this is that set up will take a little longer since the exact version will have to be downloaded if the exact version is not already installed on the runner due to more recent versions.
- MSI installers are used on Windows for this, so runs will take a little longer to set up vs Mac and Linux.
You should specify only a major and minor version if you are okay with the most recent patch version being used.
- There will be a single patch version already installed on each runner for every minor version of Python that is supported.
- The patch version that will be preinstalled, will generally be the latest and every time there is a new patch released, the older version that is preinstalled will be replaced.
- Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version Python on the runner will be used.
# Specifying a PyPy version
The version of PyPy should be specified in the format `pypy-<python_version>[-v<pypy_version>]`.
The `<pypy_version>` parameter is optional and can be skipped. The latest version will be used in this case.
```
pypy-3.7 # the latest available version of PyPy that supports Python 3.7
pypy-3.8 # the latest available version of PyPy that supports Python 3.8
pypy-2.7 # the latest available version of PyPy that supports Python 2.7
pypy-3.7-v7.3.3 # Python 3.7 and PyPy 7.3.3
pypy-3.7-v7.x # Python 3.7 and the latest available PyPy 7.x
pypy-3.7-v7.3.3rc1 # Python 3.7 and preview version of PyPy
pypy-3.7-nightly # Python 3.7 and nightly PyPy
```
# Caching packages dependencies
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.
The action defaults to searching for a dependency file (`requirements.txt` for pip, `Pipfile.lock` for pipenv or `poetry.lock` for poetry) in the repository, and uses its hash as a part of the cache key. Use `cache-dependency-path` for cases where multiple dependency files are used, they are located in different subdirectories or different files for the hash want to be used.
- For pip, the action will cache global cache directory
- For pipenv, the action will cache virtualenv directory
- For poetry, the action will cache virtualenv directory
**Please Note:** Restored cache will not be used if the requirements.txt file is not updated for a long time and a newer version of the dependency is available that can lead to an increase in total build time.
The requirements file format allows to specify dependency versions using logical operators (for example chardet>=3.0.4) or specify dependencies without any versions. In this case the pip install -r requirements.txt command will always try to install the latest available package version. To be sure that the cache will be used, please stick to a specific dependency version and update it manually if necessary.
**Caching pip dependencies:** **Caching pip dependencies:**
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: actions/setup-python@v3 - uses: actions/setup-python@v4
with: with:
python-version: '3.9' python-version: '3.9'
cache: 'pip' cache: 'pip' # caching pip dependencies
- run: pip install -r requirements.txt - run: pip install -r requirements.txt
``` ```
>**Note:** Restored cache will not be used if the requirements.txt file is not updated for a long time and a newer version of the dependency is available which can lead to an increase in total build time.
**Caching pipenv dependencies:** >The requirements file format allows for specifying dependency versions using logical operators (for example chardet>=3.0.4) or specifying dependencies without any versions. In this case the pip install -r requirements.txt command will always try to install the latest available package version. To be sure that the cache will be used, please stick to a specific dependency version and update it manually if necessary.
```yaml
steps:
- uses: actions/checkout@v3
- name: Install pipenv
run: pipx install pipenv
- uses: actions/setup-python@v3
with:
python-version: '3.9'
cache: 'pipenv'
- run: pipenv install
```
**Caching poetry dependencies:** See examples of using `cache` and `cache-dependency-path` for `pipenv` and `poetry` in the section: [Caching packages](docs/advanced-usage.md#caching-packages) of the [Advanced usage](docs/advanced-usage.md) guide.
```yaml
steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v3
with:
python-version: '3.9'
cache: 'poetry'
- run: poetry install
- run: poetry run pytest
```
**Using wildcard patterns to cache dependencies** ## Advanced usage
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '3.9'
cache: 'pip'
cache-dependency-path: '**/requirements-dev.txt'
- run: pip install -r subdirectory/requirements-dev.txt
```
**Using a list of file paths to cache dependencies** - [Using the python-version input](docs/advanced-usage.md#using-the-python-version-input)
```yaml - [Using the python-version-file input](docs/advanced-usage.md#using-the-python-version-file-input)
steps: - [Check latest version](docs/advanced-usage.md#check-latest-version)
- uses: actions/checkout@v3 - [Caching packages](docs/advanced-usage.md#caching-packages)
- name: Install pipenv - [Outputs and environment variables](docs/advanced-usage.md#outputs-and-environment-variables)
run: pipx install pipenv - [Available versions of Python and PyPy](docs/advanced-usage.md#available-versions-of-python-and-pypy)
- uses: actions/setup-python@v3 - [Hosted tool cache](docs/advanced-usage.md#hosted-tool-cache)
with: - [Using `setup-python` with a self-hosted runner](docs/advanced-usage.md#using-setup-python-with-a-self-hosted-runner)
python-version: '3.9' - [Using `setup-python` on GHES](docs/advanced-usage.md#using-setup-python-on-ghes)
cache: 'pipenv'
cache-dependency-path: |
server/app/Pipfile.lock
__test__/app/Pipfile.lock
- run: pipenv install
```
# Using `setup-python` with a self hosted runner ## License
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.
If you are experiencing problems while configuring Python on your self-hosted runner, turn on [step debugging](https://github.com/actions/toolkit/blob/main/docs/action-debugging.md#step-debug-logs) to see addition logs.
### Windows
- Your runner needs to be running with administrator privileges so that the appropriate directories and files can be set up when downloading and installing a new version of Python for the first time.
- If your runner is configured as a service, make sure the account that is running the service has the appropriate write permissions so that Python can get installed. The default `NT AUTHORITY\NETWORK SERVICE` should be sufficient.
- You need `7zip` installed and added to your `PATH` so that the downloaded versions of Python files can be extracted properly during first-time setup.
- MSI installers are used when setting up Python on Windows. A word of caution as MSI installers update registry settings.
- The 3.8 MSI installer for Windows will not let you install another 3.8 version of Python. If `setup-python` fails for a 3.8 version of Python, make sure any previously installed versions are removed by going to "Apps & Features" in the Settings app.
### Linux
- The Python packages that are downloaded from `actions/python-versions` are originally compiled from source in `/opt/hostedtoolcache/` with the [--enable-shared](https://github.com/actions/python-versions/blob/94f04ae6806c6633c82db94c6406a16e17decd5c/builders/ubuntu-python-builder.psm1#L35) flag, which makes them non-relocatable.
- Create an environment variable called `AGENT_TOOLSDIRECTORY` and set it to `/opt/hostedtoolcache`. This controls where the runner downloads and installs tools.
- In the same shell that your runner is using, type `export AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`.
- A more permanent way of setting the environment variable is to create a `.env` file in the same directory as your runner and to add `AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`. This ensures the variable is always set if your runner is configured as a service.
- Create a directory called `hostedtoolcache` inside `/opt`.
- The user starting the runner must have write permission to the `/opt/hostedtoolcache` directory. It is not possible to start the Linux runner with `sudo` and the `/opt` directory usually requires root privileges to write to. Check the current user and group that the runner belongs to by typing `ls -l` inside the runners root directory.
- The runner can be granted write access to the `/opt/hostedtoolcache` directory using a few techniques:
- The user starting the runner is the owner, and the owner has write permission.
- The user starting the runner is in the owning group, and the owning group has write permission.
- All users have write permission.
- One quick way to grant access is to change the user and group of `/opt/hostedtoolcache` to be the same as the runners using `chown`.
- `sudo chown runner-user:runner-group /opt/hostedtoolcache/`.
- If your runner is configured as a service and you run into problems, make sure the user that the service is running as is correct. For more information, you can [check the status of your self-hosted runner](https://help.github.com/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service#checking-the-status-of-the-service).
### Mac
- The same setup that applies to `Linux` also applies to `Mac`, just with a different tools cache directory.
- Create a directory called `/Users/runner/hostedtoolcache`.
- Set the `AGENT_TOOLSDIRECTORY` environment variable to `/Users/runner/hostedtoolcache`.
- Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access.
# Using Python without `setup-python`
`setup-python` helps keep your dependencies explicit and ensures consistent behavior between different runners. If you use `python` in a shell on a GitHub hosted runner without `setup-python` it will default to whatever is in PATH. The default version of Python in PATH vary between runners and can change unexpectedly so we recommend you always use `setup-python`.
# Using `setup-python` on GHES
`setup-python` comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading Python distributions, `setup-python` downloads distributions from [`actions/python-versions`](https://github.com/actions/python-versions) on github.com (outside of the appliance). These calls to `actions/python-versions` are made via unauthenticated requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting). If more requests are made within the time frame, then you will start to see rate-limit errors during download that read `##[error]API rate limit exceeded for...`.
To avoid hitting rate-limit problems, we recommend [setting up your own runner tool cache](https://docs.github.com/en/enterprise-server@2.22/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access#about-the-included-setup-actions-and-the-runner-tool-cache).
# License
The scripts and documentation in this project are released under the [MIT License](LICENSE). The scripts and documentation in this project are released under the [MIT License](LICENSE).
# Contributions ## Contributions
Contributions are welcome! See our [Contributor's Guide](docs/contributors.md). Contributions are welcome! See our [Contributor's Guide](docs/contributors.md).

View File

@ -1,11 +1,13 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as cache from '@actions/cache'; import * as cache from '@actions/cache';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
import * as io from '@actions/io';
import {getCacheDistributor} from '../src/cache-distributions/cache-factory'; import {getCacheDistributor} from '../src/cache-distributions/cache-factory';
import * as utils from './../src/utils';
describe('restore-cache', () => { describe('restore-cache', () => {
const pipFileLockHash = const pipFileLockHash =
'd1dd6218299d8a6db5fc2001d988b34a8b31f1e9d0bb4534d377dde7c19f64b3'; 'a3bdcc71289e4979ca9e051810d81999cc99823109faf6912e17ff14c8e621a6';
const requirementsHash = const requirementsHash =
'd8110e0006d7fb5ee76365d565eef9d37df1d11598b912d3eb66d398d57a1121'; 'd8110e0006d7fb5ee76365d565eef9d37df1d11598b912d3eb66d398d57a1121';
const requirementsLinuxHash = const requirementsLinuxHash =
@ -28,6 +30,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
let saveSatetSpy: jest.SpyInstance; let saveSatetSpy: jest.SpyInstance;
let getStateSpy: jest.SpyInstance; let getStateSpy: jest.SpyInstance;
let setOutputSpy: jest.SpyInstance; let setOutputSpy: jest.SpyInstance;
let getLinuxOSReleaseInfoSpy: jest.SpyInstance;
// cache spy // cache spy
let restoreCacheSpy: jest.SpyInstance; let restoreCacheSpy: jest.SpyInstance;
@ -35,6 +38,9 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
// exec spy // exec spy
let getExecOutputSpy: jest.SpyInstance; let getExecOutputSpy: jest.SpyInstance;
// io spy
let whichSpy: jest.SpyInstance;
beforeEach(() => { beforeEach(() => {
process.env['RUNNER_OS'] = process.env['RUNNER_OS'] ?? 'linux'; process.env['RUNNER_OS'] = process.env['RUNNER_OS'] ?? 'linux';
@ -74,6 +80,10 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
return primaryKey; return primaryKey;
} }
); );
whichSpy = jest.spyOn(io, 'which');
whichSpy.mockImplementation(() => '/path/to/python');
getLinuxOSReleaseInfoSpy = jest.spyOn(utils, 'getLinuxOSReleaseInfo');
}); });
describe('Validate provided package manager', () => { describe('Validate provided package manager', () => {
@ -109,11 +119,24 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
pythonVersion, pythonVersion,
dependencyFile dependencyFile
); );
if (process.platform === 'linux') {
getLinuxOSReleaseInfoSpy.mockImplementation(() =>
Promise.resolve('Ubuntu-20.4')
);
}
await cacheDistributor.restoreCache(); await cacheDistributor.restoreCache();
expect(infoSpy).toHaveBeenCalledWith( if (process.platform === 'linux' && packageManager === 'pip') {
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}` expect(infoSpy).toHaveBeenCalledWith(
); `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-Ubuntu-20.4-python-${pythonVersion}-${packageManager}-${fileHash}`
);
} else {
expect(infoSpy).toHaveBeenCalledWith(
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}`
);
}
}, },
30000 30000
); );

View File

@ -212,6 +212,59 @@ describe('run', () => {
); );
expect(setFailedSpy).not.toHaveBeenCalled(); expect(setFailedSpy).not.toHaveBeenCalled();
}); });
it('saves with -1 cacheId , should not fail workflow', async () => {
inputs['cache'] = 'poetry';
getStateSpy.mockImplementation((name: string) => {
if (name === State.STATE_CACHE_PRIMARY_KEY) {
return poetryLockHash;
} else if (name === State.CACHE_PATHS) {
return JSON.stringify([__dirname]);
} else {
return requirementsHash;
}
});
saveCacheSpy.mockImplementation(() => {
return -1;
});
await run();
expect(getInputSpy).toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(3);
expect(infoSpy).not.toHaveBeenCalled();
expect(saveCacheSpy).toHaveBeenCalled();
expect(infoSpy).not.toHaveBeenLastCalledWith(
`Cache saved with the key: ${poetryLockHash}`
);
expect(setFailedSpy).not.toHaveBeenCalled();
});
it('saves with error from toolkit, should fail workflow', async () => {
inputs['cache'] = 'npm';
getStateSpy.mockImplementation((name: string) => {
if (name === State.STATE_CACHE_PRIMARY_KEY) {
return poetryLockHash;
} else if (name === State.CACHE_PATHS) {
return JSON.stringify([__dirname]);
} else {
return requirementsHash;
}
});
saveCacheSpy.mockImplementation(() => {
throw new cache.ValidationError('Validation failed');
});
await run();
expect(getInputSpy).toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(3);
expect(infoSpy).not.toHaveBeenCalledWith();
expect(saveCacheSpy).toHaveBeenCalled();
expect(setFailedSpy).toHaveBeenCalled();
});
}); });
afterEach(() => { afterEach(() => {

14
__tests__/check-python-path.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
set -euo pipefail
PYTHON_PATH="$1"
PATH_EXECUTABLE=$(python -c 'import sys; print(sys.executable)')
PYTHON_PATH_EXECUTABLE=$("${PYTHON_PATH}" -c 'import sys; print(sys.executable)')
if [ "${PATH_EXECUTABLE}" != "${PYTHON_PATH_EXECUTABLE}" ]; then
echo "Executable mismatch."
echo "python in PATH is: ${PATH_EXECUTABLE}"
echo "python-path (${PYTHON_PATH}) is: ${PYTHON_PATH_EXECUTABLE}"
exit 1
fi
echo "python-path: ${PYTHON_PATH}"

View File

@ -4,8 +4,8 @@ verify_ssl = true
name = "pypi" name = "pypi"
[packages] [packages]
numpy = "1.22.3" flake8 = "==4.0.1"
pandas = "1.4.2" numpy = "==1.23.0"
[dev-packages] [dev-packages]

View File

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "33e3640eff8b2b6c7149b85568151f39a66c544033b4b3f3f2ec9ad5ce6dfe7e" "sha256": "e9c37110984955621040e2dc8548c026eb8466c23db1b8e69430289b10be8938"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -16,81 +16,64 @@
] ]
}, },
"default": { "default": {
"flake8": {
"hashes": [
"sha256:479b1304f72536a55948cb40a32dce8bb0ffe3501e26eaf292c7e60eb5e0428d",
"sha256:806e034dda44114815e23c16ef92f95c91e4c71100ff52813adf7132a6ad870d"
],
"index": "pypi",
"version": "==4.0.1"
},
"mccabe": {
"hashes": [
"sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42",
"sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"
],
"version": "==0.6.1"
},
"numpy": { "numpy": {
"hashes": [ "hashes": [
"sha256:07a8c89a04997625236c5ecb7afe35a02af3896c8aa01890a849913a2309c676", "sha256:092f5e6025813e64ad6d1b52b519165d08c730d099c114a9247c9bb635a2a450",
"sha256:08d9b008d0156c70dc392bb3ab3abb6e7a711383c3247b410b39962263576cd4", "sha256:196cd074c3f97c4121601790955f915187736f9cf458d3ee1f1b46aff2b1ade0",
"sha256:201b4d0552831f7250a08d3b38de0d989d6f6e4658b709a02a73c524ccc6ffce", "sha256:1c29b44905af288b3919803aceb6ec7fec77406d8b08aaa2e8b9e63d0fe2f160",
"sha256:2c10a93606e0b4b95c9b04b77dc349b398fdfbda382d2a39ba5a822f669a0123", "sha256:2b2da66582f3a69c8ce25ed7921dcd8010d05e59ac8d89d126a299be60421171",
"sha256:3ca688e1b9b95d80250bca34b11a05e389b1420d00e87a0d12dc45f131f704a1", "sha256:5043bcd71fcc458dfb8a0fc5509bbc979da0131b9d08e3d5f50fb0bbb36f169a",
"sha256:48a3aecd3b997bf452a2dedb11f4e79bc5bfd21a1d4cc760e703c31d57c84b3e", "sha256:58bfd40eb478f54ff7a5710dd61c8097e169bc36cc68333d00a9bcd8def53b38",
"sha256:568dfd16224abddafb1cbcce2ff14f522abe037268514dd7e42c6776a1c3f8e5", "sha256:79a506cacf2be3a74ead5467aee97b81fca00c9c4c8b3ba16dbab488cd99ba10",
"sha256:5bfb1bb598e8229c2d5d48db1860bcf4311337864ea3efdbe1171fb0c5da515d", "sha256:94b170b4fa0168cd6be4becf37cb5b127bd12a795123984385b8cd4aca9857e5",
"sha256:639b54cdf6aa4f82fe37ebf70401bbb74b8508fddcf4797f9fe59615b8c5813a", "sha256:97a76604d9b0e79f59baeca16593c711fddb44936e40310f78bfef79ee9a835f",
"sha256:8251ed96f38b47b4295b1ae51631de7ffa8260b5b087808ef09a39a9d66c97ab", "sha256:98e8e0d8d69ff4d3fa63e6c61e8cfe2d03c29b16b58dbef1f9baa175bbed7860",
"sha256:92bfa69cfbdf7dfc3040978ad09a48091143cffb778ec3b03fa170c494118d75", "sha256:ac86f407873b952679f5f9e6c0612687e51547af0e14ddea1eedfcb22466babd",
"sha256:97098b95aa4e418529099c26558eeb8486e66bd1e53a6b606d684d0c3616b168", "sha256:ae8adff4172692ce56233db04b7ce5792186f179c415c37d539c25de7298d25d",
"sha256:a3bae1a2ed00e90b3ba5f7bd0a7c7999b55d609e0c54ceb2b076a25e345fa9f4", "sha256:bd3fa4fe2e38533d5336e1272fc4e765cabbbde144309ccee8675509d5cd7b05",
"sha256:c34ea7e9d13a70bf2ab64a2532fe149a9aced424cd05a2c4ba662fd989e3e45f", "sha256:d0d2094e8f4d760500394d77b383a1b06d3663e8892cdf5df3c592f55f3bff66",
"sha256:dbc7601a3b7472d559dc7b933b18b4b66f9aa7452c120e87dfb33d02008c8a18", "sha256:d54b3b828d618a19779a84c3ad952e96e2c2311b16384e973e671aa5be1f6187",
"sha256:e7927a589df200c5e23c57970bafbd0cd322459aa7b1ff73b7c2e84d6e3eae62", "sha256:d6ca8dabe696c2785d0c8c9b0d8a9b6e5fdbe4f922bde70d57fa1a2848134f95",
"sha256:f8c1f39caad2c896bc0018f699882b345b2a63708008be29b1f355ebf6f933fe", "sha256:d8cc87bed09de55477dba9da370c1679bd534df9baa171dd01accbb09687dac3",
"sha256:f950f8845b480cffe522913d35567e29dd381b0dc7e4ce6a4a9f9156417d2430", "sha256:f0f18804df7370571fb65db9b98bf1378172bd4e962482b857e612d1fec0f53e",
"sha256:fade0d4f4d292b6f39951b6836d7a3c7ef5b2347f3c420cd9820a1d90d794802", "sha256:f1d88ef79e0a7fa631bb2c3dda1ea46b32b1fe614e10fedd611d3d5398447f2f",
"sha256:fdf3c08bce27132395d3c3ba1503cac12e17282358cb4bddc25cc46b0aca07aa" "sha256:f9c3fc2adf67762c9fe1849c859942d23f8d3e0bee7b5ed3d4a9c3eeb50a2f07",
"sha256:fc431493df245f3c627c0c05c2bd134535e7929dbe2e602b80e42bf52ff760bc",
"sha256:fe8b9683eb26d2c4d5db32cd29b38fdcf8381324ab48313b5b69088e0e355379"
], ],
"index": "pypi", "index": "pypi",
"version": "==1.22.3" "version": "==1.23.0"
}, },
"pandas": { "pycodestyle": {
"hashes": [ "hashes": [
"sha256:0010771bd9223f7afe5f051eb47c4a49534345dfa144f2f5470b27189a4dd3b5", "sha256:720f8b39dde8b293825e7ff02c475f3077124006db4f440dcbc9a20b76548a20",
"sha256:061609334a8182ab500a90fe66d46f6f387de62d3a9cb9aa7e62e3146c712167", "sha256:eddd5847ef438ea1c7870ca7eb78a9d47ce0cdb4851a5523949f2601d0cbbe7f"
"sha256:09d8be7dd9e1c4c98224c4dfe8abd60d145d934e9fc1f5f411266308ae683e6a",
"sha256:295872bf1a09758aba199992c3ecde455f01caf32266d50abc1a073e828a7b9d",
"sha256:3228198333dd13c90b6434ddf61aa6d57deaca98cf7b654f4ad68a2db84f8cfe",
"sha256:385c52e85aaa8ea6a4c600a9b2821181a51f8be0aee3af6f2dcb41dafc4fc1d0",
"sha256:51649ef604a945f781105a6d2ecf88db7da0f4868ac5d45c51cb66081c4d9c73",
"sha256:5586cc95692564b441f4747c47c8a9746792e87b40a4680a2feb7794defb1ce3",
"sha256:5a206afa84ed20e07603f50d22b5f0db3fb556486d8c2462d8bc364831a4b417",
"sha256:5b79af3a69e5175c6fa7b4e046b21a646c8b74e92c6581a9d825687d92071b51",
"sha256:5c54ea4ef3823108cd4ec7fb27ccba4c3a775e0f83e39c5e17f5094cb17748bc",
"sha256:8c5bf555b6b0075294b73965adaafb39cf71c312e38c5935c93d78f41c19828a",
"sha256:92bc1fc585f1463ca827b45535957815b7deb218c549b7c18402c322c7549a12",
"sha256:95c1e422ced0199cf4a34385ff124b69412c4bc912011ce895582bee620dfcaa",
"sha256:b8134651258bce418cb79c71adeff0a44090c98d955f6953168ba16cc285d9f7",
"sha256:be67c782c4f1b1f24c2f16a157e12c2693fd510f8df18e3287c77f33d124ed07",
"sha256:c072c7f06b9242c855ed8021ff970c0e8f8b10b35e2640c657d2a541c5950f59",
"sha256:d0d4f13e4be7ce89d7057a786023c461dd9370040bdb5efa0a7fe76b556867a0",
"sha256:df82739e00bb6daf4bba4479a40f38c718b598a84654cbd8bb498fd6b0aa8c16",
"sha256:f549097993744ff8c41b5e8f2f0d3cbfaabe89b4ae32c8c08ead6cc535b80139",
"sha256:ff08a14ef21d94cdf18eef7c569d66f2e24e0bc89350bcd7d243dd804e3b5eb2"
], ],
"index": "pypi", "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
"version": "==1.4.2" "version": "==2.8.0"
}, },
"python-dateutil": { "pyflakes": {
"hashes": [ "hashes": [
"sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86", "sha256:05a85c2872edf37a4ed30b0cce2f6093e1d0581f8c19d7393122da7e25b2b24c",
"sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9" "sha256:3bb3a3f256f4b7968c9c788781e4ff07dce46bdf12339dcda61053375426ee2e"
], ],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'", "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==2.8.2" "version": "==2.4.0"
},
"pytz": {
"hashes": [
"sha256:1e760e2fe6a8163bc0b3d9a19c4f84342afa0a2affebfaa84b01b978a02ecaa7",
"sha256:e68985985296d9a66a881eb3193b0906246245294a881e7c8afe623866ac6a5c"
],
"version": "==2022.1"
},
"six": {
"hashes": [
"sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926",
"sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'",
"version": "==1.16.0"
} }
}, },
"develop": {} "develop": {}

View File

@ -0,0 +1,15 @@
[tool.poetry]
name = "testactiontasks"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = "^3.8"
flake8 = "^4.0.1"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

View File

@ -5,6 +5,7 @@ import {HttpClient} from '@actions/http-client';
import * as ifm from '@actions/http-client/interfaces'; import * as ifm from '@actions/http-client/interfaces';
import * as tc from '@actions/tool-cache'; import * as tc from '@actions/tool-cache';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
import * as core from '@actions/core';
import * as path from 'path'; import * as path from 'path';
import * as semver from 'semver'; import * as semver from 'semver';
@ -13,7 +14,6 @@ import * as finder from '../src/find-pypy';
import { import {
IPyPyManifestRelease, IPyPyManifestRelease,
IS_WINDOWS, IS_WINDOWS,
validateVersion,
getPyPyVersionFromPath getPyPyVersionFromPath
} from '../src/utils'; } from '../src/utils';
@ -37,16 +37,34 @@ describe('parsePyPyVersion', () => {
['pypy-3.6-v7.x', {pythonVersion: '3.6', pypyVersion: 'v7.x'}], ['pypy-3.6-v7.x', {pythonVersion: '3.6', pypyVersion: 'v7.x'}],
['pypy-3.6', {pythonVersion: '3.6', pypyVersion: 'x'}], ['pypy-3.6', {pythonVersion: '3.6', pypyVersion: 'x'}],
['pypy-3.6-nightly', {pythonVersion: '3.6', pypyVersion: 'nightly'}], ['pypy-3.6-nightly', {pythonVersion: '3.6', pypyVersion: 'nightly'}],
['pypy-3.6-v7.3.3rc1', {pythonVersion: '3.6', pypyVersion: 'v7.3.3-rc.1'}] ['pypy-3.6-v7.3.3rc1', {pythonVersion: '3.6', pypyVersion: 'v7.3.3-rc.1'}],
['pypy3.8-v7.3.7', {pythonVersion: '3.8', pypyVersion: 'v7.3.7'}],
['pypy3.8-v7.3.x', {pythonVersion: '3.8', pypyVersion: 'v7.3.x'}],
['pypy3.8-v7.x', {pythonVersion: '3.8', pypyVersion: 'v7.x'}],
['pypy3.8', {pythonVersion: '3.8', pypyVersion: 'x'}],
['pypy3.9-nightly', {pythonVersion: '3.9', pypyVersion: 'nightly'}],
['pypy3.9-v7.3.8rc1', {pythonVersion: '3.9', pypyVersion: 'v7.3.8-rc.1'}]
])('%s -> %s', (input, expected) => { ])('%s -> %s', (input, expected) => {
expect(finder.parsePyPyVersion(input)).toEqual(expected); expect(finder.parsePyPyVersion(input)).toEqual(expected);
}); });
it('throw on invalid input', () => { it.each(['', 'pypy-', 'pypy', 'p', 'notpypy-'])(
expect(() => finder.parsePyPyVersion('pypy-')).toThrowError( 'throw on invalid input "%s"',
"Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy-<python-version>'. See README for examples and documentation." input => {
); expect(() => finder.parsePyPyVersion(input)).toThrowError(
}); "Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy<python-version>' or 'pypy-<python-version>'. See README for examples and documentation."
);
}
);
it.each(['pypy-2', 'pypy-3', 'pypy2', 'pypy3', 'pypy3.x', 'pypy3.8.10'])(
'throw on invalid input "%s"',
input => {
expect(() => finder.parsePyPyVersion(input)).toThrowError(
"Invalid format of Python version for PyPy. Python version should be specified in format 'x.y'. See README for examples and documentation."
);
}
);
}); });
describe('getPyPyVersionFromPath', () => { describe('getPyPyVersionFromPath', () => {
@ -63,6 +81,12 @@ describe('findPyPyToolCache', () => {
const pypyPath = path.join('PyPy', actualPythonVersion, architecture); const pypyPath = path.join('PyPy', actualPythonVersion, architecture);
let tcFind: jest.SpyInstance; let tcFind: jest.SpyInstance;
let spyReadExactPyPyVersion: jest.SpyInstance; let spyReadExactPyPyVersion: jest.SpyInstance;
let infoSpy: jest.SpyInstance;
let warningSpy: jest.SpyInstance;
let debugSpy: jest.SpyInstance;
let addPathSpy: jest.SpyInstance;
let exportVariableSpy: jest.SpyInstance;
let setOutputSpy: jest.SpyInstance;
beforeEach(() => { beforeEach(() => {
tcFind = jest.spyOn(tc, 'find'); tcFind = jest.spyOn(tc, 'find');
@ -75,6 +99,24 @@ describe('findPyPyToolCache', () => {
spyReadExactPyPyVersion = jest.spyOn(utils, 'readExactPyPyVersionFile'); spyReadExactPyPyVersion = jest.spyOn(utils, 'readExactPyPyVersionFile');
spyReadExactPyPyVersion.mockImplementation(() => actualPyPyVersion); spyReadExactPyPyVersion.mockImplementation(() => actualPyPyVersion);
infoSpy = jest.spyOn(core, 'info');
infoSpy.mockImplementation(() => null);
warningSpy = jest.spyOn(core, 'warning');
warningSpy.mockImplementation(() => null);
debugSpy = jest.spyOn(core, 'debug');
debugSpy.mockImplementation(() => null);
addPathSpy = jest.spyOn(core, 'addPath');
addPathSpy.mockImplementation(() => null);
exportVariableSpy = jest.spyOn(core, 'exportVariable');
exportVariableSpy.mockImplementation(() => null);
setOutputSpy = jest.spyOn(core, 'setOutput');
setOutputSpy.mockImplementation(() => null);
}); });
afterEach(() => { afterEach(() => {
@ -117,6 +159,13 @@ describe('findPyPyToolCache', () => {
}); });
describe('findPyPyVersion', () => { describe('findPyPyVersion', () => {
let getBooleanInputSpy: jest.SpyInstance;
let warningSpy: jest.SpyInstance;
let debugSpy: jest.SpyInstance;
let infoSpy: jest.SpyInstance;
let addPathSpy: jest.SpyInstance;
let exportVariableSpy: jest.SpyInstance;
let setOutputSpy: jest.SpyInstance;
let tcFind: jest.SpyInstance; let tcFind: jest.SpyInstance;
let spyExtractZip: jest.SpyInstance; let spyExtractZip: jest.SpyInstance;
let spyExtractTar: jest.SpyInstance; let spyExtractTar: jest.SpyInstance;
@ -130,8 +179,34 @@ describe('findPyPyVersion', () => {
let spyWriteExactPyPyVersionFile: jest.SpyInstance; let spyWriteExactPyPyVersionFile: jest.SpyInstance;
let spyCacheDir: jest.SpyInstance; let spyCacheDir: jest.SpyInstance;
let spyChmodSync: jest.SpyInstance; let spyChmodSync: jest.SpyInstance;
let spyCoreAddPath: jest.SpyInstance;
let spyCoreExportVariable: jest.SpyInstance;
const env = process.env;
beforeEach(() => { beforeEach(() => {
getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput');
getBooleanInputSpy.mockImplementation(() => false);
infoSpy = jest.spyOn(core, 'info');
infoSpy.mockImplementation(() => {});
warningSpy = jest.spyOn(core, 'warning');
warningSpy.mockImplementation(() => null);
debugSpy = jest.spyOn(core, 'debug');
debugSpy.mockImplementation(() => null);
addPathSpy = jest.spyOn(core, 'addPath');
addPathSpy.mockImplementation(() => null);
exportVariableSpy = jest.spyOn(core, 'exportVariable');
exportVariableSpy.mockImplementation(() => null);
setOutputSpy = jest.spyOn(core, 'setOutput');
setOutputSpy.mockImplementation(() => null);
jest.resetModules();
process.env = {...env};
tcFind = jest.spyOn(tc, 'find'); tcFind = jest.spyOn(tc, 'find');
tcFind.mockImplementation((tool: string, version: string) => { tcFind.mockImplementation((tool: string, version: string) => {
const semverRange = new semver.Range(version); const semverRange = new semver.Range(version);
@ -183,32 +258,46 @@ describe('findPyPyVersion', () => {
spyExistsSync = jest.spyOn(fs, 'existsSync'); spyExistsSync = jest.spyOn(fs, 'existsSync');
spyExistsSync.mockReturnValue(true); spyExistsSync.mockReturnValue(true);
spyCoreAddPath = jest.spyOn(core, 'addPath');
spyCoreExportVariable = jest.spyOn(core, 'exportVariable');
}); });
afterEach(() => { afterEach(() => {
jest.resetAllMocks(); jest.resetAllMocks();
jest.clearAllMocks(); jest.clearAllMocks();
jest.restoreAllMocks(); jest.restoreAllMocks();
process.env = env;
}); });
it('found PyPy in toolcache', async () => { it('found PyPy in toolcache', async () => {
await expect( await expect(
finder.findPyPyVersion('pypy-3.6-v7.3.x', architecture) finder.findPyPyVersion('pypy-3.6-v7.3.x', architecture, true, false)
).resolves.toEqual({ ).resolves.toEqual({
resolvedPythonVersion: '3.6.12', resolvedPythonVersion: '3.6.12',
resolvedPyPyVersion: '7.3.3' 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 () => { it('throw on invalid input format', async () => {
await expect( await expect(
finder.findPyPyVersion('pypy3.7-v7.3.x', architecture) finder.findPyPyVersion('pypy3.7-v7.3.x', architecture, true, false)
).rejects.toThrow(); ).rejects.toThrow();
}); });
it('throw on invalid input format pypy3.7-7.3.x', async () => { it('throw on invalid input format pypy3.7-7.3.x', async () => {
await expect( await expect(
finder.findPyPyVersion('pypy3.7-v7.3.x', architecture) finder.findPyPyVersion('pypy3.7-v7.3.x', architecture, true, false)
).rejects.toThrow(); ).rejects.toThrow();
}); });
@ -220,18 +309,96 @@ describe('findPyPyVersion', () => {
spyChmodSync = jest.spyOn(fs, 'chmodSync'); spyChmodSync = jest.spyOn(fs, 'chmodSync');
spyChmodSync.mockImplementation(() => undefined); spyChmodSync.mockImplementation(() => undefined);
await expect( await expect(
finder.findPyPyVersion('pypy-3.7-v7.3.x', architecture) finder.findPyPyVersion('pypy-3.7-v7.3.x', architecture, true, false)
).resolves.toEqual({ ).resolves.toEqual({
resolvedPythonVersion: '3.7.9', resolvedPythonVersion: '3.7.9',
resolvedPyPyVersion: '7.3.3' 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, 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 () => { it('throw if release is not found', async () => {
await expect( await expect(
finder.findPyPyVersion('pypy-3.7-v7.5.x', architecture) finder.findPyPyVersion('pypy-3.7-v7.5.x', architecture, true, false)
).rejects.toThrowError( ).rejects.toThrowError(
`PyPy version 3.7 (v7.5.x) with arch ${architecture} not found` `PyPy version 3.7 (v7.5.x) with arch ${architecture} not found`
); );
}); });
it('check-latest enabled version found and used from toolcache', async () => {
await expect(
finder.findPyPyVersion('pypy-3.6-v7.3.x', architecture, false, true)
).resolves.toEqual({
resolvedPythonVersion: '3.6.12',
resolvedPyPyVersion: '7.3.3'
});
expect(infoSpy).toHaveBeenCalledWith(
'Resolved as PyPy 7.3.3 with Python (3.6.12)'
);
});
it('check-latest enabled version found and install successfully', 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, true)
).resolves.toEqual({
resolvedPythonVersion: '3.7.9',
resolvedPyPyVersion: '7.3.3'
});
expect(infoSpy).toHaveBeenCalledWith(
'Resolved as PyPy 7.3.3 with Python (3.7.9)'
);
});
it('check-latest enabled version is not found and used from toolcache', async () => {
tcFind.mockImplementationOnce((tool: string, version: string) => {
const semverRange = new semver.Range(version);
let pypyPath = '';
if (semver.satisfies('3.8.8', semverRange)) {
pypyPath = path.join(toolDir, 'PyPy', '3.8.8', architecture);
}
return pypyPath;
});
await expect(
finder.findPyPyVersion('pypy-3.8-v7.3.x', architecture, false, true)
).resolves.toEqual({
resolvedPythonVersion: '3.8.8',
resolvedPyPyVersion: '7.3.3'
});
expect(infoSpy).toHaveBeenCalledWith(
'Failed to resolve PyPy v7.3.x with Python (3.8) from manifest'
);
});
}); });

View File

@ -1,6 +1,7 @@
import io = require('@actions/io'); import * as io from '@actions/io';
import fs = require('fs'); import os from 'os';
import path = require('path'); import fs from 'fs';
import path from 'path';
const toolDir = path.join( const toolDir = path.join(
__dirname, __dirname,
@ -19,29 +20,71 @@ process.env['RUNNER_TOOL_CACHE'] = toolDir;
process.env['RUNNER_TEMP'] = tempDir; process.env['RUNNER_TEMP'] = tempDir;
import * as tc from '@actions/tool-cache'; import * as tc from '@actions/tool-cache';
import * as core from '@actions/core';
import * as finder from '../src/find-python'; import * as finder from '../src/find-python';
import * as installer from '../src/install-python'; import * as installer from '../src/install-python';
const manifestData = require('./data/versions-manifest.json'); const manifestData = require('./data/versions-manifest.json');
describe('Finder tests', () => { describe('Finder tests', () => {
let writeSpy: jest.SpyInstance;
let spyCoreAddPath: jest.SpyInstance;
let spyCoreExportVariable: jest.SpyInstance;
const env = process.env;
beforeEach(() => {
writeSpy = jest.spyOn(process.stdout, 'write');
writeSpy.mockImplementation(() => {});
jest.resetModules();
process.env = {...env};
spyCoreAddPath = jest.spyOn(core, 'addPath');
spyCoreExportVariable = jest.spyOn(core, 'exportVariable');
});
afterEach(() => { afterEach(() => {
jest.resetAllMocks(); jest.resetAllMocks();
jest.clearAllMocks(); jest.clearAllMocks();
jest.restoreAllMocks();
process.env = env;
}); });
it('Finds Python if it is installed', async () => { it('Finds Python if it is installed', async () => {
const getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput');
getBooleanInputSpy.mockImplementation(input => false);
const pythonDir: string = path.join(toolDir, 'Python', '3.0.0', 'x64'); const pythonDir: string = path.join(toolDir, 'Python', '3.0.0', 'x64');
await io.mkdirP(pythonDir); await io.mkdirP(pythonDir);
fs.writeFileSync(`${pythonDir}.complete`, 'hello'); 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) // This will throw if it doesn't find it in the cache and in the manifest (because no such version exists)
await finder.useCpythonVersion('3.x', 'x64'); await finder.useCpythonVersion('3.x', 'x64', true, false);
expect(spyCoreAddPath).toHaveBeenCalled();
expect(spyCoreExportVariable).toHaveBeenCalledWith(
'pythonLocation',
expect.anything()
);
expect(spyCoreExportVariable).toHaveBeenCalledWith(
'PKG_CONFIG_PATH',
expect.anything()
);
});
it('Finds Python if it is installed without environment update', 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 and in the manifest (because no such version exists)
await finder.useCpythonVersion('3.x', 'x64', false, false);
expect(spyCoreAddPath).not.toHaveBeenCalled();
expect(spyCoreExportVariable).not.toHaveBeenCalled();
}); });
it('Finds stable Python version if it is not installed, but exists in the manifest', async () => { it('Finds stable Python version if it is not installed, but exists in the manifest', async () => {
const findSpy: jest.SpyInstance = jest.spyOn(tc, 'getManifestFromRepo'); const findSpy: jest.SpyInstance = jest.spyOn(tc, 'getManifestFromRepo');
findSpy.mockImplementation(() => <tc.IToolRelease[]>manifestData); findSpy.mockImplementation(() => <tc.IToolRelease[]>manifestData);
const getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput');
getBooleanInputSpy.mockImplementation(input => false);
const installSpy: jest.SpyInstance = jest.spyOn( const installSpy: jest.SpyInstance = jest.spyOn(
installer, installer,
'installCpythonFromRelease' 'installCpythonFromRelease'
@ -52,13 +95,25 @@ describe('Finder tests', () => {
fs.writeFileSync(`${pythonDir}.complete`, 'hello'); 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) // This will throw if it doesn't find it in the cache and in the manifest (because no such version exists)
await finder.useCpythonVersion('1.2.3', 'x64'); await finder.useCpythonVersion('1.2.3', 'x64', true, false);
expect(spyCoreAddPath).toHaveBeenCalled();
expect(spyCoreExportVariable).toHaveBeenCalledWith(
'pythonLocation',
expect.anything()
);
expect(spyCoreExportVariable).toHaveBeenCalledWith(
'PKG_CONFIG_PATH',
expect.anything()
);
}); });
it('Finds pre-release Python version in the manifest', async () => { it('Finds pre-release Python version in the manifest', async () => {
const findSpy: jest.SpyInstance = jest.spyOn(tc, 'getManifestFromRepo'); const findSpy: jest.SpyInstance = jest.spyOn(tc, 'getManifestFromRepo');
findSpy.mockImplementation(() => <tc.IToolRelease[]>manifestData); findSpy.mockImplementation(() => <tc.IToolRelease[]>manifestData);
const getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput');
getBooleanInputSpy.mockImplementation(input => false);
const installSpy: jest.SpyInstance = jest.spyOn( const installSpy: jest.SpyInstance = jest.spyOn(
installer, installer,
'installCpythonFromRelease' 'installCpythonFromRelease'
@ -74,17 +129,86 @@ describe('Finder tests', () => {
fs.writeFileSync(`${pythonDir}.complete`, 'hello'); fs.writeFileSync(`${pythonDir}.complete`, 'hello');
}); });
// This will throw if it doesn't find it in the manifest (because no such version exists) // This will throw if it doesn't find it in the manifest (because no such version exists)
await finder.useCpythonVersion('1.2.3-beta.2', 'x64'); await finder.useCpythonVersion('1.2.3-beta.2', 'x64', false, false);
});
it('Check-latest true, finds the latest version in the manifest', async () => {
const findSpy: jest.SpyInstance = jest.spyOn(tc, 'getManifestFromRepo');
findSpy.mockImplementation(() => <tc.IToolRelease[]>manifestData);
const getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput');
getBooleanInputSpy.mockImplementation(input => true);
const cnSpy: jest.SpyInstance = jest.spyOn(process.stdout, 'write');
cnSpy.mockImplementation(line => {
// uncomment to debug
// process.stderr.write('write:' + line + '\n');
});
const addPathSpy: jest.SpyInstance = jest.spyOn(core, 'addPath');
addPathSpy.mockImplementation(() => null);
const infoSpy: jest.SpyInstance = jest.spyOn(core, 'info');
infoSpy.mockImplementation(() => {});
const debugSpy: jest.SpyInstance = jest.spyOn(core, 'debug');
debugSpy.mockImplementation(() => {});
const pythonDir: string = path.join(toolDir, 'Python', '1.2.2', 'x64');
const expPath: string = path.join(toolDir, 'Python', '1.2.3', 'x64');
const installSpy: jest.SpyInstance = jest.spyOn(
installer,
'installCpythonFromRelease'
);
installSpy.mockImplementation(async () => {
await io.mkdirP(expPath);
fs.writeFileSync(`${expPath}.complete`, 'hello');
});
const tcFindSpy: jest.SpyInstance = jest.spyOn(tc, 'find');
tcFindSpy
.mockImplementationOnce(() => '')
.mockImplementationOnce(() => expPath);
await io.mkdirP(pythonDir);
await io.rmRF(path.join(toolDir, 'Python', '1.2.3'));
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.useCpythonVersion('1.2', 'x64', true, true);
expect(infoSpy).toHaveBeenCalledWith("Resolved as '1.2.3'");
expect(infoSpy).toHaveBeenCalledWith(
'Version 1.2.3 was not found in the local cache'
);
expect(infoSpy).toBeCalledWith(
'Version 1.2.3 is available for downloading'
);
expect(installSpy).toHaveBeenCalled();
expect(addPathSpy).toHaveBeenCalledWith(expPath);
await finder.useCpythonVersion('1.2.3-beta.2', 'x64', false, true);
expect(spyCoreAddPath).toHaveBeenCalled();
expect(spyCoreExportVariable).toHaveBeenCalledWith(
'pythonLocation',
expect.anything()
);
expect(spyCoreExportVariable).toHaveBeenCalledWith(
'PKG_CONFIG_PATH',
expect.anything()
);
}); });
it('Errors if Python is not installed', async () => { it('Errors if Python is not installed', async () => {
// This will throw if it doesn't find it in the cache and in the manifest (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; let thrown = false;
try { try {
await finder.useCpythonVersion('3.300000', 'x64'); await finder.useCpythonVersion('3.300000', 'x64', true, false);
} catch { } catch {
thrown = true; thrown = true;
} }
expect(thrown).toBeTruthy(); expect(thrown).toBeTruthy();
expect(spyCoreAddPath).not.toHaveBeenCalled();
expect(spyCoreExportVariable).not.toHaveBeenCalled();
}); });
}); });

View File

@ -4,6 +4,7 @@ import {HttpClient} from '@actions/http-client';
import * as ifm from '@actions/http-client/interfaces'; import * as ifm from '@actions/http-client/interfaces';
import * as tc from '@actions/tool-cache'; import * as tc from '@actions/tool-cache';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
import * as core from '@actions/core';
import * as path from 'path'; import * as path from 'path';
import * as installer from '../src/install-pypy'; import * as installer from '../src/install-pypy';
@ -51,6 +52,22 @@ describe('findRelease', () => {
download_url: `https://test.download.python.org/pypy/pypy3.6-v7.3.3-${extensionName}` download_url: `https://test.download.python.org/pypy/pypy3.6-v7.3.3-${extensionName}`
}; };
let getBooleanInputSpy: jest.SpyInstance;
let warningSpy: jest.SpyInstance;
let debugSpy: jest.SpyInstance;
let infoSpy: jest.SpyInstance;
beforeEach(() => {
infoSpy = jest.spyOn(core, 'info');
infoSpy.mockImplementation(() => {});
warningSpy = jest.spyOn(core, 'warning');
warningSpy.mockImplementation(() => null);
debugSpy = jest.spyOn(core, 'debug');
debugSpy.mockImplementation(() => null);
});
it("Python version is found, but PyPy version doesn't match", () => { it("Python version is found, but PyPy version doesn't match", () => {
const pythonVersion = '3.6'; const pythonVersion = '3.6';
const pypyVersion = '7.3.7'; const pypyVersion = '7.3.7';
@ -133,6 +150,10 @@ describe('findRelease', () => {
describe('installPyPy', () => { describe('installPyPy', () => {
let tcFind: jest.SpyInstance; let tcFind: jest.SpyInstance;
let getBooleanInputSpy: jest.SpyInstance;
let warningSpy: jest.SpyInstance;
let debugSpy: jest.SpyInstance;
let infoSpy: jest.SpyInstance;
let spyExtractZip: jest.SpyInstance; let spyExtractZip: jest.SpyInstance;
let spyExtractTar: jest.SpyInstance; let spyExtractTar: jest.SpyInstance;
let spyFsReadDir: jest.SpyInstance; let spyFsReadDir: jest.SpyInstance;
@ -158,6 +179,15 @@ describe('installPyPy', () => {
spyExtractTar = jest.spyOn(tc, 'extractTar'); spyExtractTar = jest.spyOn(tc, 'extractTar');
spyExtractTar.mockImplementation(() => tempDir); spyExtractTar.mockImplementation(() => tempDir);
infoSpy = jest.spyOn(core, 'info');
infoSpy.mockImplementation(() => {});
warningSpy = jest.spyOn(core, 'warning');
warningSpy.mockImplementation(() => null);
debugSpy = jest.spyOn(core, 'debug');
debugSpy.mockImplementation(() => null);
spyFsReadDir = jest.spyOn(fs, 'readdirSync'); spyFsReadDir = jest.spyOn(fs, 'readdirSync');
spyFsReadDir.mockImplementation(() => ['PyPyTest']); spyFsReadDir.mockImplementation(() => ['PyPyTest']);
@ -194,7 +224,7 @@ describe('installPyPy', () => {
it('throw if release is not found', async () => { it('throw if release is not found', async () => {
await expect( await expect(
installer.installPyPy('7.3.3', '3.6.17', architecture) installer.installPyPy('7.3.3', '3.6.17', architecture, undefined)
).rejects.toThrowError( ).rejects.toThrowError(
`PyPy version 3.6.17 (7.3.3) with arch ${architecture} not found` `PyPy version 3.6.17 (7.3.3) with arch ${architecture} not found`
); );
@ -214,7 +244,7 @@ describe('installPyPy', () => {
spyChmodSync.mockImplementation(() => undefined); spyChmodSync.mockImplementation(() => undefined);
await expect( await expect(
installer.installPyPy('7.3.x', '3.6.12', architecture) installer.installPyPy('7.3.x', '3.6.12', architecture, undefined)
).resolves.toEqual({ ).resolves.toEqual({
installDir: path.join(toolDir, 'PyPy', '3.6.12', architecture), installDir: path.join(toolDir, 'PyPy', '3.6.12', architecture),
resolvedPythonVersion: '3.6.12', resolvedPythonVersion: '3.6.12',

View File

@ -1,26 +1,35 @@
--- ---
name: 'Setup Python' name: "Setup Python"
description: 'Set up a specific version of Python and add the command-line tools to the PATH.' description: "Set up a specific version of Python and add the command-line tools to the PATH."
author: 'GitHub' author: "GitHub"
inputs: inputs:
python-version: python-version:
description: "Version range or exact version of a Python version to use, using SemVer's version range syntax." description: "Version range or exact version of Python or PyPy to use, using SemVer's version range syntax. Reads from .python-version if unset."
default: '3.x' python-version-file:
description: "File containing the Python version to use. Example: .python-version"
cache: cache:
description: 'Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry.' description: "Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry."
required: false required: false
architecture: architecture:
description: 'The target architecture (x86, x64) of the Python interpreter.' description: "The target architecture (x86, x64) of the Python or PyPy interpreter."
check-latest:
description: "Set this option if you want the action to check for the latest available version that satisfies the version spec."
default: false
token: token:
description: Used to pull python distributions from actions/python-versions. Since there's a default, this is typically not supplied by the user. 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 }} default: ${{ github.token }}
cache-dependency-path: cache-dependency-path:
description: 'Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies.' description: "Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies."
update-environment:
description: "Set this option if you want the action to update environment variables."
default: true
outputs: outputs:
python-version: python-version:
description: "The installed python version. Useful when given a version range as input." description: "The installed Python or PyPy version. Useful when given a version range as input."
cache-hit: cache-hit:
description: 'A boolean value to indicate a cache entry was found' description: "A boolean value to indicate a cache entry was found"
python-path:
description: "The absolute path to the Python or PyPy executable."
runs: runs:
using: 'node16' using: 'node16'
main: 'dist/setup/index.js' main: 'dist/setup/index.js'

54653
dist/cache-save/index.js vendored

File diff suppressed because one or more lines are too long

67435
dist/setup/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -45,8 +45,8 @@ We won't pursue the goal to provide wide customization of caching in the scope o
``` ```
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions/setup-python@v2 - uses: actions/setup-python@v4
with: with:
python-version: 3.9 python-version: 3.9
cache: pip cache: pip
@ -56,8 +56,8 @@ steps:
``` ```
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions/setup-python@v2 - uses: actions/setup-python@v4
with: with:
python-version: 3.9 python-version: 3.9
cache: pipenv cache: pipenv
@ -66,8 +66,8 @@ steps:
``` ```
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions/setup-python@v2 - uses: actions/setup-python@v4
with: with:
python-version: 3.9 python-version: 3.9
cache: pip cache: pip
@ -80,8 +80,8 @@ steps:
``` ```
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions/setup-python@v2 - uses: actions/setup-python@v4
with: with:
python-version: 3.9 python-version: 3.9
cache: pip cache: pip

476
docs/advanced-usage.md Normal file
View File

@ -0,0 +1,476 @@
# Advanced Usage
- [Using the python-version input](advanced-usage.md#using-the-python-version-input)
- [Specifying a Python version](advanced-usage.md#specifying-a-python-version)
- [Specifying a PyPy version](advanced-usage.md#specifying-a-pypy-version)
- [Matrix Testing](advanced-usage.md#matrix-testing)
- [Using the python-version-file input](advanced-usage.md#using-the-python-version-file-input)
- [Check latest version](advanced-usage.md#check-latest-version)
- [Caching packages](advanced-usage.md#caching-packages)
- [Outputs and environment variables](advanced-usage.md#outputs-and-environment-variables)
- [Outputs](advanced-usage.md#outputs)
- [Environment variables](advanced-usage.md#environment-variables)
- [Using update-environment flag](advanced-usage.md#using-update-environment-flag)
- [Available versions of Python and PyPy](advanced-usage.md#available-versions-of-python-and-pypy)
- [Python](advanced-usage.md#python)
- [PyPy](advanced-usage.md#pypy)
- [Hosted tool cache](advanced-usage.md#hosted-tool-cache)
- [Using `setup-python` with a self-hosted runner](advanced-usage.md#using-setup-python-with-a-self-hosted-runner)
- [Windows](advanced-usage.md#windows)
- [Linux](advanced-usage.md#linux)
- [macOS](advanced-usage.md#macos)
- [Using `setup-python` on GHES](advanced-usage.md#using-setup-python-on-ghes)
## Using the `python-version` input
### Specifying a Python version
If there is a specific version of Python that you need and you don't want to worry about any potential breaking changes due to patch updates (going from `3.7.5` to `3.7.6` for example), you should specify the **exact major, minor, and patch version** (such as `3.7.5`):
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.7.5'
- run: python my_script.py
```
- The only downside to this is that setup may take a little longer. If the exact version is not already installed on the runner due to more recent versions, the exact version will have to be downloaded.
- MSI installers are used on Windows for this, so runs will take a little longer to set up vs macOS and Linux.
You can specify **only a major and minor version** if you are okay with the most recent patch version being used:
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.7'
- run: python my_script.py
```
- There will be a single patch version already installed on each runner for every minor version of Python that is supported.
- The patch version that will be preinstalled, will generally be the latest and every time there is a new patch released, the older version that is preinstalled will be replaced.
- Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version of Python on the runner will be used.
You can specify the version with **prerelease tag** to download and set up an accurate pre-release version of Python:
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11.0-alpha.1'
- run: python my_script.py
```
It's also possible to use **x.y-dev syntax** to download and set up the latest patch version of Python, alpha and beta releases included. (for specified major & minor versions):
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11-dev'
- run: python my_script.py
```
You can also use several types of ranges that are specified in [semver](https://github.com/npm/node-semver#ranges), for instance:
- **[hyphen ranges](https://github.com/npm/node-semver#hyphen-ranges-xyz---abc)** to download and set up the latest available version of Python (includes both pre-release and stable versions):
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11.0-alpha - 3.11.0'
- run: python my_script.py
```
- **[x-ranges](https://github.com/npm/node-semver#x-ranges-12x-1x-12-)** to specify the latest stable version of Python (for specified major version):
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- run: python my_script.py
```
Please refer to the [Advanced range syntax section](https://github.com/npm/node-semver#advanced-range-syntax) of the [semver](https://github.com/npm/node-semver) to check other available range syntaxes.
### Specifying a PyPy version
The version of PyPy should be specified in the format `pypy<python_version>[-v<pypy_version>]` or `pypy-<python_version>[-v<pypy_version>]`.
The `-v<pypy_version>` parameter is optional and can be skipped. The latest PyPy version will be used in this case.
```
pypy3.8 or pypy-3.8 # the latest available version of PyPy that supports Python 3.8
pypy2.7 or pypy-2.7 # the latest available version of PyPy that supports Python 2.7
pypy3.7-v7.3.3 or pypy-3.7-v7.3.3 # Python 3.7 and PyPy 7.3.3
pypy3.7-v7.x or pypy-3.7-v7.x # Python 3.7 and the latest available PyPy 7.x
pypy3.7-v7.3.3rc1 or pypy-3.7-v7.3.3rc1 # Python 3.7 and preview version of PyPy
pypy3.7-nightly or pypy-3.7-nightly # Python 3.7 and nightly PyPy
```
Download and set up PyPy:
```yaml
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- 'pypy3.7' # the latest available version of PyPy that supports Python 3.7
- 'pypy3.7-v7.3.3' # Python 3.7 and PyPy 7.3.3
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: python my_script.py
```
More details on PyPy syntax can be found in the [Available versions of PyPy](#pypy) section.
### Matrix Testing
Using `setup-python` it's possible to use [matrix syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix) to install several versions of Python or PyPy:
```yaml
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '2.x', '3.x', 'pypy2.7', 'pypy3.7', 'pypy3.8' ]
name: Python ${{ matrix.python-version }} sample
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: python my_script.py
```
Exclude a specific Python version:
```yaml
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['2.7', '3.7', '3.8', '3.9', '3.10', 'pypy2.7', 'pypy3.8']
exclude:
- os: macos-latest
python-version: '3.8'
- os: windows-latest
python-version: '3.6'
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python --version
```
## Using the `python-version-file` input
`setup-python` action can read Python or PyPy version from a version file. `python-version-file` input is used for specifying the path to the version file. If the file that was supplied to `python-version-file` input doesn't exist, the action will fail with error.
>In case both `python-version` and `python-version-file` inputs are supplied, the `python-version-file` input will be ignored due to its lower priority.
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version-file: '.python-version' # Read python version from a file .python-version
- run: python my_script.py
```
## Check latest version
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 or PyPy` version is always used.
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 or PyPy` version will then be downloaded. Set `check-latest` to `true` if you want the most up-to-date `Python or PyPy` version to always be used.
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '3.7'
check-latest: true
- run: python my_script.py
```
> Setting `check-latest` to `true` has performance implications as downloading `Python or PyPy` versions is slower than using cached versions.
## Caching packages
**Caching pipenv dependencies:**
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pipenv'
- name: Install pipenv
run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python
- run: pipenv install
```
**Caching poetry dependencies:**
```yaml
steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'poetry'
- run: poetry install
- run: poetry run pytest
```
**Using a list of file paths to cache dependencies**
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pipenv'
cache-dependency-path: |
server/app/Pipfile.lock
__test__/app/Pipfile.lock
- name: Install pipenv
run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python
- run: pipenv install
```
**Using wildcard patterns to cache dependencies**
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'
cache-dependency-path: '**/requirements-dev.txt'
- run: pip install -r subdirectory/requirements-dev.txt
```
**Using a list of wildcard patterns to cache dependencies**
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
cache-dependency-path: |
**/setup.cfg
**/requirements*.txt
- run: pip install -e . -r subdirectory/requirements-dev.txt
```
# Outputs and environment variables
## Outputs
### `python-version`
Using **python-version** output it's possible to get the installed by action Python or PyPy version. This output is useful when the input `python-version` is given as a range (e.g. 3.8.0 - 3.10.0 ), but down in a workflow you need to operate with the exact installed version (e.g. 3.10.1).
```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
id: cp310
with:
python-version: "3.8.0 - 3.10.0"
- run: echo '${{ steps.cp310.outputs.python-version }}'
```
### `python-path`
**python-path** output is available with the absolute path of the Python or PyPy interpreter executable if you need it:
```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
id: cp310
with:
python-version: "3.10"
- run: pipx run --python '${{ steps.cp310.outputs.python-path }}' nox --version
```
### `cache-hit`
**cache-hit** output is available with a boolean value that indicates whether a cache hit occurred on the primary key:
```
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
id: cp310
with:
python-version: "3.8.0"
cache: "poetry"
- run: echo '${{ steps.cp310.outputs.cache-hit }}' # true if cache-hit occured on the primary key
```
## Environment variables
These environment variables become available after setup-python action execution:
| **Env.variable** | **Description** |
| ----------- | ----------- |
| pythonLocation |Contains the absolute path to the folder where the requested version of Python or PyPy is installed|
| Python_ROOT_DIR | https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython |
| Python2_ROOT_DIR |https://cmake.org/cmake/help/latest/module/FindPython2.html#module:FindPython2|
| Python3_ROOT_DIR |https://cmake.org/cmake/help/latest/module/FindPython2.html#module:FindPython3|
## Using `update-environment` flag
The `update-environment` flag defaults to `true`.
With this setting, the action will add/update environment variables (e.g. `PATH`, `PKG_CONFIG_PATH`, `pythonLocation`) for Python or PyPy to just work out of the box.
If `update-environment` is set to `false`, the action will not add/update environment variables.
This can prove useful if you want the only side-effect to be to ensure Python or PyPy is installed and rely on the `python-path` output to run executable.
Such a requirement on side-effect could be because you don't want your composite action messing with your user's workflows.
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
id: cp310
with:
python-version: '3.10'
update-environment: false
- run: ${{ steps.cp310.outputs.python-path }} my_script.py
```
## Available versions of Python and PyPy
### Python
`setup-python` is able to configure **Python** from two sources:
- Preinstalled versions of Python in the tool cache on GitHub-hosted runners.
- For detailed information regarding the available versions of Python that are installed, see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software).
- For every minor version of Python, expect only the latest patch to be preinstalled.
- If `3.8.1` is installed for example, and `3.8.2` is released, expect `3.8.1` to be removed and replaced by `3.8.2` in the tool cache.
- If the exact patch version doesn't matter to you, specifying just the major and minor versions will get you the latest preinstalled patch version. In the previous example, the version spec `3.8` will use the `3.8.2` Python version found in the cache.
- Use `-dev` instead of a patch number (e.g., `3.11-dev`) to install the latest patch version release for a given minor version, *alpha and beta releases included*.
- Downloadable Python versions from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)).
- All available versions are listed in the [version-manifest.json](https://github.com/actions/python-versions/blob/main/versions-manifest.json) file.
- If there is a specific version of Python that is not available, you can open an issue here
>**Note:** Python versions used in this action are generated in the [python-versions](https://github.com/actions/python-versions) repository. For macOS and Ubuntu images, python versions are built from the source code. For Windows, the python-versions repository uses installation executable. For more information please refer to the [python-versions](https://github.com/actions/python-versions) repository.
### PyPy
`setup-python` is able to configure **PyPy** from two sources:
- Preinstalled versions of PyPy in the tool cache on GitHub-hosted runners
- For detailed information regarding the available versions of PyPy that are installed, see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software).
- For the latest PyPy release, all versions of Python are cached.
- Cache is updated with a 1-2 week delay. If you specify the PyPy version as `pypy3.7` or `pypy-3.7`, the cached version will be used although a newer version is available. If you need to start using the recently released version right after release, you should specify the exact PyPy version using `pypy3.7-v7.3.3` or `pypy-3.7-v7.3.3`.
- Downloadable PyPy versions from the [official PyPy site](https://downloads.python.org/pypy/).
- All available versions that we can download are listed in [versions.json](https://downloads.python.org/pypy/versions.json) file.
- PyPy < 7.3.3 are not available to install on-flight.
- If some versions are not available, you can open an issue in https://foss.heptapod.net/pypy/pypy/
## Hosted tool cache
GitHub hosted runners have a tool cache that comes with a few versions of Python + PyPy already installed. This tool cache helps speed up runs and tool setup by not requiring any new downloads. There is an environment variable called `RUNNER_TOOL_CACHE` on each runner that describes the location of the tool cache with Python and PyPy installed. `setup-python` works by taking a specific version of Python or PyPy from this tool cache and adding it to PATH.
|| Location |
|------|-------|
|**Tool cache Directory** |`RUNNER_TOOL_CACHE`|
|**Python tool cache**|`RUNNER_TOOL_CACHE/Python/*`|
|**PyPy tool cache**|`RUNNER_TOOL_CACHE/PyPy/*`|
GitHub virtual environments are set up in [actions/virtual-environments](https://github.com/actions/virtual-environments). During the setup, the available versions of Python and PyPy are automatically downloaded, set up and documented.
- Tool cache setup for Ubuntu: [Install-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/linux/scripts/installers/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/linux/scripts/installers/Configure-Toolset.ps1)
- Tool cache setup for Windows: [Install-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/win/scripts/Installers/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/virtual-environments/blob/main/images/win/scripts/Installers/Configure-Toolset.ps1)
## Using `setup-python` with a self-hosted runner
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` may 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.
### Windows
- Your runner needs to be running with administrator privileges so that the appropriate directories and files can be set up when downloading and installing a new version of Python for the first time.
- If your runner is configured as a service, make sure the account that is running the service has the appropriate write permissions so that Python can get installed. The default `NT AUTHORITY\NETWORK SERVICE` should be sufficient.
- You need `7zip` installed and added to your `PATH` so that the downloaded versions of Python files can be extracted properly during the first-time setup.
- MSI installers are used when setting up Python on Windows. A word of caution as MSI installers update registry settings.
- The 3.8 MSI installer for Windows will not let you install another 3.8 version of Python. If `setup-python` fails for a 3.8 version of Python, make sure any previously installed versions are removed by going to "Apps & Features" in the Settings app.
> By default runner downloads and installs tools into the folder set up by `RUNNER_TOOL_CACHE` environment variable. The environment variable called `AGENT_TOOLSDIRECTORY` can be set to change this location for Windows self-hosted runners.
>If you are experiencing problems while configuring Python on your self-hosted runner, turn on [step debugging](https://github.com/actions/toolkit/blob/main/docs/action-debugging.md#step-debug-logs) to see additional logs.
### Linux
By default runner downloads and installs tools into the folder set up by `RUNNER_TOOL_CACHE` environment variable. The environment variable called `AGENT_TOOLSDIRECTORY` can be set to change this location for Linux self-hosted runners:
- In the same shell that your runner is using, type `export AGENT_TOOLSDIRECTORY=/path/to/folder`.
- More permanent way of setting the environment variable is to create an `.env` file in the same directory as your runner and to add `AGENT_TOOLSDIRECTORY=/path/to/folder`. This ensures the variable is always set if your runner is configured as a service.
If you're using a non-default tool cache directory be sure that the user starting the runner has write permission to the new tool cache directory. To check the current user and group that the runner belongs type `ls -l` inside the runner's root directory.
The runner can be granted write access to any directory using a few techniques:
- The user starting the runner is the owner, and the owner has write permission.
- The user starting the runner is in the owning group, and the owning group has write permission.
- All users have write permission.
One quick way to grant access is to change the user and group of the non-default tool cache folder to be the same as the runners using `chown`:
`sudo chown runner-user:runner-group /path/to/folder`.
> If your runner is configured as a service and you run into problems, make sure the user that the service is running as is correct. For more information, you can [check the status of your self-hosted runner](https://docs.github.com/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service#checking-the-status-of-the-service).
### macOS
The Python packages for macOS that are downloaded from `actions/python-versions` are originally compiled from the source in `/Users/runner/hostedtoolcache`. Due to the fixed shared library path, these Python packages are non-relocatable and require to be installed only in `/Users/runner/hostedtoolcache`. Before the use of `setup-python` on the macOS self-hosted runner:
- Create a directory called `/Users/runner/hostedtoolcache`
- Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access
You can check the current user and group that the runner belongs to by typing `ls -l` inside the runner's root directory.
The runner can be granted write access to the `/Users/runner/hostedtoolcache` directory using a few techniques:
- The user starting the runner is the owner, and the owner has write permission
- The user starting the runner is in the owning group, and the owning group has write permission
- All users have write permission.
One quick way to grant access is to change the user and group of `/Users/runner/hostedtoolcache` to be the same as the runners using `chown`:
`sudo chown runner-user:runner-group /Users/runner/hostedtoolcache`
> If your runner is configured as a service and you run into problems, make sure the user that the service is running as is correct. For more information, you can [check the status of your self-hosted runner](https://docs.github.com/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service#checking-the-status-of-the-service).
## Using `setup-python` on GHES
`setup-python` comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading Python distributions, `setup-python` downloads distributions from [`actions/python-versions`](https://github.com/actions/python-versions) on github.com (outside of the appliance). These calls to `actions/python-versions` are made via unauthenticated requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting). If more requests are made within the time frame, then you will start to see rate-limit errors during downloading that looks like: `##[error]API rate limit exceeded for...`.
To avoid hitting rate-limit problems, we recommend [setting up your own runner tool cache](https://docs.github.com/en/enterprise-server@2.22/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access#about-the-included-setup-actions-and-the-runner-tool-cache).

10423
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "setup-python", "name": "setup-python",
"version": "3.1.1", "version": "4.0.0",
"private": true, "private": true,
"description": "Setup python action", "description": "Setup python action",
"main": "dist/index.js", "main": "dist/index.js",
@ -9,7 +9,7 @@
"format": "prettier --write \"{,!(node_modules)/**/}*.ts\"", "format": "prettier --write \"{,!(node_modules)/**/}*.ts\"",
"format-check": "prettier --check \"{,!(node_modules)/**/}*.ts\"", "format-check": "prettier --check \"{,!(node_modules)/**/}*.ts\"",
"release": "ncc build -o dist/setup src/setup-python.ts && ncc build -o dist/cache-save src/cache-save.ts && git add -f dist/", "release": "ncc build -o dist/setup src/setup-python.ts && ncc build -o dist/cache-save src/cache-save.ts && git add -f dist/",
"test": "jest" "test": "jest --coverage"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -23,8 +23,8 @@
"author": "GitHub", "author": "GitHub",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/cache": "^2.0.2", "@actions/cache": "^3.0.0",
"@actions/core": "^1.2.3", "@actions/core": "^1.7.0",
"@actions/exec": "^1.1.0", "@actions/exec": "^1.1.0",
"@actions/glob": "^0.2.0", "@actions/glob": "^0.2.0",
"@actions/io": "^1.0.2", "@actions/io": "^1.0.2",
@ -35,7 +35,7 @@
"@types/jest": "^27.0.2", "@types/jest": "^27.0.2",
"@types/node": "^16.11.25", "@types/node": "^16.11.25",
"@types/semver": "^7.1.0", "@types/semver": "^7.1.0",
"@zeit/ncc": "^0.22.0", "@vercel/ncc": "^0.33.4",
"husky": "^7.0.2", "husky": "^7.0.2",
"jest": "^27.2.5", "jest": "^27.2.5",
"jest-circus": "^27.2.5", "jest-circus": "^27.2.5",

View File

@ -7,7 +7,7 @@ import * as path from 'path';
import os from 'os'; import os from 'os';
import CacheDistributor from './cache-distributor'; import CacheDistributor from './cache-distributor';
import {IS_WINDOWS} from '../utils'; import {getLinuxOSReleaseInfo, IS_LINUX, IS_WINDOWS} from '../utils';
class PipCache extends CacheDistributor { class PipCache extends CacheDistributor {
constructor( constructor(
@ -57,8 +57,17 @@ class PipCache extends CacheDistributor {
protected async computeKeys() { protected async computeKeys() {
const hash = await glob.hashFiles(this.cacheDependencyPath); const hash = await glob.hashFiles(this.cacheDependencyPath);
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`; let primaryKey = '';
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`; let restoreKey = '';
if (IS_LINUX) {
const osRelease = await getLinuxOSReleaseInfo();
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}`;
} else {
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;
}
return { return {
primaryKey, primaryKey,

View File

@ -1,9 +1,11 @@
import * as glob from '@actions/glob'; import * as glob from '@actions/glob';
import * as os from 'os'; import * as io from '@actions/io';
import * as path from 'path'; import * as path from 'path';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
import * as core from '@actions/core';
import CacheDistributor from './cache-distributor'; import CacheDistributor from './cache-distributor';
import {logWarning} from '../utils';
class PoetryCache extends CacheDistributor { class PoetryCache extends CacheDistributor {
constructor( constructor(
@ -28,6 +30,26 @@ class PoetryCache extends CacheDistributor {
paths.push(path.join(process.cwd(), '.venv')); paths.push(path.join(process.cwd(), '.venv'));
} }
const pythonLocation = await io.which('python');
if (pythonLocation) {
core.debug(`pythonLocation is ${pythonLocation}`);
const {
exitCode,
stderr
} = await exec.getExecOutput(
`poetry env use ${pythonLocation}`,
undefined,
{ignoreReturnCode: true}
);
if (exitCode) {
logWarning(stderr);
}
} else {
logWarning('python binaries were not found in PATH');
}
return paths; return paths;
} }
@ -58,7 +80,7 @@ class PoetryCache extends CacheDistributor {
const config: any = {}; const config: any = {};
for (let line of lines) { for (let line of lines) {
line = line.replace(/#.*$/, ''); line = line.replace(/#.*$/gm, '');
const [key, value] = line.split('=').map(part => part.trim()); const [key, value] = line.split('=').map(part => part.trim());

View File

@ -43,17 +43,11 @@ async function saveCache(packageManager: string) {
return; return;
} }
try { const cacheId = await cache.saveCache(cachePaths, primaryKey);
await cache.saveCache(cachePaths, primaryKey); if (cacheId == -1) {
core.info(`Cache saved with the key: ${primaryKey}`); return;
} catch (error) {
const err = error as Error;
if (err.name === cache.ReserveCacheError.name) {
core.info(err.message);
} else {
throw error;
}
} }
core.info(`Cache saved with the key: ${primaryKey}`);
} }
function isCacheDirectoryExists(cacheDirectory: string[]) { function isCacheDirectoryExists(cacheDirectory: string[]) {

View File

@ -6,7 +6,8 @@ import {
validateVersion, validateVersion,
getPyPyVersionFromPath, getPyPyVersionFromPath,
readExactPyPyVersionFile, readExactPyPyVersionFile,
validatePythonVersionFormatForPyPy validatePythonVersionFormatForPyPy,
IPyPyManifestRelease
} from './utils'; } from './utils';
import * as semver from 'semver'; import * as semver from 'semver';
@ -20,14 +21,41 @@ interface IPyPyVersionSpec {
export async function findPyPyVersion( export async function findPyPyVersion(
versionSpec: string, versionSpec: string,
architecture: string architecture: string,
updateEnvironment: boolean,
checkLatest: boolean
): Promise<{resolvedPyPyVersion: string; resolvedPythonVersion: string}> { ): Promise<{resolvedPyPyVersion: string; resolvedPythonVersion: string}> {
let resolvedPyPyVersion = ''; let resolvedPyPyVersion = '';
let resolvedPythonVersion = ''; let resolvedPythonVersion = '';
let installDir: string | null; let installDir: string | null;
let releases: IPyPyManifestRelease[] | undefined;
const pypyVersionSpec = parsePyPyVersion(versionSpec); const pypyVersionSpec = parsePyPyVersion(versionSpec);
if (checkLatest) {
releases = await pypyInstall.getAvailablePyPyVersions();
if (releases && releases.length > 0) {
const releaseData = pypyInstall.findRelease(
releases,
pypyVersionSpec.pythonVersion,
pypyVersionSpec.pypyVersion,
architecture
);
if (releaseData) {
core.info(
`Resolved as PyPy ${releaseData.resolvedPyPyVersion} with Python (${releaseData.resolvedPythonVersion})`
);
pypyVersionSpec.pythonVersion = releaseData.resolvedPythonVersion;
pypyVersionSpec.pypyVersion = releaseData.resolvedPyPyVersion;
} else {
core.info(
`Failed to resolve PyPy ${pypyVersionSpec.pypyVersion} with Python (${pypyVersionSpec.pythonVersion}) from manifest`
);
}
}
}
({installDir, resolvedPythonVersion, resolvedPyPyVersion} = findPyPyToolCache( ({installDir, resolvedPythonVersion, resolvedPyPyVersion} = findPyPyToolCache(
pypyVersionSpec.pythonVersion, pypyVersionSpec.pythonVersion,
pypyVersionSpec.pypyVersion, pypyVersionSpec.pypyVersion,
@ -42,17 +70,33 @@ export async function findPyPyVersion(
} = await pypyInstall.installPyPy( } = await pypyInstall.installPyPy(
pypyVersionSpec.pypyVersion, pypyVersionSpec.pypyVersion,
pypyVersionSpec.pythonVersion, pypyVersionSpec.pythonVersion,
architecture architecture,
releases
)); ));
} }
const pipDir = IS_WINDOWS ? 'Scripts' : 'bin'; const pipDir = IS_WINDOWS ? 'Scripts' : 'bin';
const _binDir = path.join(installDir, pipDir); const _binDir = path.join(installDir, pipDir);
const binaryExtension = IS_WINDOWS ? '.exe' : '';
const pythonPath = path.join(
IS_WINDOWS ? installDir : _binDir,
`python${binaryExtension}`
);
const pythonLocation = pypyInstall.getPyPyBinaryPath(installDir); const pythonLocation = pypyInstall.getPyPyBinaryPath(installDir);
core.exportVariable('pythonLocation', pythonLocation); if (updateEnvironment) {
core.addPath(pythonLocation); core.exportVariable('pythonLocation', installDir);
core.addPath(_binDir); // https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython
core.exportVariable('Python_ROOT_DIR', installDir);
// https://cmake.org/cmake/help/latest/module/FindPython2.html#module:FindPython2
core.exportVariable('Python2_ROOT_DIR', installDir);
// https://cmake.org/cmake/help/latest/module/FindPython3.html#module:FindPython3
core.exportVariable('Python3_ROOT_DIR', installDir);
core.exportVariable('PKG_CONFIG_PATH', pythonLocation + '/lib/pkgconfig');
core.addPath(pythonLocation);
core.addPath(_binDir);
}
core.setOutput('python-version', 'pypy' + resolvedPyPyVersion.trim()); core.setOutput('python-version', 'pypy' + resolvedPyPyVersion.trim());
core.setOutput('python-path', pythonPath);
return {resolvedPyPyVersion, resolvedPythonVersion}; return {resolvedPyPyVersion, resolvedPythonVersion};
} }
@ -97,9 +141,14 @@ export function findPyPyToolCache(
export function parsePyPyVersion(versionSpec: string): IPyPyVersionSpec { export function parsePyPyVersion(versionSpec: string): IPyPyVersionSpec {
const versions = versionSpec.split('-').filter(item => !!item); const versions = versionSpec.split('-').filter(item => !!item);
if (/^(pypy)(.+)/.test(versions[0])) {
let pythonVersion = versions[0].replace('pypy', '');
versions.splice(0, 1, 'pypy', pythonVersion);
}
if (versions.length < 2 || versions[0] != 'pypy') { if (versions.length < 2 || versions[0] != 'pypy') {
throw new Error( throw new Error(
"Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy-<python-version>'. See README for examples and documentation." "Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy<python-version>' or 'pypy-<python-version>'. See README for examples and documentation."
); );
} }

View File

@ -32,12 +32,35 @@ function binDir(installDir: string): string {
export async function useCpythonVersion( export async function useCpythonVersion(
version: string, version: string,
architecture: string architecture: string,
updateEnvironment: boolean,
checkLatest: boolean
): Promise<InstalledVersion> { ): Promise<InstalledVersion> {
let manifest: tc.IToolRelease[] | null = null;
const desugaredVersionSpec = desugarDevVersion(version); const desugaredVersionSpec = desugarDevVersion(version);
const semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec); let semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec);
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`); core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
if (checkLatest) {
manifest = await installer.getManifest();
const resolvedVersion = (
await installer.findReleaseFromManifest(
semanticVersionSpec,
architecture,
manifest
)
)?.version;
if (resolvedVersion) {
semanticVersionSpec = resolvedVersion;
core.info(`Resolved as '${semanticVersionSpec}'`);
} else {
core.info(
`Failed to resolve version ${semanticVersionSpec} from manifest`
);
}
}
let installDir: string | null = tc.find( let installDir: string | null = tc.find(
'Python', 'Python',
semanticVersionSpec, semanticVersionSpec,
@ -49,7 +72,8 @@ export async function useCpythonVersion(
); );
const foundRelease = await installer.findReleaseFromManifest( const foundRelease = await installer.findReleaseFromManifest(
semanticVersionSpec, semanticVersionSpec,
architecture architecture,
manifest
); );
if (foundRelease && foundRelease.files && foundRelease.files.length > 0) { if (foundRelease && foundRelease.files && foundRelease.files.length > 0) {
@ -69,54 +93,67 @@ export async function useCpythonVersion(
); );
} }
core.exportVariable('pythonLocation', installDir); const _binDir = binDir(installDir);
const binaryExtension = IS_WINDOWS ? '.exe' : '';
const pythonPath = path.join(
IS_WINDOWS ? installDir : _binDir,
`python${binaryExtension}`
);
if (updateEnvironment) {
core.exportVariable('pythonLocation', installDir);
core.exportVariable('PKG_CONFIG_PATH', installDir + '/lib/pkgconfig');
core.exportVariable('pythonLocation', installDir);
// https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython
core.exportVariable('Python_ROOT_DIR', installDir);
// https://cmake.org/cmake/help/latest/module/FindPython2.html#module:FindPython2
core.exportVariable('Python2_ROOT_DIR', installDir);
// https://cmake.org/cmake/help/latest/module/FindPython3.html#module:FindPython3
core.exportVariable('Python3_ROOT_DIR', installDir);
core.exportVariable('PKG_CONFIG_PATH', installDir + '/lib/pkgconfig');
if (IS_LINUX) { if (IS_LINUX) {
const libPath = process.env.LD_LIBRARY_PATH const libPath = process.env.LD_LIBRARY_PATH
? `:${process.env.LD_LIBRARY_PATH}` ? `:${process.env.LD_LIBRARY_PATH}`
: ''; : '';
const pyLibPath = path.join(installDir, 'lib'); const pyLibPath = path.join(installDir, 'lib');
if (!libPath.split(':').includes(pyLibPath)) { if (!libPath.split(':').includes(pyLibPath)) {
core.exportVariable('LD_LIBRARY_PATH', pyLibPath + libPath); core.exportVariable('LD_LIBRARY_PATH', pyLibPath + libPath);
}
} }
core.addPath(installDir);
core.addPath(_binDir);
if (IS_WINDOWS) {
// Add --user directory
// `installDir` from tool cache should look like $RUNNER_TOOL_CACHE/Python/<semantic version>/x64/
// So if `findLocalTool` succeeded above, we must have a conformant `installDir`
const version = path.basename(path.dirname(installDir));
const major = semver.major(version);
const minor = semver.minor(version);
const userScriptsDir = path.join(
process.env['APPDATA'] || '',
'Python',
`Python${major}${minor}`,
'Scripts'
);
core.addPath(userScriptsDir);
}
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
} }
core.addPath(installDir);
core.addPath(binDir(installDir));
if (IS_WINDOWS) {
// Add --user directory
// `installDir` from tool cache should look like $RUNNER_TOOL_CACHE/Python/<semantic version>/x64/
// So if `findLocalTool` succeeded above, we must have a conformant `installDir`
const version = path.basename(path.dirname(installDir));
const major = semver.major(version);
const minor = semver.minor(version);
const userScriptsDir = path.join(
process.env['APPDATA'] || '',
'Python',
`Python${major}${minor}`,
'Scripts'
);
core.addPath(userScriptsDir);
}
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
const installed = versionFromPath(installDir); const installed = versionFromPath(installDir);
core.setOutput('python-version', installed); core.setOutput('python-version', installed);
core.setOutput('python-path', pythonPath);
return {impl: 'CPython', version: installed}; return {impl: 'CPython', version: installed};
} }
/** Convert versions like `3.8-dev` to a version like `>= 3.8.0-a0`. */ /** Convert versions like `3.8-dev` to a version like `~3.8.0-0`. */
function desugarDevVersion(versionSpec: string) { function desugarDevVersion(versionSpec: string) {
if (versionSpec.endsWith('-dev')) { const devVersion = /^(\d+)\.(\d+)-dev$/;
const versionRoot = versionSpec.slice(0, -'-dev'.length); return versionSpec.replace(devVersion, '~$1.$2.0-0');
return `>= ${versionRoot}.0-a0`;
} else {
return versionSpec;
}
} }
/** Extracts python version from install path from hosted tool cache as described in README.md */ /** Extracts python version from install path from hosted tool cache as described in README.md */

View File

@ -19,11 +19,13 @@ import {
export async function installPyPy( export async function installPyPy(
pypyVersion: string, pypyVersion: string,
pythonVersion: string, pythonVersion: string,
architecture: string architecture: string,
releases: IPyPyManifestRelease[] | undefined
) { ) {
let downloadDir; let downloadDir;
const releases = await getAvailablePyPyVersions(); releases = releases ?? (await getAvailablePyPyVersions());
if (!releases || releases.length === 0) { if (!releases || releases.length === 0) {
throw new Error('No release was found in PyPy version.json'); throw new Error('No release was found in PyPy version.json');
} }
@ -78,7 +80,7 @@ export async function installPyPy(
return {installDir, resolvedPythonVersion, resolvedPyPyVersion}; return {installDir, resolvedPythonVersion, resolvedPyPyVersion};
} }
async function getAvailablePyPyVersions() { export async function getAvailablePyPyVersions() {
const url = 'https://downloads.python.org/pypy/versions.json'; const url = 'https://downloads.python.org/pypy/versions.json';
const http: httpm.HttpClient = new httpm.HttpClient('tool-cache'); const http: httpm.HttpClient = new httpm.HttpClient('tool-cache');
@ -98,7 +100,9 @@ async function createPyPySymlink(
) { ) {
const version = semver.coerce(pythonVersion)!; const version = semver.coerce(pythonVersion)!;
const pythonBinaryPostfix = semver.major(version); const pythonBinaryPostfix = semver.major(version);
const pythonMinor = semver.minor(version);
const pypyBinaryPostfix = pythonBinaryPostfix === 2 ? '' : '3'; const pypyBinaryPostfix = pythonBinaryPostfix === 2 ? '' : '3';
const pypyMajorMinorBinaryPostfix = `${pythonBinaryPostfix}.${pythonMinor}`;
let binaryExtension = IS_WINDOWS ? '.exe' : ''; let binaryExtension = IS_WINDOWS ? '.exe' : '';
core.info('Creating symlinks...'); core.info('Creating symlinks...');
@ -115,6 +119,13 @@ async function createPyPySymlink(
`python${binaryExtension}`, `python${binaryExtension}`,
true true
); );
createSymlinkInFolder(
pypyBinaryPath,
`pypy${pypyBinaryPostfix}${binaryExtension}`,
`pypy${pypyMajorMinorBinaryPostfix}${binaryExtension}`,
true
);
} }
async function installPip(pythonLocation: string) { async function installPip(pythonLocation: string) {

View File

@ -14,20 +14,33 @@ export const MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_O
export async function findReleaseFromManifest( export async function findReleaseFromManifest(
semanticVersionSpec: string, semanticVersionSpec: string,
architecture: string architecture: string,
manifest: tc.IToolRelease[] | null
): Promise<tc.IToolRelease | undefined> { ): Promise<tc.IToolRelease | undefined> {
const manifest: tc.IToolRelease[] = await tc.getManifestFromRepo( if (!manifest) {
MANIFEST_REPO_OWNER, manifest = await getManifest();
MANIFEST_REPO_NAME, }
AUTH,
MANIFEST_REPO_BRANCH const foundRelease = await tc.findFromManifest(
);
return await tc.findFromManifest(
semanticVersionSpec, semanticVersionSpec,
false, false,
manifest, manifest,
architecture architecture
); );
return foundRelease;
}
export function getManifest(): Promise<tc.IToolRelease[]> {
core.debug(
`Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}`
);
return tc.getManifestFromRepo(
MANIFEST_REPO_OWNER,
MANIFEST_REPO_NAME,
AUTH,
MANIFEST_REPO_BRANCH
);
} }
async function installPython(workingDirectory: string) { async function installPython(workingDirectory: string) {

View File

@ -3,11 +3,12 @@ import * as finder from './find-python';
import * as finderPyPy from './find-pypy'; import * as finderPyPy from './find-pypy';
import * as path from 'path'; import * as path from 'path';
import * as os from 'os'; import * as os from 'os';
import fs from 'fs';
import {getCacheDistributor} from './cache-distributions/cache-factory'; import {getCacheDistributor} from './cache-distributions/cache-factory';
import {isCacheFeatureAvailable} from './utils'; import {isCacheFeatureAvailable, logWarning, IS_MAC} from './utils';
function isPyPyVersion(versionSpec: string) { function isPyPyVersion(versionSpec: string) {
return versionSpec.startsWith('pypy-'); return versionSpec.startsWith('pypy');
} }
async function cacheDependencies(cache: string, pythonVersion: string) { async function cacheDependencies(cache: string, pythonVersion: string) {
@ -21,33 +22,96 @@ async function cacheDependencies(cache: string, pythonVersion: string) {
await cacheDistributor.restoreCache(); await cacheDistributor.restoreCache();
} }
function resolveVersionInput(): string {
let version = core.getInput('python-version');
let versionFile = core.getInput('python-version-file');
if (version && versionFile) {
core.warning(
'Both python-version and python-version-file inputs are specified, only python-version will be used.'
);
}
if (version) {
return version;
}
if (versionFile) {
if (!fs.existsSync(versionFile)) {
throw new Error(
`The specified python version file at: ${versionFile} doesn't exist.`
);
}
version = fs.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
return version;
}
logWarning(
"Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '.python-version' file."
);
versionFile = '.python-version';
if (fs.existsSync(versionFile)) {
version = fs.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
return version;
}
logWarning(`${versionFile} doesn't exist.`);
return version;
}
async function run() { async function run() {
if (IS_MAC) {
process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache';
}
if (process.env.AGENT_TOOLSDIRECTORY?.trim()) {
process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY'];
}
core.debug(
`Python is expected to be installed into ${process.env['RUNNER_TOOL_CACHE']}`
);
try { try {
const version = core.getInput('python-version'); const version = resolveVersionInput();
const checkLatest = core.getBooleanInput('check-latest');
if (version) { if (version) {
let pythonVersion: string; let pythonVersion: string;
const arch: string = core.getInput('architecture') || os.arch(); const arch: string = core.getInput('architecture') || os.arch();
const updateEnvironment = core.getBooleanInput('update-environment');
if (isPyPyVersion(version)) { if (isPyPyVersion(version)) {
const installed = await finderPyPy.findPyPyVersion(version, arch); const installed = await finderPyPy.findPyPyVersion(
version,
arch,
updateEnvironment,
checkLatest
);
pythonVersion = `${installed.resolvedPyPyVersion}-${installed.resolvedPythonVersion}`; pythonVersion = `${installed.resolvedPyPyVersion}-${installed.resolvedPythonVersion}`;
core.info( core.info(
`Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})` `Successfully set up PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`
); );
} else { } else {
if (version.trim().startsWith('2')) { const installed = await finder.useCpythonVersion(
core.warning( version,
'The support for python 2.7 will be removed on June 19. Related issue: https://github.com/actions/setup-python/issues/672' arch,
); updateEnvironment,
} checkLatest
const installed = await finder.useCpythonVersion(version, arch); );
pythonVersion = installed.version; pythonVersion = installed.version;
core.info(`Successfully setup ${installed.impl} (${pythonVersion})`); core.info(`Successfully set up ${installed.impl} (${pythonVersion})`);
} }
const cache = core.getInput('cache'); const cache = core.getInput('cache');
if (cache && isCacheFeatureAvailable()) { if (cache && isCacheFeatureAvailable()) {
await cacheDependencies(cache, pythonVersion); await cacheDependencies(cache, pythonVersion);
} }
} else {
core.warning(
'The `python-version` input is not set. The version of Python currently in `PATH` will be used.'
);
} }
const matchersPath = path.join(__dirname, '../..', '.github'); const matchersPath = path.join(__dirname, '../..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`); core.info(`##[add-matcher]${path.join(matchersPath, 'python.json')}`);

View File

@ -3,9 +3,11 @@ import * as core from '@actions/core';
import fs from 'fs'; import fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import * as semver from 'semver'; import * as semver from 'semver';
import * as exec from '@actions/exec';
export const IS_WINDOWS = process.platform === 'win32'; export const IS_WINDOWS = process.platform === 'win32';
export const IS_LINUX = process.platform === 'linux'; export const IS_LINUX = process.platform === 'linux';
export const IS_MAC = process.platform === 'darwin';
export const WINDOWS_ARCHS = ['x86', 'x64']; export const WINDOWS_ARCHS = ['x86', 'x64'];
export const WINDOWS_PLATFORMS = ['win32', 'win64']; export const WINDOWS_PLATFORMS = ['win32', 'win64'];
const PYPY_VERSION_FILE = 'PYPY_VERSION'; const PYPY_VERSION_FILE = 'PYPY_VERSION';
@ -119,3 +121,24 @@ export function isCacheFeatureAvailable(): boolean {
return true; return true;
} }
export async function getLinuxOSReleaseInfo() {
const {stdout, stderr, exitCode} = await exec.getExecOutput(
'lsb_release',
['-i', '-r', '-s'],
{
silent: true
}
);
const [osRelease, osVersion] = stdout.trim().split('\n');
core.debug(`OS Release: ${osRelease}, Version: ${osVersion}`);
return `${osVersion}-${osRelease}`;
}
export function logWarning(message: string): void {
const warningPrefix = '[warning]';
core.info(`${warningPrefix}${message}`);
}