Skip to content

chore: add prettier, commitlint & lefthook #520

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

Merged
merged 6 commits into from
Jan 17, 2024
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
3 changes: 3 additions & 0 deletions .github/actionlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
self-hosted-runner:
labels:
- buildjet-2vcpu-ubuntu-2004
33 changes: 33 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
on:
pull_request:
types: [synchronize, edited, opened]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-node@v1
with:
node-version: 20.6.0

- name: npm install
run: npm ci

- name: Lint commit messages
run: npx commitlint --from $BASE_SHA --to $HEAD_SHA --verbose
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}

- name: Lint pull request title
run: echo $PR_TITLE | npx commitlint --verbose
env:
PR_TITLE: ${{ github.event.pull_request.title }}
48 changes: 24 additions & 24 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ jobs:
matrix:
node-version: [20.6.0]
services:
storage-ftp:
image: garethflowers/ftp-server:0.7.0
env:
FTP_USER: user
FTP_PASS: '123'
ports:
- "20-21:20-21"
- "40000-40009:40000-40009"
storage-sftp:
image: atmoz/sftp:alpine
env:
SFTP_USERS: user:123:::upload
ports:
- "2222:22"
storage-ftp:
image: garethflowers/ftp-server:0.7.0
env:
FTP_USER: user
FTP_PASS: '123'
ports:
- '20-21:20-21'
- '40000-40009:40000-40009'
storage-sftp:
image: atmoz/sftp:alpine
env:
SFTP_USERS: user:123:::upload
ports:
- '2222:22'
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
strategy:
matrix:
node-version: [20.6.0]
postgres-version: [ 14 ]
postgres-version: [14]
services:
postgres:
image: postgres:${{ matrix.postgres-version }}
Expand All @@ -101,7 +101,7 @@ jobs:
POSTGRES_PASSWORD: ''
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- "5432:5432"
- '5432:5432'
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v2
Expand All @@ -112,7 +112,7 @@ jobs:
- name: Cache node_modules
uses: actions/cache@v1
with:
path: "**/node_modules"
path: '**/node_modules'
key: ${{ runner.os }}-postgres-node_modules-${{ hashFiles('**/package-lock.json') }}
- name: npm install
run: npm ci
Expand All @@ -131,16 +131,16 @@ jobs:
strategy:
matrix:
node-version: [20.6.0]
mysql-version: [ 8.0 ]
mysql-version: [8.0]
services:
mysql:
image: "mysql:${{ matrix.mysql-version }}"
image: 'mysql:${{ matrix.mysql-version }}'
options: >-
--health-cmd "mysqladmin ping --silent"
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes
-e MYSQL_DATABASE=default
ports:
- "3306:3306"
- '3306:3306'
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -150,7 +150,7 @@ jobs:
- name: Cache node_modules
uses: actions/cache@v1
with:
path: "**/node_modules"
path: '**/node_modules'
key: ${{ runner.os }}-mysql-node_modules-${{ hashFiles('**/package-lock.json') }}
- name: npm install
run: npm ci
Expand Down Expand Up @@ -178,7 +178,7 @@ jobs:
- name: Cache node_modules
uses: actions/cache@v1
with:
path: "**/node_modules"
path: '**/node_modules'
key: ${{ runner.os }}-sqlite-node_modules-${{ hashFiles('**/package-lock.json') }}
- name: npm install
run: npm ci
Expand All @@ -197,7 +197,7 @@ jobs:
strategy:
matrix:
node-version: [20.6.0]
mongo-version: [ 4.0 ]
mongo-version: [4.0]
services:
# this is used for the simple-auth test
mongo:
Expand All @@ -224,7 +224,7 @@ jobs:
- name: Cache node_modules
uses: actions/cache@v1
with:
path: "**/node_modules"
path: '**/node_modules'
key: ${{ runner.os }}-mongo-node_modules-${{ hashFiles('**/package-lock.json') }}
- name: npm install
run: npm ci
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
legacy-peer-deps=true
19 changes: 19 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"trailingComma": "all",
"bracketSpacing": true,
"tabWidth": 2,
"singleQuote": true,
"arrowParens": "avoid",
"endOfLine": "lf",
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"options": {
"tabWidth": 4
}
}
]
}
24 changes: 24 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const {
utils: { getPackages },
} = require('@commitlint/config-lerna-scopes');

const customScopes = ['deps'];

module.exports = {
extends: ['@commitlint/config-conventional', '@commitlint/config-lerna-scopes'],
ignores: [
message =>
message.startsWith('Merge') ||
message.startsWith('Revert'),
],
rules: {
'header-max-length': [0, 'always', 125],
'footer-max-line-length': [0, 'always', Infinity],
'body-max-line-length': [0, 'always', Infinity],
'scope-enum': async ctx => [
2,
'always',
[...customScopes, ...(await getPackages(ctx))],
],
},
};
14 changes: 14 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md
commit-msg:
commands:
commitlint:
run: npx commitlint --edit {1}
pre-commit:
commands:
github-actions:
glob: '*.{yaml,yml}'
root: '.github'
run: echo {staged_files} && actionlint
prettier:
glob: '[*.{json,yml,yaml,html,ts,tsx,js,jsx},!./package-lock.json]'
run: npx prettier --write {staged_files} && git add {staged_files}
Loading