This repository was archived by the owner on Aug 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
130 lines (120 loc) · 4.36 KB
/
Copy pathaction.yml
File metadata and controls
130 lines (120 loc) · 4.36 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Setup CI/CD
description: Common CI/CD setup for The Westervelt Company
inputs:
python-version:
description: The version of Python to setup
required: true
default: "3.11"
python-requirements:
description: A comma-deliniated list of requirements*.txt files to be installed and cached
python-requirements-nohash:
description: A comma-deliniated list of requirements*.txt files to be installed, but not cached
required: false
extra-python-dependencies:
description: A comma-deliniated list of extra dependencies to be installed
use-uv:
description: Use `uv` for dependency installation
required: false
node-version:
description: The version of Node.js to setup
required: false
runs:
using: composite
steps:
- if: ${{ !inputs.python-requirements && !inputs.extra-python-dependencies }}
shell: bash
run: |
echo "Either `python-requirements` and/or `extra-python-dependencies` must be provided" >> $GITHUB_OUTPUT
exit 1
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
- name: Install prerequisites
shell: bash
run: |
if [ -n "${{ inputs.use-uv }}" ]; then
python -m pip install -U pip uv
else
python -m pip install -U pip
fi
- name: Get cache dir
id: py-cache
shell: bash
run: |
if [ -n "${{ inputs.use-uv }}" ]; then
echo "dir=$(uv cache dir)" >> $GITHUB_OUTPUT
else
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
fi
- name: Generate Python requirements hash
id: python-requirements-hash
shell: bash
run: |
HASH_INPUT=""
if [ -n "${{ inputs.python-requirements }}" ]; then
IFS=',' read -ra REQ_FILES <<< "${{ inputs.python-requirements }}"
for req_file in "${REQ_FILES[@]}"; do
cat "$req_file" >> combined_requirements.txt
done
HASH_INPUT+="$(sha256sum combined_requirements.txt | awk '{print $1}')-"
rm combined_requirements.txt
fi
if [ -n "${{ inputs.extra-python-dependencies }}" ]; then
HASH_INPUT+="${{ inputs.extra-python-dependencies }}"
fi
echo "hash=$(echo -n $HASH_INPUT | sha256sum | awk '{print $1}')" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
path: ${{ steps.py-cache.outputs.dir }}
key: ${{ runner.os }}-py-${{ steps.python-requirements-hash.outputs.hash }}
restore-keys: |
${{ runner.os }}-py-
- uses: actions/setup-node@v4
if: ${{ inputs.node-version }}
with:
node-version: ${{ inputs.node-version }}
- name: Get npm cache dir
if: ${{ inputs.node-version }}
id: npm-cache
shell: bash
run: |
echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
if: ${{ inputs.node-version }}
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Install Python dependencies
env:
PIP_CACHE_DIR: ${{ steps.pip-cache.outputs.dir }}
shell: bash
run: |
INSTALL_ARGS=""
if [ -n "${{ inputs.python-requirements }}" ]; then
INSTALL_ARGS+="$(echo "${{ inputs.python-requirements }}" | sed "s/,/ -r /g" | sed 's/^/-r /')"
fi
if [ -n "${{ inputs.extra-python-dependencies }}" ]; then
INSTALL_ARGS+=" $(echo "${{ inputs.extra-python-dependencies }}" | tr ',' ' ')"
fi
if [ -n "$INSTALL_ARGS" ]; then
if [ -n "${{ inputs.use-uv }}" ]; then
python -m uv pip install --system $INSTALL_ARGS
else
python -m pip install --no-warn-script-location $INSTALL_ARGS
fi
fi
if [ -n "${{ inputs.python-requirements-nohash }}" ]; then
NOHASH_REQ_FILES_ARG="-r $(echo "${{ inputs.python-requirements-nohash }}" | sed "s/,/ -r /g")"
if [ -n "${{ inputs.use-uv }}" ]; then
python -m uv pip install --system $NOHASH_REQ_FILES_ARG
else
python -m pip install --no-warn-script-location $NOHASH_REQ_FILES_ARG
fi
fi
- name: Install Node.js dependencies
if: ${{ inputs.node-version }}
shell: bash
run: |
npm install