-
Notifications
You must be signed in to change notification settings - Fork 5
135 lines (128 loc) · 5 KB
/
ci.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
name: CI & Release
on:
# Build on pushes to release branches
push:
branches: [main]
# Build on pull requests targeting release branches
pull_request:
branches: [main]
# https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow
# https://github.com/sanity-io/semantic-release-preset/actions/workflows/ci.yml
workflow_dispatch:
inputs:
release:
description: 'Release new version'
required: true
default: false
type: boolean
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}-${{ github.event.inputs.release || 'no-release' }}
cancel-in-progress: true
jobs:
build:
name: Build, lint and test coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
with:
node-version: lts/*
cache: npm
- run: npm ci
- run: npm run build
- run: npm run lint -- --quiet
- run: npm run coverage
test:
name: Node.js ${{ matrix.node }} on ${{ matrix.os }}
needs: build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Run the testing suite on each major OS with the latest LTS release of Node.js
os: [macos-latest, ubuntu-latest, windows-latest]
node: [lts/*]
# It makes sense to also test the oldest, and latest, versions of Node.js, on ubuntu-only since it's the fastest CI runner
include:
- os: ubuntu-latest
# Test the oldest LTS release of Node that's still receiving bugfixes and security patches, versions older than that have reached End-of-Life
node: lts/-2
- os: ubuntu-latest
# Test the actively developed version that will become the latest LTS release next October
node: current
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm i
- run: npm run build
- run: npm test
env:
SKIP_MTLS_TEST: "${{ matrix.os == 'ubuntu-latest' && 'true' || 'false' }}"
test-esm:
name: Test ESM exports
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
with:
# The testing suite uses the native test runner introduced in Node.js v18
# https://nodejs.org/api/test.html
node-version: lts/*
cache: npm
- run: npm ci
- run: npm run build
- run: npm run test:esm
# This test will run both in a CJS and an ESM mode in Node.js to ensure backwards compatibility
name: Ensure pkg.exports don't break anything in modern Node.js envs
- run: npm run test:esm:browser
# This test is just ensuring the pkg.exports defined by 'browser' conditionals don't point to files that don't exist and have valid syntax (no CJS)
# Please note that this test DOES support Node.js APIs, we need to test in a Cloudflare Worker v8 runtime, or Vercel Edge Runtime, to fully test e2e
name: Test the 'browser' conditional using Node.js
test-deno:
name: Test Deno in Node compatibility mode
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
with:
node-version: lts/*
cache: npm
- run: npm ci
- run: npm run build
- uses: denoland/setup-deno@v1
with:
deno-version: vx.x.x
- run: npm run test:esm:deno
name: Test that pkg.exports supports Deno running in Node Compatibility mode
release:
name: Semantic release
runs-on: ubuntu-latest
needs: [test, test-esm, test-deno]
if: inputs.release == true
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
with:
fetch-depth: 0
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
with:
node-version: lts/*
cache: npm
- run: npm ci
- run: npx semantic-release
# Don't allow interrupting the release step if the job is cancelled, as it can lead to an inconsistent state
# e.g. git tags were pushed but it exited before `npm publish`
if: always()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
# Should release fail, dry rerun with debug on for richer logs
- run: npx semantic-release --dry-run --debug
if: ${{ failure() }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}