forked from getsentry/action-setup-venv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
70 lines (60 loc) · 2.53 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: 'venv setup'
description: 'configures venv, python and caches'
inputs:
python-version:
description: "Version range or exact version of Python or PyPy to use, using SemVer's version range syntax."
cache-dependency-path:
description: "Requirement files to install. Can be a glob pattern."
default: '**/requirements*.txt'
venv-dir:
default: '.venv'
install-cmd:
description: 'Command to install python dependencies.'
outputs:
cache-hit:
description: "A boolean value to indicate if a cache was restored"
value: ${{ steps.cache-venv.outputs.cache-hit }}
runs:
using: 'composite'
steps:
- uses: thebrowsercompany/check-python-exists@7a9d28cb86e2aae6d6ef75af09b4bb14fcd03ff1
id: setup-python
with:
python-version: ${{ inputs.python-version }}
is-self-hosted: ${{ !startsWith(runner.name, 'GitHub Actions') }}
- name: SHA the install command
id: install-cmd-sha
shell: bash
# macOS doesn't include shasum256 and Windows doesn't include shasum, so
# use python.
run: |
CMD_HASH="$(echo '${{ inputs.install-cmd }}' | python3 -c 'import hashlib,sys;print(hashlib.sha256(sys.stdin.buffer.read()).hexdigest())')"
echo -n "install-cmd-sha=$CMD_HASH" >> $GITHUB_OUTPUT
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
id: cache-venv
with:
path: ${{ inputs.venv-dir }}
key: setup-venv-${{ runner.os }}-py-${{ steps.setup-python.outputs.python-version }}-${{ steps.setup-python.outputs.python-path }}-${{ hashFiles(inputs.cache-dependency-path) }}-${{ steps.install-cmd-sha.outputs.install-cmd-sha }}
- run: python${{ steps.setup-python.outputs.python-version }} -m venv ${{ inputs.venv-dir }}
if: steps.cache-venv.outputs.cache-hit != 'true'
shell: bash
- name: venv save env (posix)
if: runner.os != 'Windows'
shell: bash
run: |
source ${{ inputs.venv-dir }}/bin/activate
echo "VIRTUAL_ENV=${VIRTUAL_ENV}" >> $GITHUB_ENV
echo "${VIRTUAL_ENV}/bin" >> $GITHUB_PATH
- name: venv save env (windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
${{ inputs.venv-dir }}\Scripts\Activate.ps1
echo "$Env:VIRTUAL_ENV"
echo "VIRTUAL_ENV=$Env:VIRTUAL_ENV" >> $Env:GITHUB_ENV
echo "$Env:VIRTUAL_ENV\Scripts" >> $Env:GITHUB_PATH
- run: echo $PATH
shell: bash
- run: ${{ inputs.install-cmd }}
if: inputs.install-cmd != '' && steps.cache-venv.outputs.cache-hit != 'true'
shell: bash