-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
action.yml
151 lines (138 loc) · 5.07 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: "Base Setup"
description: "Base Setup Actions Used Across Workflows"
inputs:
python_version:
description: "The python version"
node_version:
description: "The node version"
dependency_type:
default: "standard"
description: "The dependency installation type: standard, pre, minimum"
runs:
using: "composite"
steps:
- name: Set up environment
shell: bash
run: |
set -eux
PYTHON_VERSION="${{ inputs.python_version || matrix.python-version }}"
NODE_VERSION=${{ inputs.node_version || matrix.node-version || '20.x' }}
DEPENDENCY_TYPE=${{ inputs.dependency_type }}
# Handle default python value based on dependency type.
if [ $DEPENDENCY_TYPE == "pre" ]; then
DEFAULT_PYTHON="3.12"
elif [ $DEPENDENCY_TYPE == "minimum" ]; then
DEFAULT_PYTHON="3.8"
elif [ $DEPENDENCY_TYPE != "standard" ]; then
echo "Unrecognized dependency type $DEPENDENCY_TYPE"
exit 1
else
DEFAULT_PYTHON="3.11"
fi
echo "DEFAULT_PYTHON is $DEFAULT_PYTHON"
PYTHON_VERSION="${PYTHON_VERSION:-$DEFAULT_PYTHON}"
echo "PYTHON_VERSION=$PYTHON_VERSION" >> $GITHUB_ENV
echo "NODE_VERSION=$NODE_VERSION" >> $GITHUB_ENV
echo "CACHE_PREFIX=${{ runner.os }}-${{ github.workflow}}-${{ github.job }}" >> $GITHUB_ENV
echo "DEPENDENCY_TYPE=$DEPENDENCY_TYPE" >> $GITHUB_ENV
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
allow-prereleases: true
# Cache pip
# We cannot use the builtin cache because it errors out with the files
# are not present.
- name: Get pip cache dir
id: pip-cache
shell: bash
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: Cache pip
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ env.CACHE_PREFIX }}-pip-${{ env.PYTHON_VERSION }}-${{ hashFiles('setup.cfg', 'setup.py', '**/requirements.txt', '**/pyproject.toml') }}
restore-keys: |
${{ env.CACHE_PREFIX }}-pip-${{ env.PYTHON_VERSION }}
- name: Install node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
# Cache yarn
# We cannot use the builtin cache because it errors out with the files
# are not present.
- name: Get yarn cache directory path
id: yarn-cache-dir-path
shell: bash
run: |
# Enable corepack if the project defines packageManager
if [ -f package.json ]; then
export HAS_PKG_MANAGER=$(grep -e \"packageManager\"\: package.json)
if [ ! -z "$HAS_PKG_MANAGER" ]; then corepack enable; fi
fi
CACHE_DIR=$(yarn config get cacheFolder)
[[ "$CACHE_DIR" == "undefined" ]] && CACHE_DIR=$(yarn cache dir)
echo "dir=$CACHE_DIR" >> $GITHUB_OUTPUT
- name: Cache yarn
uses: actions/cache@v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ env.CACHE_PREFIX }}-yarn-${{ env.NODE_VERSION }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ env.CACHE_PREFIX }}-yarn-${{ env.NODE_VERSION }}
- name: Cache checked links
if: ${{ matrix.group == 'link_check' }}
uses: actions/cache@v4
with:
path: ~/.cache/pytest-link-check
key: ${{ env.CACHE_PREFIX }}-linkcheck-${{ hashFiles('**/*.md', '**/*.rst') }}-links
restore-keys: |
${{ env.CACHE_PREFIX }}-linkcheck-
- name: Cache conda
uses: actions/cache@v4
with:
path: ~/conda_pkgs_dir
key: ${{ env.CACHE_PREFIX }}-conda-${{ env.CACHE_NUMBER }}-${{
hashFiles('**/environment*.yml') }}
restore-keys: |
${{ env.CACHE_PREFIX }}-conda-
- name: Enable long paths on Windows
if: startsWith(runner.os, 'Windows')
run: Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled -Value 1
shell: pwsh
- name: Upgrade packaging dependencies
shell: bash
run: |
set -eux
echo "::group::Upgrade packaging dependencies"
python -m pip install --upgrade pip
if [ "$RUNNER_OS" != "Windows" ]; then
pipx install hatch --python $(which python)
else
pipx install hatch
fi
echo "::endgroup::"
- name: Handle dependency type
shell: bash
run: |
set -eux
if [ $DEPENDENCY_TYPE == 'pre' ]; then
echo "PIP_PRE=1" >> $GITHUB_ENV
elif [ $DEPENDENCY_TYPE == 'minimum' ]; then
source ${{ github.action_path }}/setup_constraints.sh
fi
- name: Print Diagnostics
shell: bash
run: |
set -eux
echo "::group::env"
env
echo "::endgroup::"
pip debug || true
echo "::group::piplist"
pip list || true
echo "::endgroup::"
yarn --version
node --version