Skip to content

Commit 20bdede

Browse files
ByteOtterNotTheEvilOne
authored andcommitted
CI: Consolidate python environment evaluation steps
* Format Code * Combine cache type evaluation and installation verification into one * Expose cache_type as output to invoked actions
1 parent 3bccf57 commit 20bdede

File tree

1 file changed

+52
-41
lines changed

1 file changed

+52
-41
lines changed

.github/actions/setup/action.yml

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,56 @@
11
name: python_lib
22
description: Installs the given GardenLinux Python library
3+
34
inputs:
4-
version:
5-
description: GardenLinux Python library version
6-
default: "0.8.9"
5+
version:
6+
description: GardenLinux Python library version
7+
default: "0.8.9"
8+
9+
outputs:
10+
version:
11+
description: "Detected Python cache strategy."
12+
value: ${{ steps.env-check.outputs.cache_type }}
13+
714
runs:
8-
using: composite
9-
steps:
10-
- name: Verify requirements.txt for "actions/setup-python" with enabled "pip" cache
11-
shell: bash
12-
run: |
13-
if [ ! -f "requirements.txt" ]; then
14-
echo "python-gardenlinux-lib @ git+https://github.com/gardenlinux/python-gardenlinux-lib.git@${{ inputs.version }}" | tee -a requirements.txt
15-
fi
16-
- name: Check for Python
17-
id: python-check
18-
run: |
19-
if command -v python &/dev/null; then
20-
echo "python_installed=true" >> $GITHUB_OUTPUT
21-
else
22-
echo "python_installed=false" >> $GITHUB_OUTPUT
23-
fi
24-
- name: Activate caching based on lockfile
25-
id: lockfile
26-
run: |
27-
if [ -f poetry.lock ]; then
28-
echo "cache_type=poetry" >> $GITHUB_OUTPUT
29-
elif [ -f requirements.txt ]; then
30-
echo "cache_type=pip" >> $GITHUB_OUTPUT
31-
else
32-
# no lockfile present: create empty requirements.txt and use pip caching
33-
touch requirements.txt
34-
echo "cache_type=pip" >> $GITHUB_OUTPUT
35-
fi
36-
- name: Set up Python 3.13
37-
if: steps.python-check.outputs.python_installed == 'false'
38-
uses: actions/setup-python@v5
39-
with:
40-
python-version: "3.13"
41-
cache: ${{ steps.lockfile.outputs.cache_type }}
42-
- name: Install GardenLinux Python library
43-
shell: bash
44-
run: |
45-
pip install git+https://github.com/gardenlinux/python-gardenlinux-lib.git@${{ inputs.version }}
15+
using: composite
16+
steps:
17+
- name: Verify requirements.txt for "actions/setup-python" with enabled "pip" cache
18+
shell: bash
19+
run: |
20+
if [ ! -f "requirements.txt" ]; then
21+
echo "gardenlinux @ git+https://github.com/gardenlinux/python-gardenlinux-lib.git@${{ inputs.version }}" | tee -a requirements.txt
22+
fi
23+
24+
- name: Evaluate Python Environment
25+
id: env-check
26+
shell: bash
27+
run: |
28+
# Check if python is installed
29+
if command -v python &> /dev/null; then
30+
echo "python_installed=true" >> $GITHUB_OUTPUT
31+
else
32+
echo "python_installed=false" >> $GITHUB_OUTPUT
33+
fi
34+
35+
# Determine cache type based on available lockfile
36+
if [ -f poetry.lock ]; then
37+
echo "cache_type=poetry" >> $GITHUB_OUTPUT
38+
elif [ -f requirements.txt ]; then
39+
echo "cache_type=pip" >> $GITHUB_OUTPUT
40+
else
41+
# no lockfile present: create empty requirements.txt and use pip caching
42+
touch requirements.txt
43+
echo "cache_type=pip" >> $GITHUB_OUTPUT
44+
fi
45+
46+
- name: Set up Python 3.13
47+
if: steps.env-check.outputs.python_installed == 'false'
48+
uses: actions/setup-python@v5
49+
with:
50+
python-version: "3.13"
51+
cache: ${{ steps.env-check.outputs.cache_type }}
52+
53+
- name: Install GardenLinux Python library
54+
shell: bash
55+
run: |
56+
pip install git+https://github.com/gardenlinux/python-gardenlinux-lib.git@${{ inputs.version }}

0 commit comments

Comments
 (0)