Repository navigation
221 lines (199 loc) · 7.04 KB
/
Copy pathnode-ci.yml
File metadata and controls
221 lines (199 loc) · 7.04 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
name: Node CI
on:
workflow_call:
inputs:
node-version:
description: Node.js version to install.
required: false
type: string
default: '24'
package-manager:
description: Package manager to configure. Supported values are npm, pnpm, and yarn.
required: false
type: string
default: pnpm
working-directory:
description: Directory that contains the Node package.
required: false
type: string
default: .
install-command:
description: Dependency install command. Empty uses the setup-node action default for the package manager.
required: false
type: string
default: ''
lint-command:
description: Optional additional lint command run after the built-in zero-warning checks.
required: false
type: string
default: ''
eslint-args:
description: ESLint arguments. The workflow always appends --max-warnings=0.
required: false
type: string
default: .
typecheck-command:
description: TypeScript typecheck command. Empty uses tsc --noEmit through the selected package manager.
required: false
type: string
default: ''
prettier-args:
description: Prettier check arguments.
required: false
type: string
default: .
test-command:
description: Optional test command.
required: false
type: string
default: ''
build-command:
description: Optional build command.
required: false
type: string
default: ''
package-check-command:
description: Optional package validation command.
required: false
type: string
default: ''
secrets:
packages-token:
description: GitHub Packages token used for npm package resolution.
required: false
permissions:
contents: read
packages: read
jobs:
node:
name: Node CI
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v7
- name: Resolve workflow ref
id: workflow-ref
shell: bash
env:
WORKFLOW_REF: ${{ github.workflow_ref }}
run: |
set -euo pipefail
ref="${WORKFLOW_REF#*@}"
if [ -z "$ref" ] || [ "$ref" = "$WORKFLOW_REF" ]; then
echo "::error::Unable to resolve reusable workflow ref from $WORKFLOW_REF"
exit 1
fi
printf 'ref=%s\n' "$ref" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v7
with:
repository: JorisJonkers-dev/github-workflows
ref: v0.35.0 # x-release-please-version
path: .github-workflows
persist-credentials: false
- uses: ./.github-workflows/actions/setup-node
with:
node-version: ${{ inputs.node-version }}
package-manager: ${{ inputs.package-manager }}
working-directory: ${{ inputs.working-directory }}
install-command: ${{ inputs.install-command }}
github-packages-token: ${{ secrets.packages-token || github.token }}
# The vendored actions tree lives at .github-workflows/. Consuming projects exclude it from
# linting/formatting by default (it is in the shared eslint/ktlint config ignores, the
# scaffolded .gitignore — which antfu-eslint honours — and .prettierignore), so quality
# commands see only the project's own files without this workflow mutating the checkout.
- name: Package check
if: ${{ inputs.package-check-command != '' }}
working-directory: ${{ inputs.working-directory }}
env:
PACKAGE_CHECK_COMMAND: ${{ inputs.package-check-command }}
run: bash -euo pipefail -c "$PACKAGE_CHECK_COMMAND"
- name: ESLint
working-directory: ${{ inputs.working-directory }}
env:
ESLINT_ARGS: ${{ inputs.eslint-args }}
PACKAGE_MANAGER: ${{ inputs.package-manager }}
run: |
set -euo pipefail
case "$PACKAGE_MANAGER" in
npm)
eslint_command="npm exec -- eslint ${ESLINT_ARGS} --max-warnings=0"
;;
pnpm)
eslint_command="pnpm exec eslint ${ESLINT_ARGS} --max-warnings=0"
;;
yarn)
eslint_command="yarn eslint ${ESLINT_ARGS} --max-warnings=0"
;;
*)
echo "::error::Unsupported package-manager: $PACKAGE_MANAGER. Use npm, pnpm, or yarn."
exit 1
;;
esac
bash -euo pipefail -c "$eslint_command"
- name: Typecheck
working-directory: ${{ inputs.working-directory }}
env:
PACKAGE_MANAGER: ${{ inputs.package-manager }}
TYPECHECK_COMMAND: ${{ inputs.typecheck-command }}
run: |
set -euo pipefail
typecheck_command="$TYPECHECK_COMMAND"
if [ -z "$typecheck_command" ]; then
case "$PACKAGE_MANAGER" in
npm)
typecheck_command="npm exec -- tsc --noEmit"
;;
pnpm)
typecheck_command="pnpm exec tsc --noEmit"
;;
yarn)
typecheck_command="yarn tsc --noEmit"
;;
*)
echo "::error::Unsupported package-manager: $PACKAGE_MANAGER. Use npm, pnpm, or yarn."
exit 1
;;
esac
fi
bash -euo pipefail -c "$typecheck_command"
- name: Prettier
working-directory: ${{ inputs.working-directory }}
env:
PACKAGE_MANAGER: ${{ inputs.package-manager }}
PRETTIER_ARGS: ${{ inputs.prettier-args }}
run: |
set -euo pipefail
case "$PACKAGE_MANAGER" in
npm)
prettier_command="npm exec -- prettier --check ${PRETTIER_ARGS}"
;;
pnpm)
prettier_command="pnpm exec prettier --check ${PRETTIER_ARGS}"
;;
yarn)
prettier_command="yarn prettier --check ${PRETTIER_ARGS}"
;;
*)
echo "::error::Unsupported package-manager: $PACKAGE_MANAGER. Use npm, pnpm, or yarn."
exit 1
;;
esac
bash -euo pipefail -c "$prettier_command"
- name: Additional lint
if: ${{ inputs.lint-command != '' }}
working-directory: ${{ inputs.working-directory }}
env:
LINT_COMMAND: ${{ inputs.lint-command }}
run: bash -euo pipefail -c "$LINT_COMMAND"
- name: Test
if: ${{ inputs.test-command != '' }}
working-directory: ${{ inputs.working-directory }}
env:
TEST_COMMAND: ${{ inputs.test-command }}
run: bash -euo pipefail -c "$TEST_COMMAND"
- name: Build
if: ${{ inputs.build-command != '' }}
working-directory: ${{ inputs.working-directory }}
env:
BUILD_COMMAND: ${{ inputs.build-command }}
run: bash -euo pipefail -c "$BUILD_COMMAND"