Skip to content

Commit b1541f5

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 b1541f5

3 files changed

Lines changed: 168 additions & 46 deletions

File tree

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

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,18 @@ 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+
secrets: inherit
35+
3136
release-and-publish:
3237
name: Release & Publish
3338
runs-on: ubuntu-latest
3439
timeout-minutes: 30
3540

41+
needs: ci-validation
42+
3643
steps:
3744
- name: Generate release bot token
3845
id: release-bot

.github/workflows/pull_request.yml

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

0 commit comments

Comments
 (0)