Skip to content

Commit ff3da15

Browse files
authored
fix(ci): improve selective checks and detailed PR comment reporting (#453)
* fix: Fixed linting issues * fix(ci): improve selective checks and detailed PR comment reporting
1 parent 1833d1f commit ff3da15

3 files changed

Lines changed: 124 additions & 62 deletions

File tree

.github/scripts/ciScript.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,36 @@ module.exports = async ({ github, context, core }) => {
4040
}
4141
});
4242

43-
console.log({
44-
backendFiles,
45-
mobileFiles,
46-
webFiles
47-
});
43+
console.log({
44+
backendFiles,
45+
mobileFiles,
46+
webFiles
47+
});
48+
49+
core.setOutput(
50+
"backendFiles",
51+
backendFiles
52+
.map(file => file.replace("apps/backend/", ""))
53+
.join(" ")
54+
)
55+
56+
core.setOutput(
57+
"mobileFiles",
58+
mobileFiles
59+
.map(file => file.replace("apps/mobile/", ""))
60+
.join(" ")
61+
)
62+
63+
core.setOutput(
64+
"webFiles",
65+
webFiles
66+
.map(file => file.replace("apps/web/", ""))
67+
.join(" ")
68+
)
4869

49-
core.setOutput("backendChanged",backendFiles.length > 0)
50-
core.setOutput("mobileChanged",mobileFiles.length > 0)
51-
core.setOutput("webChanged",webFiles.length > 0)
70+
core.setOutput("backendChanged", backendFiles.length > 0)
71+
core.setOutput("mobileChanged", mobileFiles.length > 0)
72+
core.setOutput("webChanged", webFiles.length > 0)
5273

5374
} catch (error) {
5475
console.error(error);

.github/scripts/commentResults.js

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,101 @@
1-
module.exports = async ({ github, context, backend, mobile, web }) => {
1+
module.exports = async ({
2+
github,
3+
context,
4+
backend,
5+
mobile,
6+
web,
7+
backendLint,
8+
backendTest,
9+
backendTypecheck,
10+
mobileLint,
11+
mobileTest,
12+
webCheck,
13+
webBuild
14+
}) => {
215
const owner = context.repo.owner;
316
const repo = context.repo.repo;
4-
const pr = context.payload.pull_request;
5-
const prNumber = pr.number;
17+
const prNumber = context.payload.pull_request.number;
618

7-
const statusEmoji = (status) => {
19+
const emoji = (status) => {
820
if (status === 'success') return '✅';
921
if (status === 'failure') return '❌';
1022
if (status === 'skipped') return '⏭️';
1123
return '⚪';
1224
};
1325

14-
const statusLabel = (status) => {
15-
if (status === 'skipped') return `${statusEmoji(status)} Skipped — no changes detected`;
16-
return `${statusEmoji(status)} ${status}`;
26+
const label = (status) => {
27+
if (!status) return '⚪ unknown';
28+
return `${emoji(status)} ${status}`;
1729
};
1830

19-
const results = [backend, mobile, web];
20-
const allSkipped = results.every((s) => s === 'skipped');
21-
const anyFailure = results.some((s) => s === 'failure');
22-
const allPassed = results.every((s) => s === 'success' || s === 'skipped');
31+
const anyFailure = [
32+
backend,
33+
mobile,
34+
web
35+
].includes('failure');
2336

24-
let title;
25-
if (allSkipped) {
26-
title = '⏭️ No changes detected — all checks skipped';
27-
} else if (anyFailure) {
28-
title = '❌ Some checks failed';
29-
} else if (allPassed) {
30-
title = '✅ All checks passed';
31-
} else {
32-
title = '⚪ Checks completed';
33-
}
37+
const title = anyFailure
38+
? '❌ Some checks failed'
39+
: '✅ CI completed';
3440

3541
const timestamp = new Date().toUTCString();
3642

3743
const body = `## CI Results — ${title}
3844
45+
### 🖥️ Backend (${label(backend)})
3946
| Check | Status |
4047
|---|---|
41-
| 🖥️ Backend | ${statusLabel(backend)} |
42-
| 📱 Mobile | ${statusLabel(mobile)} |
43-
| 🌐 Web | ${statusLabel(web)} |
48+
| Lint | ${label(backendLint)} |
49+
| Test | ${label(backendTest)} |
50+
| Typecheck | ${label(backendTypecheck)} |
4451
45-
> ⏭️ **Skipped** means no files were changed in that area — the check was not needed.
52+
### 📱 Mobile (${label(mobile)})
53+
| Check | Status |
54+
|---|---|
55+
| Lint | ${label(mobileLint)} |
56+
| Test | ${label(mobileTest)} |
57+
58+
### 🌐 Web (${label(web)})
59+
| Check | Status |
60+
|---|---|
61+
| Check | ${label(webCheck)} |
62+
| Build | ${label(webBuild)} |
4663
4764
---
4865
🕐 Last updated: \`${timestamp}\``;
4966

5067
const COMMENT_MARKER = '## CI Results —';
5168

5269
try {
53-
const comments = await github.paginate(github.rest.issues.listComments, {
54-
owner,
55-
repo,
56-
issue_number: prNumber,
57-
});
70+
const comments = await github.paginate(
71+
github.rest.issues.listComments,
72+
{
73+
owner,
74+
repo,
75+
issue_number: prNumber
76+
}
77+
);
5878

59-
const existingComment = comments.find(
60-
(c) => c.body && c.body.startsWith(COMMENT_MARKER)
79+
const existing = comments.find(
80+
c => c.body && c.body.startsWith(COMMENT_MARKER)
6181
);
6282

63-
if (existingComment) {
83+
if (existing) {
6484
await github.rest.issues.updateComment({
6585
owner,
6686
repo,
67-
comment_id: existingComment.id,
68-
body,
87+
comment_id: existing.id,
88+
body
6989
});
70-
console.log(`Updated existing comment: ${existingComment.id}`);
7190
} else {
7291
await github.rest.issues.createComment({
7392
owner,
7493
repo,
7594
issue_number: prNumber,
76-
body,
95+
body
7796
});
78-
console.log('Created new CI results comment');
7997
}
80-
} catch (error) {
81-
console.error('Failed to post comment:', error);
98+
} catch (err) {
99+
console.error(err);
82100
}
83101
};

.github/workflows/ci.yml

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ jobs:
1515
backendChanged: ${{ steps.detect.outputs.backendChanged }}
1616
mobileChanged: ${{ steps.detect.outputs.mobileChanged }}
1717
webChanged: ${{ steps.detect.outputs.webChanged }}
18+
backendFiles: ${{ steps.detect.outputs.backendFiles }}
19+
mobileFiles: ${{ steps.detect.outputs.mobileFiles }}
20+
webFiles: ${{ steps.detect.outputs.webFiles }}
1821

1922
steps:
20-
- name: Checkout repository
21-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
23+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
2224

2325
- name: Detect changed files
2426
id: detect
25-
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
27+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
2628
with:
2729
github-token: ${{ secrets.GITHUB_TOKEN }}
2830
script: |
@@ -44,9 +46,18 @@ jobs:
4446
- uses: pnpm/action-setup@v6.0.8
4547

4648
- run: pnpm install
47-
- run: cd apps/backend && pnpm lint
48-
- run: cd apps/backend && pnpm test
49-
- run: cd apps/backend && pnpm typecheck
49+
50+
- name: Backend lint
51+
id: backend_lint
52+
run: cd apps/backend && pnpm eslint ${{ needs.detect-changes.outputs.backendFiles }}
53+
54+
- name: Backend test
55+
id: backend_test
56+
run: cd apps/backend && pnpm test ${{ needs.detect-changes.outputs.backendFiles }}
57+
58+
- name: Backend typecheck
59+
id: backend_typecheck
60+
run: cd apps/backend && pnpm typecheck ${{ needs.detect-changes.outputs.backendFiles }}
5061

5162
web-ci:
5263
needs: detect-changes
@@ -63,8 +74,14 @@ jobs:
6374
- uses: pnpm/action-setup@v6.0.8
6475

6576
- run: pnpm install
66-
- run: cd apps/web && pnpm check
67-
- run: cd apps/web && pnpm build
77+
78+
- name: Web check
79+
id: web_check
80+
run: cd apps/web && pnpm check
81+
82+
- name: Web build
83+
id: web_build
84+
run: cd apps/web && pnpm build
6885

6986
mobile-ci:
7087
needs: detect-changes
@@ -81,8 +98,14 @@ jobs:
8198
- uses: pnpm/action-setup@v6.0.8
8299

83100
- run: pnpm install
84-
- run: cd apps/mobile && pnpm lint
85-
- run: cd apps/mobile && pnpm test
101+
102+
- name: Mobile lint
103+
id: mobile_lint
104+
run: cd apps/mobile && pnpm eslint ${{ needs.detect-changes.outputs.mobileFiles }}
105+
106+
- name: Mobile test
107+
id: mobile_test
108+
run: cd apps/mobile && pnpm test
86109

87110
comment-results:
88111
needs:
@@ -93,19 +116,19 @@ jobs:
93116
runs-on: ubuntu-latest
94117

95118
steps:
96-
- name: Checkout repository
97-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
119+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
98120

99121
- name: Comment results
100122
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
101123
with:
102124
github-token: ${{ secrets.GITHUB_TOKEN }}
103125
script: |
104126
const script = require('./.github/scripts/commentResults.js');
105-
await script({
127+
128+
await script({
106129
github,
107130
context,
108131
backend: '${{ needs.backend-ci.result }}',
109132
web: '${{ needs.web-ci.result }}',
110133
mobile: '${{ needs.mobile-ci.result }}'
111-
});
134+
});

0 commit comments

Comments
 (0)