Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
187 lines (164 loc) · 7.56 KB
/
Copy pathaction.yml
File metadata and controls
187 lines (164 loc) · 7.56 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: "Setup Node.js"
description: "Action to setup Node.js and install dependencies according to the package manager used."
author: hoverkraft
branding:
icon: settings
color: blue
inputs:
install-dependencies:
description: |
Install project dependencies after configuring Node.js and the package manager.
Set false when only tooling is needed, such as packaging prepared build files,
or when the caller manages dependency installation separately.
default: "true"
ignore-scripts:
description: |
Disable project and dependency lifecycle scripts during installation.
Set false to allow installation hooks, subject to the package manager's script approval settings.
Explicit commands run after installation are unaffected.
default: "true"
dependencies-cache:
description: "List of dependencies for which the cache should be managed"
required: false
default: ""
working-directory:
description: |
Working directory where the dependencies are installed.
Can be absolute or relative to the repository root.
required: false
default: "."
registry-url:
description: |
Optional registry to set up for auth.
See https://github.com/actions/setup-node?tab=readme-ov-file#usage.
required: false
default: ""
outputs:
package-manager:
description: Detected package manager (`npm`, `pnpm` or `yarn`).
value: ${{ steps.get-package-manager.outputs.package-manager }}
run-script-command:
description: "The command to run a script in the package.json file"
value: ${{ steps.get-package-manager.outputs.run-script-command }}
runs:
using: "composite"
steps:
- name: Validate installation inputs
shell: bash
env:
INSTALL_DEPENDENCIES: ${{ inputs.install-dependencies }}
IGNORE_SCRIPTS: ${{ inputs.ignore-scripts }}
run: |
for value in "$INSTALL_DEPENDENCIES" "$IGNORE_SCRIPTS"; do
case "$value" in
true|false) ;;
*) echo "install-dependencies and ignore-scripts must be true or false." >&2; exit 1 ;;
esac
done
# jscpd:ignore-start
- id: working-directory
uses: hoverkraft-tech/ci-github-common/actions/working-directory@66882b24f9f13e45a6541896a5a7c638cb91c94c # 4.0.0
with:
working-directory: ${{ inputs.working-directory }}
enforce-path-in-workspace: "false"
# jscpd:ignore-end
- id: get-package-manager
uses: $/actions/get-package-manager
with:
working-directory: ${{ steps.working-directory.outputs.absolute-path }}
- id: get-node-version-file
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
WORKING_DIRECTORY: ${{ steps.working-directory.outputs.absolute-path }}
with:
# jscpd:ignore-start
script: |
const path = require('node:path');
const fs = require('node:fs');
const workingDirectory = process.env.WORKING_DIRECTORY;
core.debug(`Running in working directory: ${workingDirectory}`);
process.chdir(workingDirectory);
const candidates = ['.nvmrc', '.node-version'];
for (const fileName of candidates) {
const candidatePath = path.resolve(workingDirectory, fileName);
if (!fs.existsSync(candidatePath)) {
continue;
}
const relativePath = path.relative(process.env.GITHUB_WORKSPACE, candidatePath);
core.debug(`Found Node version file: ${relativePath}`);
core.setOutput('node-version-file', relativePath);
return;
}
core.debug('No Node version file found in supported list');
# jscpd:ignore-end
# FIXME: workaround until will be merged: https://github.com/actions/setup-node/pull/901
- id: get-pnpm-version
if: steps.get-package-manager.outputs.package-manager == 'pnpm'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
WORKING_DIRECTORY: ${{ steps.working-directory.outputs.absolute-path }}
# Updated by Renovate; keep the fallback version in one place.
DEFAULT_PNPM_VERSION: "12.17.0"
with:
script: |
const path = require('node:path');
const fs = require('node:fs');
const workingDirectory = process.env.WORKING_DIRECTORY;
core.debug(`Running in working directory: ${workingDirectory}`);
process.chdir(workingDirectory);
let packageJsonPath = path.join(workingDirectory, 'package.json');
if (!fs.existsSync(packageJsonPath)) {
core.debug(`package.json not found in working directory "${workingDirectory}"; using the supported pnpm default`);
core.setOutput('pnpm-version', process.env.DEFAULT_PNPM_VERSION);
return;
}
packageJsonPath = path.resolve(packageJsonPath);
let packageJson;
try {
const fileContent = fs.readFileSync(packageJsonPath, 'utf8');
packageJson = JSON.parse(fileContent);
} catch (error) {
core.setFailed(`Unable to read ${packageJsonPath} to determine pnpm version: ${error.message}`);
return;
}
const packageManagerField = (packageJson?.packageManager ?? '').trim();
if (packageManagerField) {
core.debug('package.json defines packageManager; pnpm/action-setup will use it');
return;
}
core.debug('packageManager field missing; using the supported pnpm default');
core.setOutput('pnpm-version', process.env.DEFAULT_PNPM_VERSION);
- uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
if: steps.get-package-manager.outputs.package-manager == 'pnpm'
with:
version: ${{ steps.get-pnpm-version.outputs.pnpm-version }}
package_json_file: ${{ steps.working-directory.outputs.workspace-relative-path }}/package.json
run_install: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: ${{ steps.get-node-version-file.outputs.node-version-file }}
cache: ${{ inputs.install-dependencies != 'false' && steps.get-package-manager.outputs.cache-dependency-path != '' && steps.get-package-manager.outputs.package-manager || '' }}
cache-dependency-path: ${{ steps.get-package-manager.outputs.cache-dependency-path }}
registry-url: ${{ inputs.registry-url }}
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
if: inputs.install-dependencies != 'false'
env:
INSTALL_COMMAND: ${{ steps.get-package-manager.outputs.install-command }}
IGNORE_SCRIPTS: ${{ inputs.ignore-scripts }}
WORKING_DIRECTORY: ${{ steps.working-directory.outputs.absolute-path }}
with:
script: |
const installCommand = process.env.INSTALL_COMMAND?.trim();
const workingDirectory = process.env.WORKING_DIRECTORY;
if (!installCommand) {
core.setFailed('Install command is empty');
return;
}
const [command, ...args] = installCommand.split(/\s+/);
if (process.env.IGNORE_SCRIPTS === 'true') args.push('--ignore-scripts');
await exec.exec(command, args, { cwd: workingDirectory });
- if: inputs.dependencies-cache != '' && inputs.install-dependencies != 'false'
uses: $/actions/dependencies-cache
with:
dependencies: ${{ inputs.dependencies-cache }}
working-directory: ${{ steps.working-directory.outputs.absolute-path }}