Skip to content

Commit c82f101

Browse files
authored
Add code coverage to PR, update node, update deps (#1)
1 parent 94ac403 commit c82f101

File tree

10 files changed

+478
-240
lines changed

10 files changed

+478
-240
lines changed

Diff for: .github/actions/configure-nodejs/action.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: 'Configure Node.js'
2+
description: 'Install Node.js and install Node.js modules or restore cache'
3+
4+
inputs:
5+
node-version:
6+
description: 'NodeJS Version'
7+
default: '18'
8+
lookup-only:
9+
description: 'If true, only checks if cache entry exists and skips download. Does not change save cache behavior'
10+
default: 'false'
11+
12+
runs:
13+
using: 'composite'
14+
steps:
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: ${{ inputs.node-version }}
18+
19+
- name: Restore Node Modules from Cache
20+
id: cache-node-modules
21+
uses: actions/cache@v4
22+
with:
23+
path: |
24+
node_modules
25+
packages/**/node_modules
26+
!node_modules/.cache
27+
key: node-modules-${{ inputs.node-version }}-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package.json', 'package-lock.json', '**/package-lock.json') }}
28+
lookup-only: ${{ inputs.lookup-only }}
29+
30+
- name: Install dependencies
31+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
32+
shell: bash
33+
run: npm ci

Diff for: .github/actions/coverage-report/action.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: 'Parse Coverage and Post Comment'
2+
description: 'Parses a coverage report and posts a comment on a PR'
3+
inputs:
4+
lcov-file:
5+
description: 'Path to the lcov.info file'
6+
required: true
7+
title:
8+
description: 'Title of the comment'
9+
default: 'Code Coverage Report'
10+
11+
runs:
12+
using: 'composite'
13+
steps:
14+
- name: Parse Coverage
15+
shell: bash
16+
if: github.event_name == 'pull_request'
17+
id: parse
18+
run: |
19+
./scripts/parse-coverage.js ${{ inputs.lcov-file }} > coverage-summary.txt
20+
echo "coverage-summary<<EOF" >> $GITHUB_OUTPUT
21+
cat coverage-summary.txt >> $GITHUB_OUTPUT
22+
echo "EOF" >> $GITHUB_OUTPUT
23+
24+
- name: Find Coverage Comment
25+
if: github.event_name == 'pull_request'
26+
uses: peter-evans/find-comment@v3
27+
id: fc
28+
with:
29+
issue-number: ${{ github.event.pull_request.number }}
30+
comment-author: 'github-actions[bot]'
31+
body-includes: '### 📊 ${{ inputs.title }}'
32+
33+
- name: Post Coverage Comment
34+
uses: peter-evans/create-or-update-comment@v4
35+
with:
36+
comment-id: ${{ steps.fc.outputs.comment-id }}
37+
edit-mode: replace
38+
issue-number: ${{ github.event.pull_request.number }}
39+
body: |
40+
### 📊 ${{ inputs.title }}
41+
${{ steps.parse.outputs.coverage-summary }}

Diff for: .github/workflows/ci.yml

+29-8
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,33 @@ on:
99
- main
1010

1111
jobs:
12-
build:
12+
check-access:
1313
runs-on: ubuntu-latest
14+
outputs:
15+
has-token-access: ${{ steps.check.outputs.has-token-access }}
1416
steps:
15-
- name: Checkout code
16-
uses: actions/checkout@v3
17+
- id: check
18+
run: |
19+
echo "has-token-access=$(if [[ '${{ github.event.pull_request.head.repo.fork }}' != 'true' && '${{ github.actor }}' != 'dependabot[bot]' ]]; then echo 'true'; else echo 'false'; fi)" >> $GITHUB_OUTPUT
1720
18-
- name: Use Node.js 16
19-
uses: actions/setup-node@v3
21+
install-deps:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: ./.github/actions/configure-nodejs
2026
with:
21-
node-version: 16
27+
lookup-only: 'true' # We only want to lookup from the cache - if a hit, this job does nothing
2228

23-
- name: Install Modules
24-
run: npm ci
29+
build:
30+
needs:
31+
- install-deps
32+
- check-access
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v4
37+
38+
- uses: ./.github/actions/configure-nodejs
2539

2640
- name: Build
2741
run: npm run build
@@ -34,3 +48,10 @@ jobs:
3448

3549
- name: Test
3650
run: npm run test
51+
52+
- name: Upload code coverage
53+
if: github.event_name == 'pull_request' && needs.check-access.outputs.has-token-access == 'true'
54+
uses: ./.github/actions/coverage-report
55+
with:
56+
lcov-file: coverage/lcov.info
57+
title: Node.js Code Coverage Report

Diff for: .github/workflows/docs.yml

+11-8
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@ on:
77
workflow_dispatch:
88

99
jobs:
10+
install-deps:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: ./.github/actions/configure-nodejs
15+
with:
16+
lookup-only: 'true' # We only want to lookup from the cache - if a hit, this job does nothing
17+
1018
build:
19+
needs: install-deps
1120
runs-on: ubuntu-latest
1221
steps:
1322
- name: Checkout code
14-
uses: actions/checkout@v3
15-
16-
- name: Use Node.js 16
17-
uses: actions/setup-node@v3
18-
with:
19-
node-version: 16
23+
uses: actions/checkout@v4
2024

21-
- name: Install Modules
22-
run: npm ci
25+
- uses: ./.github/actions/configure-nodejs
2326

2427
- name: Build Docs
2528
run: npm run build:docs

Diff for: .github/workflows/publish.yml

+11-8
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@ on:
55
types: [published]
66

77
jobs:
8+
install-deps:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: ./.github/actions/configure-nodejs
13+
with:
14+
lookup-only: 'true' # We only want to lookup from the cache - if a hit, this job does nothing
15+
816
build:
17+
needs: install-deps
918
runs-on: ubuntu-latest
1019
steps:
1120
- name: Checkout code
12-
uses: actions/checkout@v3
21+
uses: actions/checkout@v4
1322

14-
- name: Use Node.js 16
15-
uses: actions/setup-node@v3
16-
with:
17-
node-version: 16
23+
- uses: ./.github/actions/configure-nodejs
1824

1925
- name: Use the Release Tag Version
2026
run: |
2127
npm version from-git --allow-same-version --no-git-tag-version
2228
23-
- name: Install Modules
24-
run: npm ci
25-
2629
- name: Build
2730
run: npm run build
2831

Diff for: .nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v16.17.1
1+
v18

Diff for: jest.config.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = {
4242
// "lcov",
4343
// "clover"
4444
// ],
45-
coverageReporters: ['html', 'text'],
45+
coverageReporters: ['lcov', 'html', 'text'],
4646

4747
// An object that configures minimum threshold enforcement for coverage results
4848
// coverageThreshold: undefined,
@@ -130,9 +130,7 @@ module.exports = {
130130
// roots: [
131131
// "<rootDir>"
132132
// ],
133-
roots: [
134-
'<rootDir>src/',
135-
],
133+
roots: ['<rootDir>src/'],
136134

137135
// Allows you to use a custom runner instead of Jest's default test runner
138136
// runner: "jest-runner",

0 commit comments

Comments
 (0)