Skip to content

Commit f355777

Browse files
authored
fix(workflow) (#468)
1 parent 5fd5d98 commit f355777

3 files changed

Lines changed: 115 additions & 122 deletions

File tree

.github/scripts/ciScript.js

Lines changed: 26 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
const isTestFile = (file) => /\.(test|spec)\.[jt]sx?$/.test(file);
2+
3+
const deriveTestFiles = (files) => {
4+
return files.map((file) => {
5+
if (isTestFile(file)) return file;
6+
7+
const withoutExt = file.replace(/\.[jt]sx?$/, '');
8+
const parts = withoutExt.split('/');
9+
const baseName = parts[parts.length - 1];
10+
const dir = parts.slice(0, -1).join('/');
11+
12+
return `${dir}/__tests__/${baseName}.test.ts`;
13+
});
14+
};
15+
116
module.exports = async ({ github, context, core }) => {
217
const owner = context.repo.owner;
318
const repo = context.repo.repo;
@@ -6,7 +21,6 @@ module.exports = async ({ github, context, core }) => {
621
const prState = pr.state;
722

823
const backendFiles = [];
9-
const backendTests = [];
1024
const mobileFiles = [];
1125
const webFiles = [];
1226

@@ -34,60 +48,26 @@ module.exports = async ({ github, context, core }) => {
3448

3549
if (fileName.startsWith('apps/backend/')) {
3650
backendFiles.push(fileName);
37-
38-
const relative = fileName.replace('apps/backend/src/', '');
39-
const baseName = relative
40-
.split('/')
41-
.pop()
42-
?.replace(/\.(ts|tsx|js|jsx)$/, '');
43-
44-
if (baseName) {
45-
backendTests.push(`src/__tests__/${baseName}.test.ts`);
46-
}
47-
4851
} else if (fileName.startsWith('apps/mobile/')) {
4952
mobileFiles.push(fileName);
5053
} else if (fileName.startsWith('apps/web/')) {
5154
webFiles.push(fileName);
5255
}
5356
});
5457

55-
console.log({
56-
backendFiles,
57-
backendTests,
58-
mobileFiles,
59-
webFiles,
60-
});
58+
const strippedBackend = backendFiles.map(f => f.replace('apps/backend/', ''));
59+
const strippedMobile = mobileFiles.map(f => f.replace('apps/mobile/', ''));
6160

62-
core.setOutput(
63-
"backendFiles",
64-
backendFiles
65-
.map(file => file.replace("apps/backend/", ""))
66-
.join(" ")
67-
);
68-
69-
core.setOutput(
70-
"backendTests",
71-
[...new Set(backendTests)].join(" ")
72-
);
73-
74-
core.setOutput(
75-
"mobileFiles",
76-
mobileFiles
77-
.map(file => file.replace("apps/mobile/", ""))
78-
.join(" ")
79-
);
80-
81-
core.setOutput(
82-
"webFiles",
83-
webFiles
84-
.map(file => file.replace("apps/web/", ""))
85-
.join(" ")
86-
);
61+
console.log({ backendFiles, mobileFiles, webFiles });
8762

88-
core.setOutput("backendChanged", backendFiles.length > 0);
89-
core.setOutput("mobileChanged", mobileFiles.length > 0);
90-
core.setOutput("webChanged", webFiles.length > 0);
63+
core.setOutput('backendFiles', strippedBackend.join(' '));
64+
core.setOutput('mobileFiles', strippedMobile.join(' '));
65+
core.setOutput('webFiles', webFiles.map(f => f.replace('apps/web/', '')).join(' '));
66+
core.setOutput('backendTestFiles', deriveTestFiles(strippedBackend).join(' '));
67+
core.setOutput('mobileTestFiles', deriveTestFiles(strippedMobile).join(' '));
68+
core.setOutput('backendChanged', backendFiles.length > 0);
69+
core.setOutput('mobileChanged', mobileFiles.length > 0);
70+
core.setOutput('webChanged', webFiles.length > 0);
9171

9272
} catch (error) {
9373
console.error(error);

.github/scripts/commentResults.js

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,60 @@ module.exports = async ({
1010
mobileLint,
1111
mobileTest,
1212
webCheck,
13-
webBuild
13+
webBuild,
14+
backendLintOutput,
15+
mobileLintOutput,
1416
}) => {
1517
const owner = context.repo.owner;
1618
const repo = context.repo.repo;
1719
const prNumber = context.payload.pull_request.number;
1820

19-
const emoji = (status) => {
20-
if (status === 'success') return '';
21-
if (status === 'failure') return '';
22-
if (status === 'skipped') return '⏭️';
23-
return '';
21+
const status = (s) => {
22+
if (s === 'success') return 'PASS';
23+
if (s === 'failure') return 'FAIL';
24+
if (s === 'skipped') return 'SKIP';
25+
return '-';
2426
};
2527

26-
const label = (status) => {
27-
if (!status) return '⚪ unknown';
28-
return `${emoji(status)} ${status}`;
28+
const lintDetails = (output) => {
29+
if (!output || !output.trim()) return '';
30+
return `\n<details>\n<summary>View lint errors</summary>\n\n\`\`\`\n${output.trim()}\n\`\`\`\n</details>`;
2931
};
3032

31-
const anyFailure = [
32-
backend,
33-
mobile,
34-
web
35-
].includes('failure');
36-
37-
const title = anyFailure
38-
? '❌ Some checks failed'
39-
: '✅ CI completed';
40-
33+
const anyFailure = [backend, mobile, web].includes('failure');
34+
const title = anyFailure ? 'CI — Checks Failed' : 'CI — All Checks Passed';
4135
const timestamp = new Date().toUTCString();
4236

43-
const body = `## CI Results — ${title}
37+
const body = `## ${title}
38+
39+
### Backend — ${status(backend)}
4440
45-
### 🖥️ Backend (${label(backend)})
46-
| Check | Status |
41+
| Check | Result |
4742
|---|---|
48-
| Lint | ${label(backendLint)} |
49-
| Test | ${label(backendTest)} |
50-
| Typecheck | ${label(backendTypecheck)} |
43+
| Lint | ${status(backendLint)} |
44+
| Test | ${status(backendTest)} |
45+
| Typecheck | ${status(backendTypecheck)} |
46+
${backendLint === 'failure' ? lintDetails(backendLintOutput) : ''}
5147
52-
### 📱 Mobile (${label(mobile)})
53-
| Check | Status |
48+
### Mobile — ${status(mobile)}
49+
50+
| Check | Result |
5451
|---|---|
55-
| Lint | ${label(mobileLint)} |
56-
| Test | ${label(mobileTest)} |
52+
| Lint | ${status(mobileLint)} |
53+
| Test | ${status(mobileTest)} |
54+
${mobileLint === 'failure' ? lintDetails(mobileLintOutput) : ''}
55+
56+
### Web — ${status(web)}
5757
58-
### 🌐 Web (${label(web)})
59-
| Check | Status |
58+
| Check | Result |
6059
|---|---|
61-
| Check | ${label(webCheck)} |
62-
| Build | ${label(webBuild)} |
60+
| Check | ${status(webCheck)} |
61+
| Build | ${status(webBuild)} |
6362
6463
---
65-
🕐 Last updated: \`${timestamp}\``;
64+
Last updated: \`${timestamp}\``;
6665

67-
const COMMENT_MARKER = '## CI Results —';
66+
const COMMENT_MARKER = '## CI —';
6867

6968
try {
7069
const comments = await github.paginate(

.github/workflows/ci.yml

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
outputs:
15-
backendChanged: ${{ steps.detect.outputs.backendChanged }}
16-
mobileChanged: ${{ steps.detect.outputs.mobileChanged }}
17-
webChanged: ${{ steps.detect.outputs.webChanged }}
18-
backendFiles: ${{ steps.detect.outputs.backendFiles }}
19-
mobileFiles: ${{ steps.detect.outputs.mobileFiles }}
20-
webFiles: ${{ steps.detect.outputs.webFiles }}
21-
backendTests: ${{ steps.detect.outputs.backendTests }}
15+
backendChanged: ${{ steps.detect.outputs.backendChanged }}
16+
mobileChanged: ${{ steps.detect.outputs.mobileChanged }}
17+
webChanged: ${{ steps.detect.outputs.webChanged }}
18+
backendFiles: ${{ steps.detect.outputs.backendFiles }}
19+
mobileFiles: ${{ steps.detect.outputs.mobileFiles }}
20+
webFiles: ${{ steps.detect.outputs.webFiles }}
21+
backendTestFiles: ${{ steps.detect.outputs.backendTestFiles }}
22+
mobileTestFiles: ${{ steps.detect.outputs.mobileTestFiles }}
2223

2324
steps:
2425
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
26+
with:
27+
ref: ${{ github.event.pull_request.head.sha }}
28+
2529

2630
- name: Detect changed files
2731
id: detect
@@ -37,13 +41,15 @@ jobs:
3741
if: needs.detect-changes.outputs.backendChanged == 'true'
3842
runs-on: ubuntu-latest
3943

40-
outputs:
41-
backend_lint: ${{ steps.backend_lint.outcome }}
42-
backend_test: ${{ steps.backend_test.outcome }}
43-
backend_typecheck: ${{ steps.backend_typecheck.outcome }}
44+
outputs:
45+
lint_result: ${{ steps.backend_lint.outcome }}
46+
test_result: ${{ steps.backend_test.outcome }}
47+
typecheck_result: ${{ steps.backend_typecheck.outcome }}
4448

4549
steps:
4650
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
51+
with:
52+
ref: ${{ github.event.pull_request.head.sha }}
4753

4854
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
4955
with:
@@ -55,21 +61,25 @@ jobs:
5561

5662
- name: Backend lint
5763
id: backend_lint
58-
continue-on-error: true
64+
continue-on-error: true
5965
run: cd apps/backend && pnpm eslint ${{ needs.detect-changes.outputs.backendFiles }}
6066

6167
- name: Backend test
6268
id: backend_test
69+
if: needs.detect-changes.outputs.backendTestFiles != ''
6370
continue-on-error: true
64-
run: cd apps/backend && pnpm test ${{ needs.detect-changes.outputs.backendTests }}
71+
run: cd apps/backend && pnpm test --passWithNoTests ${{ needs.detect-changes.outputs.backendTestFiles }}
6572

6673
- name: Backend typecheck
6774
id: backend_typecheck
6875
continue-on-error: true
69-
run: cd apps/backend && pnpm typecheck ${{ needs.detect-changes.outputs.backendFiles }}
76+
run: cd apps/backend && pnpm typecheck
7077

71-
- name: Fail backend if checks failed
72-
if: steps.backend_lint.outcome == 'failure' || steps.backend_test.outcome == 'failure' || steps.backend_typecheck.outcome == 'failure'
78+
- name: Fail job if any check failed
79+
if: >
80+
steps.backend_lint.outcome == 'failure' ||
81+
steps.backend_test.outcome == 'failure' ||
82+
steps.backend_typecheck.outcome == 'failure'
7383
run: exit 1
7484

7585
web-ci:
@@ -78,11 +88,13 @@ jobs:
7888
runs-on: ubuntu-latest
7989

8090
outputs:
81-
web_check: ${{ steps.web_check.outcome }}
82-
web_build: ${{ steps.web_build.outcome }}
91+
check_result: ${{ steps.web_check.outcome }}
92+
build_result: ${{ steps.web_build.outcome }}
8393

8494
steps:
8595
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
96+
with:
97+
ref: ${{ github.event.pull_request.head.sha }}
8698

8799
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
88100
with:
@@ -102,8 +114,10 @@ jobs:
102114
continue-on-error: true
103115
run: cd apps/web && pnpm build
104116

105-
- name: Fail web if checks failed
106-
if: steps.web_check.outcome == 'failure' || steps.web_build.outcome == 'failure'
117+
- name: Fail job if any check failed
118+
if: >
119+
steps.web_check.outcome == 'failure' ||
120+
steps.web_build.outcome == 'failure'
107121
run: exit 1
108122

109123
mobile-ci:
@@ -112,11 +126,13 @@ jobs:
112126
runs-on: ubuntu-latest
113127

114128
outputs:
115-
mobile_lint: ${{ steps.mobile_lint.outcome }}
116-
mobile_test: ${{ steps.mobile_test.outcome }}
129+
lint_result: ${{ steps.mobile_lint.outcome }}
130+
test_result: ${{ steps.mobile_test.outcome }}
117131

118132
steps:
119133
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
134+
with:
135+
ref: ${{ github.event.pull_request.head.sha }}
120136

121137
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
122138
with:
@@ -133,11 +149,14 @@ jobs:
133149

134150
- name: Mobile test
135151
id: mobile_test
152+
if: needs.detect-changes.outputs.mobileTestFiles != ''
136153
continue-on-error: true
137-
run: cd apps/mobile && pnpm test
154+
run: cd apps/mobile && pnpm test --passWithNoTests ${{ needs.detect-changes.outputs.mobileTestFiles }}
138155

139-
- name: Fail mobile if checks failed
140-
if: steps.mobile_lint.outcome == 'failure' || steps.mobile_test.outcome == 'failure'
156+
- name: Fail job if any check failed
157+
if: >
158+
steps.mobile_lint.outcome == 'failure' ||
159+
steps.mobile_test.outcome == 'failure'
141160
run: exit 1
142161

143162
comment-results:
@@ -157,22 +176,17 @@ jobs:
157176
github-token: ${{ secrets.GITHUB_TOKEN }}
158177
script: |
159178
const script = require('./.github/scripts/commentResults.js');
160-
161179
await script({
162180
github,
163181
context,
164-
165-
backend: '${{ needs.backend-ci.result }}',
166-
web: '${{ needs.web-ci.result }}',
167-
mobile: '${{ needs.mobile-ci.result }}',
168-
169-
backendLint: '${{ needs.backend-ci.outputs.backend_lint }}',
170-
backendTest: '${{ needs.backend-ci.outputs.backend_test }}',
171-
backendTypecheck: '${{ needs.backend-ci.outputs.backend_typecheck }}',
172-
173-
mobileLint: '${{ needs.mobile-ci.outputs.mobile_lint }}',
174-
mobileTest: '${{ needs.mobile-ci.outputs.mobile_test }}',
175-
176-
webCheck: '${{ needs.web-ci.outputs.web_check }}',
177-
webBuild: '${{ needs.web-ci.outputs.web_build }}'
178-
});
182+
backend: '${{ needs.backend-ci.result }}',
183+
web: '${{ needs.web-ci.result }}',
184+
mobile: '${{ needs.mobile-ci.result }}',
185+
backendLint: '${{ needs.backend-ci.outputs.lint_result }}',
186+
backendTest: '${{ needs.backend-ci.outputs.test_result }}',
187+
backendTypecheck: '${{ needs.backend-ci.outputs.typecheck_result }}',
188+
webCheck: '${{ needs.web-ci.outputs.check_result }}',
189+
webBuild: '${{ needs.web-ci.outputs.build_result }}',
190+
mobileLint: '${{ needs.mobile-ci.outputs.lint_result }}',
191+
mobileTest: '${{ needs.mobile-ci.outputs.test_result }}',
192+
});

0 commit comments

Comments
 (0)