-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
134 lines (113 loc) · 4.05 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
name: 'Setup node'
description: 'Set up node with Volta or actions/setup-node'
inputs:
node-version:
description: 'The Node.js version to use. Leave empty to use Volta version or fallback default version. (20)'
required: false
cache:
description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.'
cache-dependency-path:
description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.'
key:
description: 'The key to look for under volta in package.json.'
required: false
outputs:
node-version:
description: 'The node version that is used.'
value: ${{ steps.node-version.outputs.version }}
runs:
using: composite
steps:
- name: 'Prepare'
id: prepare
env:
KEY: ${{ inputs.key }}
NODE_VERSION: ${{ inputs.node-version }}
PACKAGE_JSON_PATH: ${{ inputs.package-json-path }}
shell: bash
#language=bash
run: |
if [[ -f "package.json" ]] && \
[ "$(jq ".volta | has(\"node\")" "package.json")" == "true" ] && \
[[ -z "$KEY" || "$(jq ".volta | has(\"$KEY\")" "package.json")" == "true" ]]
then
# If Volta is present, use a manually specified node version if present
echo "volta=true" >> $GITHUB_OUTPUT
echo "node-version=${NODE_VERSION}" >> $GITHUB_OUTPUT
else
# If Volta is not present, use a fallback node version
echo "volta=false" >> $GITHUB_OUTPUT
echo "node-version=${NODE_VERSION:-20}" >> $GITHUB_OUTPUT
fi
- uses: actions/setup-node@v4
if: steps.prepare.outputs.volta != 'true'
with:
node-version: ${{ steps.prepare.outputs.node-version }}
cache: ${{ inputs.cache }}
cache-dependency-path: ${{ inputs.cache-dependency-path }}
- name: 'Handle Volta bin cache'
id: volta-bin-cache
if: steps.prepare.outputs.volta == 'true'
uses: actions/cache@v4
with:
key: ${{ format('{0}{1}-volta-bin', runner.os, runner.arch) }}
path: |
~/.volta/bin
- name: 'Handle Volta cache'
id: volta-cache
if: steps.prepare.outputs.volta == 'true'
uses: actions/cache@v4
with:
key: ${{ format('{0}{1}-volta-cache-{2}', runner.os, runner.arch, steps.prepare.outputs.node-version) }}
path: |
~/.volta/*.*
~/.volta/cache
~/.volta/tools
# Tries installing volta, node and yarn up to 5 times.
- name: 'Set up Volta'
id: volta
if: steps.prepare.outputs.volta == 'true'
env:
NODE_VERSION: ${{ steps.prepare.outputs.node-version }}
shell: bash
#language=bash
run: |
MAX_RETRIES=5
RETRY_COUNT=0
SUCCESS=false
function install-volta() {
if [ ! -d ~/.volta/tmp ]; then
mkdir -p ~/.volta/tmp
fi
chown -R $USER ~/.volta
chmod 755 ~/.volta
# Install Volta
curl https://get.volta.sh | bash
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"
if [ -n "$NODE_VERSION" ]; then
volta install "node@${NODE_VERSION}"
else
volta install node
fi
volta install yarn
echo "VOLTA_HOME=$VOLTA_HOME" >> $GITHUB_ENV
echo "PATH=$PATH" >> $GITHUB_ENV
}
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
install-volta && SUCCESS=true && break
RETRY_COUNT=$((RETRY_COUNT+1))
echo "Attempt $RETRY_COUNT failed. Retrying in 5 seconds..."
sleep 3
done
if [ "$SUCCESS" != "true" ]; then
echo "Failed to install Volta after $MAX_RETRIES attempts."
exit 1
fi
- name: 'Get node version'
id: node-version
shell: bash
#language=bash
run: |
version=$(node --version)
echo "version=${version:1}" >> $GITHUB_OUTPUT