Skip to content

Commit

Permalink
feat: setup husky and workflows (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shurtu-gal authored Oct 27, 2023
1 parent 1999d92 commit 5f22fba
Show file tree
Hide file tree
Showing 6 changed files with 385 additions and 9 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Development CI/CD

on:
pull_request:
branches: [main]
types: [opened, synchronize, reopened, edited, ready_for_review]

jobs:
# Currently, not needed as netlify is used for deployment
# build:
# uses: ./.github/workflows/build.yml
# with:
# fail-on-error: true

prettier:
# needs: build
uses: ./.github/workflows/prettier.yml
with:
fail-on-error: true

eslint:
# needs: build
uses: ./.github/workflows/eslint.yml
with:
fail-on-error: true
47 changes: 47 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Eslint Check

on:
workflow_call:
inputs:
fail-on-error:
description: 'Fail on error'
required: false
default: false
type: boolean

jobs:
eslint:
name: Eslint Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'

- name: Use Dev Cache
id: dev-cache
uses: actions/cache@v3
env:
cache-name: cache-dev
with:
# Path for node_modules
path: '**/node_modules'
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{steps.dev-cache.outputs.cache-hit != 'true'}}
name: Install Dependencies
run: yarn install

- name: Eslint Check
run: yarn lint:find
continue-on-error: ${{ github.event.inputs.fail-on-error != 'true'}}
47 changes: 47 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Prettier Check

on:
workflow_call:
inputs:
fail-on-error:
description: 'Fail on error'
required: false
default: false
type: boolean

jobs:
prettier:
name: Prettier Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
cache-dependency-path: '**/yarn.lock'

- name: Use Dev Cache
id: dev-cache
uses: actions/cache@v3
env:
cache-name: cache-dev
with:
# Path for node_modules
path: '**/node_modules'
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{steps.dev-cache.outputs.cache-hit != 'true'}}
name: Install Dependencies
run: yarn install

- name: Prettier Check
run: yarn prettier:check
continue-on-error: ${{ !inputs.fail-on-error }}
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"prettier:fix": "npx prettier --write ./src",
"prettier:check": "npx prettier --check ./src",
"lint:fix": "npx eslint --fix 'src/**/*.{js,jsx,ts,tsx,json,md}'",
"lint:find": "npx eslint 'src/**/*.{js,jsx,ts,tsx,json,md}'"
"lint:find": "npx eslint 'src/**/*.{js,jsx,ts,tsx,json,md}'",
"prepare": "husky install"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.35",
Expand Down Expand Up @@ -87,7 +88,18 @@
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"gatsby-plugin-postcss": "^4.7.1",
"husky": "^8.0.3",
"lint-staged": "^15.0.2",
"postcss": "^8.3.5",
"prettier": "^2.3.1"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,md}": [
"prettier --write",
"eslint --fix"
],
"*.{css,scss,json}": [
"prettier --write"
]
}
}
Loading

0 comments on commit 5f22fba

Please sign in to comment.