-
Notifications
You must be signed in to change notification settings - Fork 1
88 lines (71 loc) · 2.81 KB
/
default-node-build.yml
File metadata and controls
88 lines (71 loc) · 2.81 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
# This is a reusable workflow.
# https://docs.github.com/en/actions/using-workflows/reusing-workflows
name: Node.js (Shared)
on:
workflow_call:
inputs:
# Node versions to test against.
# Using JSON strings because arrays are not supported.
node_matrix:
description: 'A JSON string of an array of Node versions to run tests on'
type: string
default: '["16.x", "17.x", "18.x"]'
# Only upload coverage report for one of the Node versions in the matrix.
# Must be present in the matrix. E.g., "17.x"
# Usually the most recent/stable version.
# If ommited, coverage reports will not be generated.
node_version_coverage:
description: 'The Node version to use when uploading the Coverage Report'
type: string
node_lint_command:
description: 'The command to check for lint errors'
type: string
default: 'npx standardx --verbose'
node_test_command:
description: 'The command to run Node tests, without coverage'
type: string
default: 'npx mocha'
node_test_with_coverage_command:
description: 'The command to run Node tests, with coverage'
type: string
default: 'npx c8 mocha'
secrets:
GITHUB_PAT:
description: 'A private access token to fetch private GitHub dependencies'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ${{ fromJSON(inputs.node_matrix) }}
env:
# Cannot use `secret` in conditions so we set presence in an env variable
# -- https://github.com/actions/runner/issues/953#issuecomment-821537265
HAVE_GITHUB_PAT: ${{ secrets.GITHUB_PAT != '' }}
steps:
- uses: actions/checkout@v3
with:
persist-credentials: ${{ env.HAVE_GITHUB_PAT != 'true' }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Set Private Access Token (if present)
run: git config --global url."https://${{secrets.GITHUB_PAT}}@github.com/".insteadOf ssh://git@github.com/
if: env.HAVE_GITHUB_PAT == 'true'
- name: Install Dependencies
run: npm ci
- name: Check for lint errors
run: ${{ inputs.node_lint_command }}
- name: Run tests
run: ${{ inputs.node_test_command }}
if: matrix.node-version != inputs.node_version_coverage
- name: Run tests with coverage
run: ${{ inputs.node_test_with_coverage_command }}
if: matrix.node-version == inputs.node_version_coverage
# - uses: romeovs/lcov-reporter-action@v0.3.1
# if: matrix.node-version == inputs.node_version_coverage
# with:
# # Bugged: https://github.com/romeovs/lcov-reporter-action/issues/33
# delete-old-comments: true