Skip to content

Commit 3659990

Browse files
CI: create composite actions for setting environment and setting pip cache key; add caching for tests without installing examples; cleanup dependencies (#1697)
Co-authored-by: Sylwester Arabas <[email protected]>
1 parent 7bec9b0 commit 3659990

File tree

5 files changed

+221
-162
lines changed

5 files changed

+221
-162
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: "Setup environment"
2+
description: "Checkout repo, setup Python and dependencies"
3+
inputs:
4+
python-version:
5+
required: true
6+
setup-name:
7+
required: true
8+
runs:
9+
using: "composite"
10+
steps:
11+
- uses: actions/[email protected]
12+
13+
- uses: actions/[email protected]
14+
with:
15+
python-version: ${{ inputs.python-version }}
16+
17+
- uses: ./.github/actions/set-pip-path-and-cache-key
18+
- uses: actions/cache@v4
19+
id: cache
20+
with:
21+
path: ${{ env.pip_user_site }}
22+
key: ${{ inputs.setup-name }}-${{ env.toml_ci_md5 }}
23+
lookup-only: true
24+
25+
- name: pip-install (-e) PySDM and PySDM-examples
26+
if: steps.cache.outputs.cache-hit != 'true' && (! startsWith( inputs.setup-name, 'unit-tests'))
27+
run: |
28+
python -m pip install -e .[nonunit-tests,CI_version_pins] -e ./examples[CI_version_pins]
29+
python -m pip install -r tests/devops_tests/requirements.txt
30+
python -c "import PySDM_examples"
31+
shell: bash
32+
33+
- name: pip-install (-e) PySDM
34+
if: steps.cache.outputs.cache-hit != 'true' && startsWith( inputs.setup-name, 'unit-tests')
35+
run: |
36+
python -m pip install -e .[unit-tests,CI_version_pins]
37+
python -m pip install -r tests/devops_tests/requirements.txt
38+
python <<EOF
39+
try:
40+
import PySDM_examples
41+
exit(1)
42+
except ImportError:
43+
exit(0)
44+
EOF
45+
shell: bash
46+
47+
- uses: actions/cache/save@v4
48+
if: steps.cache.outputs.cache-hit != 'true'
49+
with:
50+
path: ${{ env.pip_user_site }}
51+
key: ${{ inputs.setup-name }}-${{ env.toml_ci_md5 }}
52+
53+
- if: steps.cache.outputs.cache-hit == 'true'
54+
run: rm -rf $pip_user_site
55+
shell: bash
56+
- if: steps.cache.outputs.cache-hit == 'true'
57+
uses: actions/cache/restore@v4
58+
with:
59+
fail-on-cache-miss: true
60+
path: ${{ env.pip_user_site }}
61+
key: ${{ inputs.setup-name }}-${{ env.toml_ci_md5 }}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "Set pip path and cache key"
2+
runs:
3+
using: "composite"
4+
steps:
5+
- run: |
6+
echo "pip_user_site=$(python -c "import sysconfig; print(sysconfig.get_path('purelib'))")" >> $GITHUB_ENV
7+
hash_input_files="
8+
pyproject.toml
9+
setup.py
10+
examples/pyproject.toml
11+
examples/setup.py
12+
tests/devops_tests/requirements.txt
13+
.github/workflows/tests.yml
14+
.github/actions/env-setup/action.yml
15+
"
16+
files=($hash_input_files)
17+
cat "${files[@]}" | python -c 'import sys, hashlib; print("toml_ci_md5=" + hashlib.md5(sys.stdin.buffer.read()).hexdigest())' >> $GITHUB_ENV
18+
shell: bash

0 commit comments

Comments
 (0)