-
Notifications
You must be signed in to change notification settings - Fork 5
141 lines (132 loc) · 3.99 KB
/
build.yml
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
name: Build
on: [push]
jobs:
#
# dependencies job
#
dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 16.x
uses: actions/setup-node@v4
with:
node-version: '16.x'
always-auth: true
registry-url: https://registry.npmjs.org
- id: cache_npm
name: Cache Node.js modules
uses: actions/cache@v4
with:
path: |
~/.npm
./node_modules.tar.zstd
key: ${{ runner.OS }}-node16.x-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node16.x-
- name: Install dependencies with NPM
if: steps.cache_npm.outputs.cache-hit != 'true'
run: npm ci
- name: Archive node_modules
if: steps.cache_npm.outputs.cache-hit != 'true'
run: tar --use-compress-program "zstd -T0 --long=31 -1" -cf node_modules.tar.zstd -P node_modules
- name: Persisting node_modules artifact
uses: actions/upload-artifact@v4
with:
name: node_modules.tar.zstd
path: node_modules.tar.zstd
retention-days: 2
#
# lint job
#
lint:
runs-on: ubuntu-latest
needs: [dependencies]
steps:
# Setup
- uses: actions/checkout@v4
with:
token: ${{ secrets.BUILD_USER_TOKEN || github.token }} # allows commit of any fixes to trigger a new workflow run
- name: Use Node.js 16.x
uses: actions/setup-node@v4
with:
node-version: '16.x'
always-auth: true
registry-url: https://registry.npmjs.org
- name: Restore node_modules artifact
uses: actions/download-artifact@v4
with:
name: node_modules.tar.zstd
- name: Unarchive node_modules
run: tar --use-compress-program "zstd -d --long=31" -xf node_modules.tar.zstd
# Lint
- name: Run linters
uses: wearerequired/lint-action@v2
with:
prettier: true
eslint: true
eslint_args: "--ext '.ts,.js' --ignore-path '.gitignore' --ignore-pattern '.github/*'"
continue_on_error: false
auto_fix: ${{ secrets.BUILD_USER_TOKEN && 'true' || 'false' }}
git_name: equabot
git_email: [email protected]
#
# build job
#
build:
runs-on: ubuntu-latest
needs: [dependencies]
steps:
# Setup
- uses: actions/checkout@v4
- name: Use Node.js 16.x
uses: actions/setup-node@v4
with:
node-version: '16.x'
always-auth: true
registry-url: https://registry.npmjs.org
- name: Restore node_modules artifact
uses: actions/download-artifact@v4
with:
name: node_modules.tar.zstd
- name: Unarchive node_modules
run: tar --use-compress-program "zstd -d --long=31" -xf node_modules.tar.zstd
# Build
- name: Build application
run: npm run build
env:
CI: true
- name: Check build worked correctly
run: |
if [ ! -f ./dist/index.js ]; then
echo "Something went wrong: no ./dist/index.js file was built!"
exit 1
else
echo "Build appears to be successful: ./dist/index.js was created"
fi
#
# test job
#
test:
runs-on: ubuntu-latest
needs: [build, lint]
steps:
# Setup
- uses: actions/checkout@v4
- name: Use Node.js 16.x
uses: actions/setup-node@v4
with:
node-version: '16.x'
always-auth: true
registry-url: https://registry.npmjs.org
- name: Restore node_modules artifact
uses: actions/download-artifact@v4
with:
name: node_modules.tar.zstd
- name: Unarchive node_modules
run: tar --use-compress-program "zstd -d --long=31" -xf node_modules.tar.zstd
# Tests
- name: Run project tests
run: node_modules/.bin/dotenv -e .env.ci -- npm run test:ci
env:
CI: true