Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add workflows for build and lint #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
79 changes: 79 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Build and Test

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- '**' # This matches all branch names
push:
branches:
- main
- dev

permissions:
contents: read
pull-requests: read

jobs:
build:
name: Build and test
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- name: Check out Git repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Cache build
uses: actions/cache@v3
with:
path: |
build
dist
.cache
key: ${{ runner.os }}-build-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
restore-keys: |
${{ runner.os }}-build-${{ hashFiles('**/package-lock.json') }}-

- name: Build project
run: npm run build
env:
CI: true

- name: Check for test script
id: test-script
run: |
if grep -q "\"test\":" package.json; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi

- name: Run tests
if: steps.test-script.outputs.exists == 'true'
run: npm test
env:
CI: true

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: build-artifacts
path: |
build
dist
retention-days: 7
84 changes: 84 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Lint

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- '**' # This matches all branch names
push:
branches:
- main
- dev

permissions:
contents: read
pull-requests: read

jobs:
lint:
name: Run linters
runs-on: ubuntu-latest

steps:
- name: Check out Git repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Cache eslint results
uses: actions/cache@v3
with:
path: .eslintcache
key: ${{ runner.os }}-eslint-${{ hashFiles('**/.eslintrc.*') }}
restore-keys: |
${{ runner.os }}-eslint-

- name: Check for ESLint config
id: eslint-config
run: |
if [ -f ".eslintrc.js" ] || [ -f ".eslintrc.json" ] || [ -f ".eslintrc.yaml" ] || [ -f ".eslintrc.yml" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi

- name: Run ESLint
if: steps.eslint-config.outputs.exists == 'true'
run: npm run lint
continue-on-error: false

- name: Check for Prettier config
id: prettier-config
run: |
if [ -f ".prettierrc" ] || [ -f ".prettierrc.js" ] || [ -f ".prettierrc.json" ] || [ -f ".prettierrc.yaml" ] || [ -f ".prettierrc.yml" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi

- name: Run Prettier check
if: steps.prettier-config.outputs.exists == 'true'
run: npm run format:check || npm run prettier:check
continue-on-error: false

- name: Check TypeScript configuration
id: typescript-config
run: |
if [ -f "tsconfig.json" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi

- name: Run TypeScript type check
if: steps.typescript-config.outputs.exists == 'true'
run: npm run type-check || npx tsc --noEmit
Loading