-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
142 lines (133 loc) · 4.8 KB
/
action.yml
File metadata and controls
142 lines (133 loc) · 4.8 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
name: 'Run node tests'
description: 'Setup Node environment and run install, audit, test, and build commands'
branding:
icon: 'package'
color: 'green'
inputs:
node-version:
description: 'Node.js version to use'
required: false
default: 'lts/*'
npm-version:
description: 'npm version to use if different from the default'
required: false
default: ''
working-directory:
description: 'Directory to run the commands in'
required: false
default: '.'
cache-dependency-path:
description: 'Path to the dependency file to use for caching (relative to working-directory)'
required: false
default: 'package-lock.json'
install-skip:
description: 'Skip npm install'
required: false
default: 'false'
skip-install:
description: 'Skip npm install'
required: false
default: 'false'
install-command:
description: 'Command to run npm ci/install'
required: false
default: 'npm ci'
audit-skip:
description: 'Skip npm audit'
required: false
default: 'false'
skip-audit:
description: 'Skip npm audit'
required: false
default: 'false'
audit-command:
description: 'Command to run npm audit'
required: false
default: 'npm audit --audit-level=high --omit=dev --package-lock-only'
test-skip:
description: 'Skip tests'
required: false
default: 'false'
skip-test:
description: 'Skip tests'
required: false
default: 'false'
test-command:
description: 'Command to run tests'
required: false
default: 'npm test'
build-skip:
description: 'Skip build'
required: false
default: 'false'
skip-build:
description: 'Skip build'
required: false
default: 'false'
build-command:
description: 'Command to run build'
required: false
default: 'npm run build'
cache-node-modules:
description: 'Cache node_modules (in addition to setup-node npm cache)'
required: false
default: 'false'
runs:
using: 'composite'
steps:
- name: Set environment variables
run: |
echo "SKIP_INSTALL=$([ "${{ inputs.install-skip }}" = "true" ] || [ "${{ inputs.skip-install }}" = "true" ] && echo "true" || echo "false")" >> $GITHUB_ENV
echo "SKIP_AUDIT=$([ "${{ inputs.audit-skip }}" = "true" ] || [ "${{ inputs.skip-audit }}" = "true" ] && echo "true" || echo "false")" >> $GITHUB_ENV
echo "SKIP_TEST=$([ "${{ inputs.test-skip }}" = "true" ] || [ "${{ inputs.skip-test }}" = "true" ] && echo "true" || echo "false")" >> $GITHUB_ENV
echo "SKIP_BUILD=$([ "${{ inputs.build-skip }}" = "true" ] || [ "${{ inputs.skip-build }}" = "true" ] && echo "true" || echo "false")" >> $GITHUB_ENV
# If cache-node-modules is true and install-command is still the default, set install-command to skip npm ci if node_modules exists
if [ "${{ inputs.cache-node-modules }}" = "true" ] && [ "${{ inputs.install-command }}" = "npm ci" ]; then
echo 'INSTALL_COMMAND=if [ -d "node_modules" ]; then echo "Using cached node_modules"; else npm ci; fi' >> $GITHUB_ENV
else
echo "INSTALL_COMMAND=${{ inputs.install-command }}" >> $GITHUB_ENV
fi
shell: bash
- name: Setup cache dependency path environment variables
run: |
if [ "${{ inputs.working-directory }}" != "." ]; then
echo "CACHE_DEPENDENCY_PATH=${{ inputs.working-directory }}/${{ inputs.cache-dependency-path }}" >> $GITHUB_ENV
else
echo "CACHE_DEPENDENCY_PATH=${{ inputs.cache-dependency-path }}" >> $GITHUB_ENV
fi
shell: bash
- name: Cache node_modules
if: ${{ inputs.cache-node-modules == 'true' }}
uses: actions/cache@v4
with:
path: ${{ inputs.working-directory }}/node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles( env.CACHE_DEPENDENCY_PATH ) }}
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: 'npm'
cache-dependency-path: ${{ env.CACHE_DEPENDENCY_PATH }}
- name: Install npm
if: ${{ inputs.npm-version }}
run: npm install -g npm@${{ inputs.npm-version }}
shell: bash
- name: Run npm audit
if: ${{ env.SKIP_AUDIT != 'true' }}
run: ${{ inputs.audit-command }}
shell: bash
working-directory: ${{ inputs.working-directory }}
- name: Install dependencies
if: ${{ env.SKIP_INSTALL != 'true' }}
run: ${{ env.INSTALL_COMMAND }}
shell: bash
working-directory: ${{ inputs.working-directory }}
- name: Run tests
if: ${{ env.SKIP_TEST != 'true' }}
run: ${{ inputs.test-command }}
shell: bash
working-directory: ${{ inputs.working-directory }}
- name: Run build
if: ${{ env.SKIP_BUILD != 'true' }}
run: ${{ inputs.build-command }}
shell: bash
working-directory: ${{ inputs.working-directory }}