Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: write
pull-requests: write

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18, 20, 22]

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Setup 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: TypeScript type checking
run: npm run lint

- name: Format check
run: npm run format:check

- name: Run tests with coverage
env:
CI: true
NODE_ENV: test
run: npm run coverage

- name: Build package
run: npm run build

- name: Upload coverage reports
if: matrix.node-version == 22
uses: codecov/codecov-action@v4
with:
directory: ./coverage
name: coverage
fail_ci_if_error: false

# Auto-format job (only runs on Node 22, separate from matrix)
format:
runs-on: ubuntu-latest
needs: test
if: failure() == false

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Format code with Prettier
run: npm run format

- name: Check for formatting changes
id: verify-changed-files
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi

- name: Check if fork PR
id: check-fork
if: steps.verify-changed-files.outputs.changed == 'true'
run: |
if [ "${{ github.event_name }}" == "pull_request" ] && [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
echo "is_fork=true" >> $GITHUB_OUTPUT
else
echo "is_fork=false" >> $GITHUB_OUTPUT
fi

- name: Warn about fork PRs
if: steps.verify-changed-files.outputs.changed == 'true' && steps.check-fork.outputs.is_fork == 'true'
run: |
echo "::warning::Formatting changes detected in fork PR. Please run 'npm run format' locally and push the changes."

- name: Commit formatting changes
if: steps.verify-changed-files.outputs.changed == 'true' && steps.check-fork.outputs.is_fork == 'false'
env:
BRANCH_NAME: ${{ github.head_ref }}
REF_NAME: ${{ github.ref_name }}
run: |
set -e
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "Auto-format code with Prettier

This commit was automatically generated by GitHub Actions
to ensure consistent code formatting across the project."

if [ "${{ github.event_name }}" == "pull_request" ]; then
git push origin HEAD:"$BRANCH_NAME"
else
git push origin HEAD:"$REF_NAME"
fi
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
node_modules/
coverage/
*.md
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"printWidth": 100,
"arrowParens": "always"
}
Loading