Skip to content

Commit

Permalink
Add code coverage to PR, update node, update deps (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntharo authored Jun 11, 2024
1 parent 94ac403 commit c82f101
Show file tree
Hide file tree
Showing 10 changed files with 478 additions and 240 deletions.
33 changes: 33 additions & 0 deletions .github/actions/configure-nodejs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Configure Node.js'
description: 'Install Node.js and install Node.js modules or restore cache'

inputs:
node-version:
description: 'NodeJS Version'
default: '18'
lookup-only:
description: 'If true, only checks if cache entry exists and skips download. Does not change save cache behavior'
default: 'false'

runs:
using: 'composite'
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}

- name: Restore Node Modules from Cache
id: cache-node-modules
uses: actions/cache@v4
with:
path: |
node_modules
packages/**/node_modules
!node_modules/.cache
key: node-modules-${{ inputs.node-version }}-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package.json', 'package-lock.json', '**/package-lock.json') }}
lookup-only: ${{ inputs.lookup-only }}

- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
shell: bash
run: npm ci
41 changes: 41 additions & 0 deletions .github/actions/coverage-report/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: 'Parse Coverage and Post Comment'
description: 'Parses a coverage report and posts a comment on a PR'
inputs:
lcov-file:
description: 'Path to the lcov.info file'
required: true
title:
description: 'Title of the comment'
default: 'Code Coverage Report'

runs:
using: 'composite'
steps:
- name: Parse Coverage
shell: bash
if: github.event_name == 'pull_request'
id: parse
run: |
./scripts/parse-coverage.js ${{ inputs.lcov-file }} > coverage-summary.txt
echo "coverage-summary<<EOF" >> $GITHUB_OUTPUT
cat coverage-summary.txt >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Find Coverage Comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '### 📊 ${{ inputs.title }}'

- name: Post Coverage Comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
issue-number: ${{ github.event.pull_request.number }}
body: |
### 📊 ${{ inputs.title }}
${{ steps.parse.outputs.coverage-summary }}
37 changes: 29 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,33 @@ on:
- main

jobs:
build:
check-access:
runs-on: ubuntu-latest
outputs:
has-token-access: ${{ steps.check.outputs.has-token-access }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- id: check
run: |
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
- name: Use Node.js 16
uses: actions/setup-node@v3
install-deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/configure-nodejs
with:
node-version: 16
lookup-only: 'true' # We only want to lookup from the cache - if a hit, this job does nothing

- name: Install Modules
run: npm ci
build:
needs:
- install-deps
- check-access
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: ./.github/actions/configure-nodejs

- name: Build
run: npm run build
Expand All @@ -34,3 +48,10 @@ jobs:

- name: Test
run: npm run test

- name: Upload code coverage
if: github.event_name == 'pull_request' && needs.check-access.outputs.has-token-access == 'true'
uses: ./.github/actions/coverage-report
with:
lcov-file: coverage/lcov.info
title: Node.js Code Coverage Report
19 changes: 11 additions & 8 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ on:
workflow_dispatch:

jobs:
install-deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/configure-nodejs
with:
lookup-only: 'true' # We only want to lookup from the cache - if a hit, this job does nothing

build:
needs: install-deps
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
uses: actions/checkout@v4

- name: Install Modules
run: npm ci
- uses: ./.github/actions/configure-nodejs

- name: Build Docs
run: npm run build:docs
Expand Down
19 changes: 11 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ on:
types: [published]

jobs:
install-deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/configure-nodejs
with:
lookup-only: 'true' # We only want to lookup from the cache - if a hit, this job does nothing

build:
needs: install-deps
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
- uses: ./.github/actions/configure-nodejs

- name: Use the Release Tag Version
run: |
npm version from-git --allow-same-version --no-git-tag-version
- name: Install Modules
run: npm ci

- name: Build
run: npm run build

Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.17.1
v18
6 changes: 2 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
// "lcov",
// "clover"
// ],
coverageReporters: ['html', 'text'],
coverageReporters: ['lcov', 'html', 'text'],

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,
Expand Down Expand Up @@ -130,9 +130,7 @@ module.exports = {
// roots: [
// "<rootDir>"
// ],
roots: [
'<rootDir>src/',
],
roots: ['<rootDir>src/'],

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

0 comments on commit c82f101

Please sign in to comment.