This repository has been archived by the owner on Sep 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.yml
121 lines (107 loc) · 4.38 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
name: 'Setup node, pnpm, and dependency cache'
description: 'Installs pnpm, uses actions/setup-node for cache, and then runs pnpm install'
author: NullVoxPopuli
branding:
icon: 'package'
color: 'orange'
inputs:
node-version:
description: "Override the default node version, or override what is specified in your project's volta config"
required: false
node-registry-url:
description: "Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, and set up auth to read in from env.NODE_AUTH_TOKEN."
required: false
default: ''
pnpm-version:
description: 'Override the default pnpm version, which defaults to the latest 8.x'
required: false
no-lockfile:
description: 'When testing with floating dependencies, the lockfile will need to be ignored. Enabling this deletes the lockfile before running pnpm install. This is safe as long as further action steps do not commit the change'
required: false
default: false
args:
description: 'Directly pass args to pnpm'
required: false
runs:
using: 'composite'
steps:
- name: 'Determine pnpm version'
id: resolved-pnpm
shell: 'bash'
# Precedence: Most important first
# 1. inputs.pnpm-version
# 2. package.json#volta.pnpm
# 3. package.json#packageManager
# 4. default pnpm version (^8.0.0)
run: |
if [ ! -f "package.json" ]; then
echo "Could not find package.json. Did actions/checkout run?"
exit 1
fi
forcedVersion=${{inputs.pnpm-version}}
packageJson=$(cat package.json)
# when using jq, we unquote, trim extra invisibles, and then remove "null" from the output
packageManager=$(echo $packageJson | jq -r '.packageManager' | tr -dc '[:print:]' | sed "s/null//g" )
voltaPnpm=$(echo $packageJson | jq -r '.volta.pnpm' | tr -dc '[:print:]' | sed "s/null//g" )
echo "--- Debug ---"
echo "inputs.pnpm-version: $forcedVersion"
echo "packageManager: $packageManager"
echo "volta.pnpm: $voltaPnpm"
echo "--- ----- ---"
# test here: https://replit.com/@NullVoxPopuli1/if-conditions#main.sh
__resolved_version__=""
function determineVersion() {
if [ "$forcedVersion" != "" ]; then
echo "Using inputs.pnpm-version"
__resolved_version__=$forcedVersion
return
else
echo "No pnpm-version override detected"
fi
if [ "$voltaPnpm" != "" ]; then
echo "Using package.json#volta.pnpm"
__resolved_version__=$voltaPnpm
return
else
echo "package.json#volta.pnpm was not defined"
fi
if [[ "$packageManager" =~ ^"pnpm" ]]; then
version=$(echo $packageManager | cut -d "@" -f2)
if [[ "$version" != "" && "$version" != "$packageManager" ]]; then
echo "Using package.json#packageManager"
__resolved_version__=$version
return
else
echo "package.json#packageManager ($packageManager) did not specify a version"
fi
else
echo "package.json#packageManager ($packageManager) did not start with 'pnpm' or was not defined."
fi
# default
__resolved_version__=8
}
determineVersion
echo "--"
echo "Resolved pnpm @ $__resolved_version__"
echo "version=$__resolved_version__" >> $GITHUB_OUTPUT
- name: 'Remove lockfile'
shell: 'bash'
run: |
echo "Detected option --no-lockfile. Lockfile will be deleted before install."
rm -f pnpm-lock.yaml
if: ${{ inputs.no-lockfile == 'true' }}
- name: 'Install pnpm'
# this action aliases the major (via branch) to the latest full version
# https://github.com/pnpm/action-setup/branches/all
uses: pnpm/action-setup@v2
with:
version: ${{ steps.resolved-pnpm.outputs.version }}
run_install: "{ args: ['${{ inputs.args }}'] }"
- name: 'Setup node and the cache for pnpm'
# this action aliases the major to the latest full version
# https://github.com/actions/setup-node/tags
uses: actions/setup-node@v3
with:
cache: 'pnpm'
node-version: ${{ inputs.node-version }}
registry-url: ${{ inputs.node-registry-url }}