-
-
Notifications
You must be signed in to change notification settings - Fork 0
213 lines (208 loc) · 7.07 KB
/
CI.yml
File metadata and controls
213 lines (208 loc) · 7.07 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
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
207
208
209
210
211
212
213
# CI for src folder
name: CI
on:
workflow_dispatch:
pull_request:
branches:
- '**'
paths:
- 'test/**'
- 'src/**'
- 'scripts/**'
- 'config/**'
- '.github/**'
- '.yarnrc.yml'
- 'package.json'
- 'yarn.lock'
push:
branches:
- master
paths:
- 'test/**'
- 'src/**'
- 'scripts/**'
- 'config/**'
- '.github/**'
- '.yarnrc.yml'
- 'package.json'
- 'yarn.lock'
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
checks:
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: corepack enable
- run: yarn install --immutable --mode=skip-build
- run: yarn lint
- run: yarn type-check
- name: Run unit tests with coverage
id: run_unit_tests
env:
NODE_OPTIONS: --max-old-space-size=12288
run: |
set -o pipefail
mkdir -p .tmp
LOG_FILE=.tmp/vitest-coverage.log
status=0
yarn test:coverage 2>&1 | tee "$LOG_FILE" || status=$?
if [ "$status" -eq 0 ]; then
exit 0
fi
node scripts/accept-known-vitest-worker-error.mjs "$LOG_FILE"
- name: Print failed unit tests
if: ${{ failure() && steps.run_unit_tests.outcome == 'failure' }}
run: node .github/workflows/print-vitest-failures.cjs
- name: Write coverage badge payload
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: node scripts/write-coverage-badge.mjs
- name: Upload coverage badge artifact
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v4
with:
name: coverage-badge
path: badges/coverage.json
- run: yarn build
- name: Upload dist artifact
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
e2e:
runs-on: ubuntu-22.04
timeout-minutes: 20
env:
TEST_PKC_RPC_PORT: ${{ matrix.pkc_rpc_port }}
VITE_TEST_PKC_RPC_PORT: ${{ matrix.pkc_rpc_port }}
strategy:
fail-fast: false
matrix:
include:
- suite: mock
pkc_rpc_port: 48392
command: CHROME_BIN=$(which chromium-browser) yarn test:e2e:mock
browsers: chromium
- suite: chrome
pkc_rpc_port: 48492
command: CHROME_BIN=$(which chromium-browser) yarn test:e2e:chrome
browsers: chromium
- suite: firefox
pkc_rpc_port: 48592
command: FIREFOX_BIN=$(which firefox) yarn test:e2e:firefox
browsers: firefox
- suite: mock-content
pkc_rpc_port: 48692
command: CHROME_BIN=$(which chromium-browser) yarn test:e2e:mock-content
browsers: chromium
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: corepack enable
- run: yarn install --immutable
- uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
- run: sudo echo "255.255.255.255 cloudflare-ipfs.com" | sudo tee -a /etc/hosts
- run: sudo echo "255.255.255.255 pubsubprovider.xyz" | sudo tee -a /etc/hosts
- run: yarn playwright install ${{ matrix.browsers }}
- run: yarn build
- run: yarn test:server & yarn test:server:wait-on
- name: Run e2e ${{ matrix.suite }} tests
id: run_e2e
run: ${{ matrix.command }}
- name: Print failed e2e ${{ matrix.suite }} tests
if: ${{ failure() && steps.run_e2e.outcome == 'failure' }}
run: node .github/workflows/print-vitest-failures.cjs
dist:
runs-on: ubuntu-22.04
timeout-minutes: 10
needs: [checks, e2e]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '22.14.0'
registry-url: 'https://registry.npmjs.org'
- run: corepack enable
- run: yarn install --immutable --mode=skip-build
- name: Download dist artifact
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Download coverage badge artifact
uses: actions/download-artifact@v4
with:
name: coverage-badge
path: badges/
- name: Upgrade npm for trusted publishing
run: npm install -g npm@11
- name: Check if package version already exists
id: check_npm_version
env:
NODE_AUTH_TOKEN: ''
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
echo "version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
if npm view @bitsocial/bitsocial-react-hooks@$PACKAGE_VERSION version 2>/dev/null; then
echo "Version $PACKAGE_VERSION already exists on npm, skipping publish"
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "Version $PACKAGE_VERSION not found on npm, will publish"
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Generate changelog
if: steps.check_npm_version.outputs.exists == 'false'
run: yarn changelog
- name: Write GitHub release notes
if: steps.check_npm_version.outputs.exists == 'false'
run: |
mkdir -p .tmp
yarn changelog:release-notes "${{ steps.check_npm_version.outputs.version }}" > .tmp/release-notes.md
- run: git add dist badges/coverage.json CHANGELOG.md --force
- run: git status
- uses: stefanzweifel/git-auto-commit-action@v4
id: dist_commit
with:
commit_message: 'chore(ci): update release artifacts'
file_pattern: 'dist badges/coverage.json CHANGELOG.md'
add_options: '--force'
branch: ${{ github.ref_name }}
- name: Publish to npm
if: steps.check_npm_version.outputs.exists == 'false'
env:
NODE_AUTH_TOKEN: ''
run: npm publish --access public --provenance
- name: Create GitHub release
if: steps.check_npm_version.outputs.exists == 'false'
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ steps.check_npm_version.outputs.tag }}
run: |
if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
echo "Release $RELEASE_TAG already exists, skipping"
exit 0
fi
gh release create "$RELEASE_TAG" \
--target "$GITHUB_SHA" \
--title "$RELEASE_TAG" \
--notes-file .tmp/release-notes.md \
--latest