Skip to content

Commit dee18fe

Browse files
committed
ci: add reusable CI validation workflow and run it before releases
Replace the single-job pull_request workflow with a reusable CI validation workflow that splits linting, type checking, testing, and building into parallel jobs. The release workflow now calls this before publishing, ensuring the merged code on main is validated before a release is published.
1 parent 183da7f commit dee18fe

4 files changed

Lines changed: 175 additions & 46 deletions

File tree

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
name: CI Validation
2+
3+
on:
4+
workflow_call:
5+
pull_request:
6+
types:
7+
- opened
8+
- reopened
9+
- synchronize
10+
11+
# Restrict permissions to read-only since validation jobs only need to checkout
12+
# and analyse the code. This limits the blast radius when called from workflows
13+
# that have broader permissions (e.g., the release workflow).
14+
permissions:
15+
contents: read
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: true
20+
21+
jobs:
22+
prepare-workflow:
23+
name: Prepare Workflow
24+
runs-on: ubuntu-latest
25+
timeout-minutes: 15
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v6
30+
31+
- name: Prepare Node.js environment
32+
uses: actions/setup-node@v6
33+
with:
34+
cache: npm
35+
node-version-file: .node-version
36+
37+
- name: Cache project 'node_modules' directory
38+
id: node-modules-cache
39+
uses: actions/cache@v5
40+
with:
41+
key: node-modules-cache-${{ hashFiles('**/package-lock.json', '**/.node-version', 'patches/**') }}
42+
path: node_modules/
43+
44+
- name: Install project npm dependencies
45+
if: ${{ steps.node-modules-cache.outputs.cache-hit != 'true' }}
46+
run: |
47+
npm ci
48+
49+
static-code-analysis:
50+
name: Static Code Analysis
51+
runs-on: ubuntu-latest
52+
timeout-minutes: 15
53+
54+
needs:
55+
- prepare-workflow
56+
57+
steps:
58+
# Full history is needed for the React Compiler compatibility check,
59+
# which diffs changed files against the base branch.
60+
- name: Checkout repository
61+
uses: actions/checkout@v6
62+
with:
63+
fetch-depth: 0
64+
65+
- name: Prepare Node.js environment
66+
uses: actions/setup-node@v6
67+
with:
68+
cache: npm
69+
node-version-file: .node-version
70+
71+
- name: Cache project 'node_modules' directory
72+
id: node-modules-cache
73+
uses: actions/cache@v5
74+
with:
75+
key: node-modules-cache-${{ hashFiles('**/package-lock.json', '**/.node-version', 'patches/**') }}
76+
path: node_modules/
77+
78+
- name: Install project npm dependencies
79+
if: ${{ steps.node-modules-cache.outputs.cache-hit != 'true' }}
80+
run: |
81+
npm ci
82+
83+
- name: Analyse code quality with ESLint
84+
run: |
85+
npm run lint
86+
87+
- name: Perform type checking with TypeScript
88+
run: |
89+
npm run type-check
90+
91+
- name: Check React Compiler compatibility
92+
if: ${{ github.event_name == 'pull_request' }}
93+
run: |
94+
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMR origin/${{ github.base_ref }}...HEAD -- 'src/**/*.ts' 'src/**/*.tsx' 'src/**/*.js' 'src/**/*.jsx' | tr '\n' ' ')
95+
if [ -n "$CHANGED_FILES" ]; then
96+
echo "Checking React Compiler compatibility for: $CHANGED_FILES"
97+
npx @doist/react-compiler-tracker --check-files $CHANGED_FILES
98+
else
99+
echo "No source files changed, skipping React Compiler check"
100+
fi
101+
102+
unit-testing:
103+
name: Unit Testing
104+
runs-on: ubuntu-latest
105+
timeout-minutes: 15
106+
107+
needs:
108+
- prepare-workflow
109+
110+
steps:
111+
- name: Checkout repository
112+
uses: actions/checkout@v6
113+
114+
- name: Prepare Node.js environment
115+
uses: actions/setup-node@v6
116+
with:
117+
cache: npm
118+
node-version-file: .node-version
119+
120+
- name: Cache project 'node_modules' directory
121+
id: node-modules-cache
122+
uses: actions/cache@v5
123+
with:
124+
key: node-modules-cache-${{ hashFiles('**/package-lock.json', '**/.node-version', 'patches/**') }}
125+
path: node_modules/
126+
127+
- name: Install project npm dependencies
128+
if: ${{ steps.node-modules-cache.outputs.cache-hit != 'true' }}
129+
run: |
130+
npm ci
131+
132+
- name: Test codebase correctness
133+
run: |
134+
npm run test
135+
136+
build-package:
137+
name: Build Package
138+
runs-on: ubuntu-latest
139+
timeout-minutes: 15
140+
141+
needs:
142+
- prepare-workflow
143+
144+
steps:
145+
- name: Checkout repository
146+
uses: actions/checkout@v6
147+
148+
- name: Prepare Node.js environment
149+
uses: actions/setup-node@v6
150+
with:
151+
cache: npm
152+
node-version-file: .node-version
153+
154+
- name: Cache project 'node_modules' directory
155+
id: node-modules-cache
156+
uses: actions/cache@v5
157+
with:
158+
key: node-modules-cache-${{ hashFiles('**/package-lock.json', '**/.node-version', 'patches/**') }}
159+
path: node_modules/
160+
161+
- name: Install project npm dependencies
162+
if: ${{ steps.node-modules-cache.outputs.cache-hit != 'true' }}
163+
run: |
164+
npm ci
165+
166+
- name: Build `@doist/reactist` package
167+
run: |
168+
npm run build

.github/workflows/chromatic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on: push
44

55
jobs:
66
chromatic-deployment:
7+
name: Chromatic Deployment
78
runs-on: ubuntu-latest
89
steps:
910
- name: Checkout repository

.github/workflows/publish-package-release.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ concurrency:
2828
cancel-in-progress: false
2929

3030
jobs:
31+
ci-validation:
32+
name: CI Validation
33+
uses: ./.github/workflows/check-ci-validation.yml
34+
3135
release-and-publish:
3236
name: Release & Publish
3337
runs-on: ubuntu-latest
3438
timeout-minutes: 30
3539

40+
needs: ci-validation
41+
3642
steps:
3743
- name: Generate release bot token
3844
id: release-bot

.github/workflows/pull_request.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)