Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
118 lines (106 loc) · 3.91 KB
/
Copy pathaction.yml
File metadata and controls
118 lines (106 loc) · 3.91 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
name: setup-node
description: 'Sets up node and npm for Angular development'
inputs:
node-version:
description: 'Node Versions'
required: true
npm-version:
description: 'The version of npm to install'
default: ''
use-stamp-cache:
description: 'Whether or not to use the stamp cache (skip install, use old node_modules)'
default: 'false'
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.'
working-directory:
description: 'The working directory of setup'
default: '.'
install:
description: 'Whether or not to run npm ci'
default: 'true'
runs:
using: 'composite'
steps:
- uses: actions/setup-node@v7
name: Set Node Version
with:
node-version: ${{ inputs.node-version }}
registry-url: ${{ inputs.registry-url }}
package-manager-cache: false
- run: |
npx npm config set prefix "${HOME}/.npm-global"
npx npm install -g npm@${{ inputs.npm-version }}
echo "${HOME}/.npm-global/bin" >> $GITHUB_PATH
working-directory: ${{ inputs.working-directory }}
shell: bash
if: inputs.npm-version != ''
name: Upgrade npm
- run: echo "npm_version=$(npm -v)" >> ${GITHUB_OUTPUT}
shell: bash
name: Get npm version
id: get-npm-version
- name: Get npm cache directory
id: npm-cache-dir
shell: bash
env:
STAMP: ${{ inputs.use-stamp-cache }}
run: |
if [ "$STAMP" == "true" ]
then
echo "dir=${{ inputs.working-directory }}/node_modules" >> ${GITHUB_OUTPUT}
else
echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
fi
- name: Get cache keys
id: npm-cache-keys
shell: bash
env:
NODE_VERSION: ${{ inputs.node-version }}
NPM_VERSION: ${{ steps.get-npm-version.outputs.npm_version }}
PACKAGE_HASH: ${{ hashFiles('**/package-lock.json') }}
OS: ${{ runner.os }}
STAMP: ${{ inputs.use-stamp-cache }}
run: |
if [ "$STAMP" == "true" ]
then
echo "key=npm-stamp-$OS-$NODE_VERSION-$NPM_VERSION-$PACKAGE_HASH" >> ${GITHUB_OUTPUT}
echo "restore=npm-stamp-$OS-$NODE_VERSION-$NPM_VERSION-" >> ${GITHUB_OUTPUT}
else
echo "key=npm-$OS-$NODE_VERSION-$NPM_VERSION-$PACKAGE_HASH" >> ${GITHUB_OUTPUT}
echo "restore=npm-$OS-$NODE_VERSION-$NPM_VERSION-" >> ${GITHUB_OUTPUT}
fi
- uses: actions/cache@v6
id: npm-cache
if: github.event_name != 'pull_request_target'
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ steps.npm-cache-keys.outputs.key }}
restore-keys: |
${{ steps.npm-cache-keys.outputs.restore }}
- uses: actions/cache/restore@v6
id: npm-cache-restore
if: github.event_name == 'pull_request_target'
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ steps.npm-cache-keys.outputs.key }}
restore-keys: |
${{ steps.npm-cache-keys.outputs.restore }}
- run: npx npm ci --prefer-offline --no-audit
working-directory: ${{ inputs.working-directory }}
shell: bash
name: Install Dependencies
if: |
(inputs.install == 'true') && !(
inputs.use-stamp-cache == 'true' &&
(steps.npm-cache.outputs.cache-hit == 'true' || steps.npm-cache-restore.outputs.cache-hit == 'true')
)
- run: |
rm -rf node_modules/.ng-packagr-ngcc
rm -rf node_modules/.cli-ngcc
rm -rf node_modules/.cache
working-directory: ${{ inputs.working-directory }}
shell: bash
name: Clear nx and angular junk
if: |
(inputs.install == 'true' && inputs.use-stamp-cache == 'true') &&
(steps.npm-cache.outputs.cache-hit == 'true' || steps.npm-cache-restore.outputs.cache-hit == 'true')