-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathaction.yaml
More file actions
152 lines (138 loc) · 4.68 KB
/
action.yaml
File metadata and controls
152 lines (138 loc) · 4.68 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
name: Setup environment
author: trunk.io
description: Automatic setup for trunk check dependencies (e.g. Node)
inputs:
cache-key:
description:
Cache key for setup (either passed into .trunk/setup-ci/, or used to cache node_modules in
this action).
required: false
default: ""
runs:
using: composite
steps:
- name: Detect npm/yarn/pnpm & custom setup
shell: bash
run: |
if [ -e package-lock.json ]; then
cat >>$GITHUB_ENV <<EOF
PACKAGE_MANAGER=npm
INSTALL_CMD=npm ci
HASH_GLOB=**/package-lock.json
EOF
elif [ -e yarn.lock ]; then
cat >>$GITHUB_ENV <<EOF
PACKAGE_MANAGER=yarn
INSTALL_CMD=yarn install --immutable
HASH_GLOB=**/yarn.lock
EOF
elif [ -e pnpm-lock.yaml ]; then
cat >>$GITHUB_ENV <<EOF
PACKAGE_MANAGER=pnpm
INSTALL_CMD=pnpm install --frozen-lockfile
HASH_GLOB=**/pnpm-lock.yaml
EOF
else
exit 0
fi
if [ -e .nvmrc ]; then
cat >>$GITHUB_ENV <<EOF
NODE_VERSION_FILE=.nvmrc
EOF
exit 0
elif [ -e .node-version ]; then
cat >>$GITHUB_ENV <<EOF
NODE_VERSION_FILE=.node-version
EOF
exit 0
elif [ -e .tool-versions ]; then
cat >>$GITHUB_ENV <<EOF
NODE_VERSION_FILE=.tool-versions
EOF
exit 0
elif [ -e package.json ]; then
cat >>$GITHUB_ENV <<EOF
NODE_VERSION_FILE=package.json
EOF
exit 0
fi
echo "Found node lockfiles but no node version to install"
if which node > /dev/null; then
echo "Detected existing node install"
cat >>$GITHUB_ENV <<EOF
RUN_INSTALL_NODE_PACKAGES=true
EOF
else
echo "Could not find existing node install, skipping node package installation"
fi
- name: Determine pnpm version
if: env.PACKAGE_MANAGER == 'pnpm'
shell: bash
run: |
if [ -e package.json ] && command -v jq >/dev/null; then
PNPM_VERSION=$(jq -r '.packageManager|split("@")[1]' package.json || echo "")
fi
if [ -z "${PNPM_VERSION}" ]; then
PNPM_VERSION=latest
fi
echo "PNPM_VERSION=${PNPM_VERSION}" >>$GITHUB_ENV
- name: Install pnpm
if: env.PACKAGE_MANAGER == 'pnpm'
uses: pnpm/action-setup@v2
with:
version: ${{ env.PNPM_VERSION }}
- name: Install Node dependencies
id: setup_node
if: env.PACKAGE_MANAGER && env.NODE_VERSION_FILE
uses: actions/setup-node@v3
with:
node-version-file: ${{ env.NODE_VERSION_FILE }}
continue-on-error: true
- name: Check for node installation
if: env.PACKAGE_MANAGER && env.NODE_VERSION_FILE
shell: bash
run: |
if [ ${{ steps.setup_node.outcome }} == "success" ]; then
exit 0
fi
echo "::warning::Failed to install specified node version."
echo "FAILED_NODE_INSTALL=true" >>$GITHUB_ENV
if ! command -v node >/dev/null; then
echo "::warning::No existing node install detected - installing latest node instead."
echo "INSTALL_LATEST_NODE=true" >>$GITHUB_ENV
fi
- name: Install backup node version
if: env.PACKAGE_MANAGER && env.NODE_VERSION_FILE && env.INSTALL_LATEST_NODE == 'true'
uses: actions/setup-node@v3
with:
node-version: latest
- name: Cache node_modules
if: inputs.cache-key && env.PACKAGE_MANAGER
uses: actions/cache@v3
with:
path: node_modules/
key:
${{ env.PACKAGE_MANAGER }}-${{ runner.os }}-${{ inputs.cache-key }}-${{
hashFiles(env.HASH_GLOB) }}
- name: Install ${{ env.PACKAGE_MANAGER }} packages
id: install_packages
if: env.PACKAGE_MANAGER && (env.NODE_VERSION_FILE || env.RUN_INSTALL_NODE_PACKAGES)
shell: bash
run: ${{ env.INSTALL_CMD }}
continue-on-error: true
- name: Check for package install
if: env.PACKAGE_MANAGER && (env.NODE_VERSION_FILE || env.RUN_INSTALL_NODE_PACKAGES)
shell: bash
run: |
if [ ${{ steps.install_packages.outcome }} == "success" ]; then
exit 0
fi
echo "FAILED_NODE_PACKAGE_INSTALL=true" >>$GITHUB_ENV
if [[ -z "${INITIALIZED_TRUNK}" ]]; then
echo "::error::Failed to install node packages."
echo "::error::Aborting because this repo has an existing trunk.yaml file."
exit 1
fi
echo "::warning::Failed to install node packages."
echo "::warning::Disabling linters that depend on node packages."
${TRUNK_PATH} check disable eslint stylelint