-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
151 lines (128 loc) · 5.86 KB
/
action.yml
File metadata and controls
151 lines (128 loc) · 5.86 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
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:
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:
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:
- shell: bash
# FIXME: workaround until will be merged: https://github.com/actions/runner/pull/1684
run: mkdir -p ./self-setup-node-action/ && cp -r $GITHUB_ACTION_PATH/../* ./self-setup-node-action/
- id: working-directory
uses: hoverkraft-tech/ci-github-common/actions/working-directory@f5847cb398fe65d53794e6aba98ebdfa0801f691 # 0.32.0
with:
working-directory: ${{ inputs.working-directory }}
enforce-path-in-workspace: "false"
- id: get-package-manager
if: inputs.package-manager == ''
uses: ./self-setup-node-action/get-package-manager
with:
working-directory: ${{ steps.working-directory.outputs.absolute-path }}
- id: get-node-version-file
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.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@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
WORKING_DIRECTORY: ${{ steps.working-directory.outputs.absolute-path }}
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}"; defaulting pnpm version to latest`);
core.setOutput('pnpm-version', 'latest');
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; defaulting pnpm version to latest');
core.setOutput('pnpm-version', 'latest');
- uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
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@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version-file: ${{ steps.get-node-version-file.outputs.node-version-file }}
cache: ${{ 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 }}
- shell: bash
working-directory: ${{ steps.working-directory.outputs.absolute-path }}
run: ${{ steps.get-package-manager.outputs.install-command }}
- if: inputs.dependencies-cache != ''
uses: ./self-setup-node-action/dependencies-cache
with:
dependencies: ${{ inputs.dependencies-cache }}
working-directory: ${{ steps.working-directory.outputs.absolute-path }}
# FIXME: workaround until will be merged: https://github.com/actions/runner/pull/1684
- shell: bash
if: always()
run: |
rm -fr ./self-setup-node-action