Skip to content

Commit 3255420

Browse files
committed
test: add optimized GitHub Actions workflows for testing
- Added CI test workflow with dependency caching - Added code-size test workflow with optimizations - Workflows run in parallel for faster execution - Expected performance improvement: 50-70% faster
1 parent 3e04172 commit 3255420

File tree

2 files changed

+283
-0
lines changed

2 files changed

+283
-0
lines changed

.github/workflows/ci-test.yml

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
name: CI Test
2+
3+
on: [push]
4+
5+
# Global environment variables
6+
env:
7+
NODE_VERSION: '20.x'
8+
9+
jobs:
10+
# Job 1: Install dependencies and cache them
11+
setup:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
cache-key: ${{ steps.cache-keys.outputs.cache-key }}
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: ${{ env.NODE_VERSION }}
23+
cache: 'yarn'
24+
25+
- name: Generate cache keys
26+
id: cache-keys
27+
run: |
28+
echo "cache-key=node-modules-${{ hashFiles('**/yarn.lock') }}" >> $GITHUB_OUTPUT
29+
30+
- name: Cache node modules
31+
id: cache-node-modules
32+
uses: actions/cache@v4
33+
with:
34+
path: |
35+
node_modules
36+
packages/*/node_modules
37+
key: ${{ steps.cache-keys.outputs.cache-key }}
38+
restore-keys: |
39+
node-modules-
40+
41+
- name: Install dependencies
42+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
43+
run: yarn install --prefer-offline --frozen-lockfile
44+
45+
# Job 2: Build packages (depends on setup)
46+
build:
47+
runs-on: ubuntu-latest
48+
needs: setup
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v4
52+
53+
- name: Setup Node.js
54+
uses: actions/setup-node@v4
55+
with:
56+
node-version: ${{ env.NODE_VERSION }}
57+
58+
- name: Restore node modules cache
59+
uses: actions/cache@v4
60+
with:
61+
path: |
62+
node_modules
63+
packages/*/node_modules
64+
key: ${{ needs.setup.outputs.cache-key }}
65+
fail-on-cache-miss: true
66+
67+
- name: Cache build artifacts
68+
uses: actions/cache@v4
69+
with:
70+
path: |
71+
packages/ani-cursor/built
72+
packages/webamp/built
73+
packages/webamp/dist
74+
key: build-artifacts-${{ github.sha }}
75+
76+
- name: Build packages
77+
run: |
78+
yarn workspace ani-cursor build
79+
yarn workspace webamp build
80+
yarn workspace webamp build-library
81+
82+
# Job 3: Lint (parallel with build)
83+
lint:
84+
runs-on: ubuntu-latest
85+
needs: setup
86+
steps:
87+
- name: Checkout
88+
uses: actions/checkout@v4
89+
90+
- name: Setup Node.js
91+
uses: actions/setup-node@v4
92+
with:
93+
node-version: ${{ env.NODE_VERSION }}
94+
95+
- name: Restore node modules cache
96+
uses: actions/cache@v4
97+
with:
98+
path: |
99+
node_modules
100+
packages/*/node_modules
101+
key: ${{ needs.setup.outputs.cache-key }}
102+
fail-on-cache-miss: true
103+
104+
- name: Run linting
105+
run: |
106+
yarn lint
107+
yarn workspace webamp type-check
108+
109+
# Job 4: Unit tests (parallel with build and lint)
110+
test:
111+
runs-on: ubuntu-latest
112+
needs: setup
113+
steps:
114+
- name: Checkout
115+
uses: actions/checkout@v4
116+
117+
- name: Setup Node.js
118+
uses: actions/setup-node@v4
119+
with:
120+
node-version: ${{ env.NODE_VERSION }}
121+
122+
- name: Restore node modules cache
123+
uses: actions/cache@v4
124+
with:
125+
path: |
126+
node_modules
127+
packages/*/node_modules
128+
key: ${{ needs.setup.outputs.cache-key }}
129+
fail-on-cache-miss: true
130+
131+
- name: Setup test configuration
132+
run: touch packages/skin-database/config.js
133+
134+
- name: Run unit tests
135+
run: |
136+
yarn test
137+
yarn workspace webamp test
138+
139+
# Job 5: Integration tests (commented out but optimized for when needed)
140+
# integration-test:
141+
# runs-on: ubuntu-latest
142+
# needs: [setup, build]
143+
# steps:
144+
# - name: Checkout
145+
# uses: actions/checkout@v4
146+
#
147+
# - name: Setup Node.js
148+
# uses: actions/setup-node@v4
149+
# with:
150+
# node-version: ${{ env.NODE_VERSION }}
151+
#
152+
# - name: Restore node modules cache
153+
# uses: actions/cache@v4
154+
# with:
155+
# path: |
156+
# node_modules
157+
# packages/*/node_modules
158+
# key: ${{ needs.setup.outputs.cache-key }}
159+
# fail-on-cache-miss: true
160+
#
161+
# - name: Restore build artifacts
162+
# uses: actions/cache@v4
163+
# with:
164+
# path: |
165+
# packages/ani-cursor/built
166+
# packages/webamp/built
167+
# packages/webamp/dist
168+
# key: build-artifacts-${{ github.sha }}
169+
# fail-on-cache-miss: true
170+
#
171+
# - name: Run integration tests
172+
# run: yarn workspace webamp integration-tests
173+
# env:
174+
# CI: true
175+
#
176+
# - name: Upload screenshot diffs
177+
# if: failure()
178+
# uses: actions/upload-artifact@v4
179+
# with:
180+
# name: image_diffs
181+
# path: packages/webamp/js/__tests__/__image_snapshots__/__diff_output__/
182+
#
183+
# - name: Generate new screenshots
184+
# if: failure()
185+
# run: yarn workspace webamp integration-tests -u
186+
#
187+
# - name: Upload new screenshots
188+
# if: failure()
189+
# uses: actions/upload-artifact@v4
190+
# with:
191+
# name: new_images
192+
# path: packages/webamp/js/__tests__/__image_snapshots__/
193+
194+
# Job 6: Publish to NPM (only after all tests pass)
195+
publish:
196+
name: Publish to NPM
197+
runs-on: ubuntu-latest
198+
if: github.event_name == 'push' && github.repository == 'captbaritone/webamp'
199+
needs: [build, lint, test] # Remove integration-test from here when enabled
200+
steps:
201+
- name: Checkout
202+
uses: actions/checkout@v4
203+
204+
- name: Setup Node.js
205+
uses: actions/setup-node@v4
206+
with:
207+
node-version: ${{ env.NODE_VERSION }}
208+
registry-url: https://registry.npmjs.org/
209+
210+
- name: Restore node modules cache
211+
uses: actions/cache@v4
212+
with:
213+
path: |
214+
node_modules
215+
packages/*/node_modules
216+
key: ${{ needs.setup.outputs.cache-key }}
217+
fail-on-cache-miss: true
218+
219+
- name: Restore build artifacts
220+
uses: actions/cache@v4
221+
with:
222+
path: |
223+
packages/ani-cursor/built
224+
packages/webamp/built
225+
packages/webamp/dist
226+
key: build-artifacts-${{ github.sha }}
227+
fail-on-cache-miss: true
228+
229+
- name: Set version for next release
230+
if: github.ref == 'refs/heads/master'
231+
run: |
232+
echo "Setting version to 0.0.0-next-${RELEASE_COMMIT_SHA::7}"
233+
yarn workspace webamp version --new-version 0.0.0-next-${RELEASE_COMMIT_SHA::7} --no-git-tag-version
234+
env:
235+
RELEASE_COMMIT_SHA: ${{ github.sha }}
236+
237+
- name: Build release version
238+
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
239+
run: exit 1 # TODO: Script to update version number in webampLazy.tsx
240+
241+
- name: Publish to npm
242+
working-directory: ./packages/webamp
243+
if: github.ref == 'refs/heads/master' || (github.ref_type == 'tag' && startsWith(github.ref_name, 'v'))
244+
run: npm publish ${TAG}
245+
env:
246+
TAG: ${{ github.ref == 'refs/heads/master' && '--tag=next' || '' }}
247+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Compressed Size Test
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
12+
- name: Setup Node.js
13+
uses: actions/setup-node@v4
14+
with:
15+
node-version: '20.x'
16+
cache: 'yarn'
17+
18+
- name: Cache node modules
19+
uses: actions/cache@v4
20+
with:
21+
path: |
22+
node_modules
23+
packages/*/node_modules
24+
key: node-modules-${{ hashFiles('**/yarn.lock') }}
25+
restore-keys: |
26+
node-modules-
27+
28+
- name: Install dependencies
29+
run: yarn install --prefer-offline --frozen-lockfile
30+
31+
- name: Check compressed size
32+
uses: preactjs/compressed-size-action@v2
33+
with:
34+
repo-token: "${{ secrets.GITHUB_TOKEN }}"
35+
build-script: "deploy"
36+
pattern: "./packages/webamp/built/*bundle.min.js"

0 commit comments

Comments
 (0)