name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
permissions:
contents: write
pages: write
id-token: write
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Check formatting
run: npm run format:check
- name: Build
run: npm run build
- name: Run unit tests
run: npm run test:unit
- name: Generate coverage report
if: matrix.node-version == '18.x'
run: npm run test:coverage -- --testPathIgnorePatterns=integration --testPathIgnorePatterns=examples
- name: Upload coverage reports
if: matrix.node-version == '18.x'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage/
- name: Update coverage gist
if: matrix.node-version == '18.x'
env:
GIST_SECRET: ${{ secrets.GIST_SECRET }}
run: |
# Extract coverage percentage from lcov.info
COVERAGE=$(awk -F: '/^SF:/{files++} /^LF:/{lines+=$2} /^LH:/{hits+=$2} END {printf "%.0f", (hits/lines)*100}' coverage/lcov.info)
# Determine color based on coverage
if [ $COVERAGE -ge 90 ]; then COLOR="brightgreen"
elif [ $COVERAGE -ge 70 ]; then COLOR="green"
elif [ $COVERAGE -ge 50 ]; then COLOR="yellow"
elif [ $COVERAGE -ge 30 ]; then COLOR="orange"
else COLOR="red"; fi
# Update gist
echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${COVERAGE}%\",\"color\":\"${COLOR}\"}" > coverage.json
gh auth login --with-token <<< "$GIST_SECRET"
gh gist edit e2abffb0deb25afa2bf9185f440dae81 coverage.json
- name: Deploy coverage to GitHub Pages
if: matrix.node-version == '18.x' && github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./coverage/lcov-report
destination_dir: coverage