Skip to content

Commit 37c11e3

Browse files
authored
Merge pull request #24 from bartstc/chore/ci-coverage-report
chore: publish coverage report
2 parents 8f73e95 + 7ef4dee commit 37c11e3

5 files changed

Lines changed: 90 additions & 28 deletions

File tree

.github/workflows/ci.yml

Lines changed: 86 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ on:
44
push:
55
branches:
66
- core
7+
- basic
78
pull_request:
89
branches:
910
- core
11+
- basic
12+
13+
env:
14+
NODE_VERSION: "22.x"
1015

1116
jobs:
1217
lint-tests:
@@ -17,17 +22,20 @@ jobs:
1722

1823
unit-tests:
1924
runs-on: ubuntu-latest
25+
26+
# For every direct push to target branches or when it's active PR
27+
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
2028
steps:
2129
- name: Checkout
2230
uses: actions/checkout@v4
2331

2432
- name: Enable corepack
2533
run: corepack enable
2634

27-
- name: Install Node.js
35+
- name: Setup Node.js
2836
uses: actions/setup-node@v4
2937
with:
30-
node-version: "22.x"
38+
node-version: ${{ env.NODE_VERSION }}
3139
cache: "pnpm"
3240

3341
- name: Get pnpm store directory
@@ -54,31 +62,40 @@ jobs:
5462
run: pnpm test:ci
5563

5664
- name: Upload test results
57-
if: always()
65+
if: success() || failure()
5866
uses: actions/upload-artifact@v4
5967
with:
60-
name: Unit tests results
68+
name: unit-test-results
6169
path: reports/**/*
6270

71+
- name: Upload coverage report
72+
if: success() || failure()
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: unit-coverage-report
76+
path: coverage/**/*
77+
6378
storybook-tests:
6479
runs-on: ubuntu-latest
80+
env:
81+
STORYBOOK_DISABLE_TELEMETRY: 1
82+
STORYBOOK: "true"
83+
CI: true
84+
85+
# For every direct push to target branches or when it's active PR
86+
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
6587
steps:
6688
- name: Checkout
6789
uses: actions/checkout@v4
6890

69-
- name: Install pnpm
70-
uses: pnpm/action-setup@v2
71-
id: pnpm-install
72-
with:
73-
version: 10.6.1
74-
run_install: false
91+
- name: Enable corepack
92+
run: corepack enable
7593

76-
# https://github.com/storybookjs/test-runner/issues/301
77-
# - name: Install Node.js
78-
# uses: actions/setup-node@v3
79-
# with:
80-
# node-version: "16.x"
81-
# cache: "pnpm"
94+
- name: Setup Node.js
95+
uses: actions/setup-node@v4
96+
with:
97+
node-version: ${{ env.NODE_VERSION }}
98+
cache: "pnpm"
8299

83100
- name: Get pnpm store directory
84101
id: pnpm-cache
@@ -107,18 +124,22 @@ jobs:
107124
run: |
108125
pnpm exec concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
109126
"pnpm exec http-server storybook-static --port 6006 --silent" \
110-
"pnpm exec wait-on tcp:6006 && pnpm exec test-storybook --coverage --junit"
127+
"pnpm exec wait-on tcp:6006 && pnpm exec test-storybook --coverage --coverageDirectory=coverage --excludeTags=\"!test\" --junit --outputFile reports/storybook-report.json"
111128
112-
- name: Move Storybook coverage report and cleanup
113-
run: |
114-
mv coverage/storybook/coverage-storybook.json reports/storybook-coverage.json && rm -rf coverage
115-
116-
- name: Upload Storybook report artifacts
129+
- name: Upload test results
130+
if: success() || failure()
117131
uses: actions/upload-artifact@v4
118132
with:
119-
name: Storybook tests results
133+
name: storybook-test-results
120134
path: reports/**/*
121135

136+
- name: Upload coverage report
137+
if: success() || failure()
138+
uses: actions/upload-artifact@v4
139+
with:
140+
name: storybook-coverage-report
141+
path: coverage/**/*
142+
122143
build:
123144
needs: [lint-tests, unit-tests, storybook-tests]
124145
runs-on: ubuntu-latest
@@ -165,8 +186,49 @@ jobs:
165186
name: build
166187
path: dist
167188

189+
test-reports:
190+
needs: [unit-tests, storybook-tests]
191+
runs-on: ubuntu-latest
192+
steps:
193+
- uses: actions/checkout@v4
194+
195+
- name: Download Artifacts
196+
uses: actions/download-artifact@v4
197+
198+
- name: Generate Full Coverage Report
199+
uses: danielpalme/ReportGenerator-GitHub-Action@v5
200+
with:
201+
reports: "unit-coverage-report/lcov.info;storybook-coverage-report/lcov.info"
202+
reporttypes: "MarkdownSummaryGithub;JsonSummary;Html"
203+
targetdir: coverage-report
204+
205+
- name: Add Coverage Report Comment to PR
206+
if: github.event_name == 'pull_request'
207+
run: gh pr comment $PR_NUMBER --body-file coverage-report/SummaryGithub.md
208+
env:
209+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
210+
PR_NUMBER: ${{ github.event.number }}
211+
212+
- name: Publish Coverage Report in Build Summary
213+
run: cat coverage-report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
214+
215+
- name: Upload Full Coverage Report
216+
uses: actions/upload-artifact@v4
217+
with:
218+
name: full-coverage-report
219+
path: coverage-report/**/*
220+
221+
- name: Publish Test Results
222+
uses: dorny/test-reporter@v2
223+
id: test-reporter
224+
with:
225+
name: Test Results
226+
path: unit-test-results/**/*.xml,storybook-test-results/**/*.xml
227+
reporter: jest-junit
228+
fail-on-error: false
229+
168230
deploy:
169-
needs: build
231+
needs: [build, test-reports]
170232
runs-on: ubuntu-latest
171233
steps:
172234
- name: Get build artifacts

.storybook/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const config: StorybookConfig = {
1414
options: {
1515
istanbul: {
1616
include: ["src/**/*.tsx"],
17-
exclude: ["src/**/*.ts"],
17+
exclude: ["src/**/*.ts", "src/test-lib/*.tsx"],
1818
},
1919
} satisfies AddonOptionsVite,
2020
},

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This version is free of any libraries. If the `core` version doesn't match your
2424
- TypeScript support.
2525
- [Devcontainer](https://code.visualstudio.com/docs/devcontainers/containers) config for VS Code.
2626
- [PNPM](https://pnpm.io/) as a package manager.
27-
- CI setup (automate tests, build, deploy draft) with [GitHub Actions](https://docs.github.com/en/actions).
27+
- CI setup (tests, build, tests coverage report, deploy draft) with [GitHub Actions](https://docs.github.com/en/actions).
2828
- [Github Copilot](https://github.com/features/copilot) instructions configured for efficient chat and agent usage.
2929

3030
## Extended version - `core`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dev": "vite",
88
"build": "tsc && vite build",
99
"test": "vitest",
10-
"test:ci": "vitest run --reporter verbose --reporter=junit --outputFile=./reports/unit-report.xml",
10+
"test:ci": "vitest run --reporter verbose --reporter=junit --outputFile=./reports/unit-report.xml --coverage --coverage.reporter=lcov --coverage.reportsDirectory=./coverage",
1111
"test:coverage": "vitest run --coverage",
1212
"preview": "vite preview",
1313
"lint": "eslint . --ignore-pattern '*.d.ts' --report-unused-disable-directives --max-warnings 0",

vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default defineConfig((env) =>
2626
"**/*{.,-}stories.?(c|m)[jt]s?(x)",
2727
...coverageConfigDefaults.exclude,
2828
],
29-
reportsDirectory: "./reports",
29+
reportsDirectory: "./coverage",
3030
},
3131
},
3232
})

0 commit comments

Comments
 (0)