-
Notifications
You must be signed in to change notification settings - Fork 1
206 lines (165 loc) · 5.35 KB
/
build-and-test.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
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
# Copyright (c) Omar Boukli-Hacene. All rights reserved.
# Distributed under an MIT-style license that can be
# found in the LICENSE file.
# SPDX-License-Identifier: MIT
name: Build and test
on:
pull_request:
push:
workflow_dispatch:
permissions: {}
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- version: 18.x
- version: 20.x
run-sonarscanner: true
- version: 21.x
steps:
- name: Check out repository with full history
if: ${{ matrix.node-version.run-sonarscanner }}
uses: actions/checkout@v3
with:
# Shallow clones disabled for a better relevancy of SonarSource analysis.
fetch-depth: 0
persist-credentials: false
- name: Check out repository
if: ${{ ! matrix.node-version.run-sonarscanner }}
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Use Node.js ${{ matrix.node-version.version }}
uses: actions/setup-node@v3
with:
cache: npm
check-latest: false
node-version: ${{ matrix.node-version.version }}
- name: Configure and update NPM
run: |-
npm config set fund=false --global
npm install --global npm@latest
- name: Install packages
run: npm ci
- name: Check code style
run: npx prettier --check .
- name: Lint
run: npm run lint
- name: Build
run: npm run build
- name: Run unit tests
run: npm test
- name: Analyze with SonarCloud
if: ${{ matrix.node-version.run-sonarscanner }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Run with npx
run: npx -- montehall --version
- name: Pack
id: pack_artifact
run: >-
echo "artifact_name="$(
npm pack --json --pack-destination '${{ runner.temp }}'
| jq --raw-output '.[0] | .filename'
)""
>> $GITHUB_OUTPUT
- name: Install
run: npm install --global ${{ steps.pack_artifact.outputs.artifact_name }}
working-directory: ${{ runner.temp }}
- name: Run integration tests
run: |-
montehall --version
montehall --help
montehall
montehall --games 11
montehall --random advanced
montehall --wise
montehall --random advanced --wise
montehall --games 0 --random advanced --wise
montehall --games 3 --random advanced --wise --verbose
montehall --games 100 --table-file ./vendor/numbers.txt
montehall --games 100 --table-file ./vendor/numbers.txt --wise
montehall --doors 100 --games 100
montehall --doors 100 --games 100 --wise
montehall --doors 100 --games 3 --wise --verbose
working-directory: ${{ github.workspace }}/..
dependency-check:
name: Dependency check
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Use latest Node.js LTS
uses: actions/setup-node@v3
with:
cache: npm
check-latest: false
node-version: lts/*
- name: Configure and update NPM
run: |-
npm config set fund=false --global
npm install --global npm@latest
- name: Do non-locked install
run: npm install
- name: Check if dependency structure can be simplified
run: npm dedupe
- name: Check if Git tree is dirty
run: git diff --exit-code
package:
name: Pack
runs-on: ubuntu-latest
needs:
- build
- dependency-check
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Use latest Node.js LTS
uses: actions/setup-node@v3
with:
cache: npm
check-latest: false
node-version: lts/*
- name: Configure and update NPM
run: |-
npm config set fund=false --global
npm install --global npm@latest
- name: Audit dependencies
run: npm audit
- name: Install packages
run: npm ci
- name: Build
run: npm run build
- name: Clean up package.json
run: npm pkg delete devDependencies scripts
- name: Prune dependencies
run: npm prune
- name: Pack
id: pack_artifact
run: >-
echo "artifact_name="$(
npm pack --json --pack-destination '${{ runner.temp }}'
| jq --raw-output '.[0] | .filename'
)""
>> $GITHUB_OUTPUT
- name: Install
run: npm install --global ${{ steps.pack_artifact.outputs.artifact_name }}
working-directory: ${{ runner.temp }}
- name: Test package
run: montehall --version
working-directory: ${{ github.workspace }}/..
- name: Upload package artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.pack_artifact.outputs.artifact_name }}
path: ${{ runner.temp }}/${{ steps.pack_artifact.outputs.artifact_name }}
if-no-files-found: error