Skip to content

Commit 2225215

Browse files
authored
chore: add prettier, commitlint & lefthook (#520)
* chore: add prettier * chore: add commitlint * chore: add lefthook * ci: add github actions workflow for commitlint * ci: add actionlint.yaml * ci: fix
1 parent fed45e0 commit 2225215

9 files changed

+1507
-49
lines changed

.github/actionlint.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
self-hosted-runner:
2+
labels:
3+
- buildjet-2vcpu-ubuntu-2004

.github/workflows/commitlint.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
on:
2+
pull_request:
3+
types: [synchronize, edited, opened]
4+
5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.ref }}
7+
cancel-in-progress: true
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- uses: actions/setup-node@v1
18+
with:
19+
node-version: 20.6.0
20+
21+
- name: npm install
22+
run: npm ci
23+
24+
- name: Lint commit messages
25+
run: npx commitlint --from $BASE_SHA --to $HEAD_SHA --verbose
26+
env:
27+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
28+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
29+
30+
- name: Lint pull request title
31+
run: echo $PR_TITLE | npx commitlint --verbose
32+
env:
33+
PR_TITLE: ${{ github.event.pull_request.title }}

.github/workflows/main.yml

+24-24
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ jobs:
1111
matrix:
1212
node-version: [20.6.0]
1313
services:
14-
storage-ftp:
15-
image: garethflowers/ftp-server:0.7.0
16-
env:
17-
FTP_USER: user
18-
FTP_PASS: '123'
19-
ports:
20-
- "20-21:20-21"
21-
- "40000-40009:40000-40009"
22-
storage-sftp:
23-
image: atmoz/sftp:alpine
24-
env:
25-
SFTP_USERS: user:123:::upload
26-
ports:
27-
- "2222:22"
14+
storage-ftp:
15+
image: garethflowers/ftp-server:0.7.0
16+
env:
17+
FTP_USER: user
18+
FTP_PASS: '123'
19+
ports:
20+
- '20-21:20-21'
21+
- '40000-40009:40000-40009'
22+
storage-sftp:
23+
image: atmoz/sftp:alpine
24+
env:
25+
SFTP_USERS: user:123:::upload
26+
ports:
27+
- '2222:22'
2828
steps:
2929
- uses: actions/checkout@v2
3030
- name: Use Node.js ${{ matrix.node-version }}
@@ -92,7 +92,7 @@ jobs:
9292
strategy:
9393
matrix:
9494
node-version: [20.6.0]
95-
postgres-version: [ 14 ]
95+
postgres-version: [14]
9696
services:
9797
postgres:
9898
image: postgres:${{ matrix.postgres-version }}
@@ -101,7 +101,7 @@ jobs:
101101
POSTGRES_PASSWORD: ''
102102
POSTGRES_HOST_AUTH_METHOD: trust
103103
ports:
104-
- "5432:5432"
104+
- '5432:5432'
105105
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
106106
steps:
107107
- uses: actions/checkout@v2
@@ -112,7 +112,7 @@ jobs:
112112
- name: Cache node_modules
113113
uses: actions/cache@v1
114114
with:
115-
path: "**/node_modules"
115+
path: '**/node_modules'
116116
key: ${{ runner.os }}-postgres-node_modules-${{ hashFiles('**/package-lock.json') }}
117117
- name: npm install
118118
run: npm ci
@@ -131,16 +131,16 @@ jobs:
131131
strategy:
132132
matrix:
133133
node-version: [20.6.0]
134-
mysql-version: [ 8.0 ]
134+
mysql-version: [8.0]
135135
services:
136136
mysql:
137-
image: "mysql:${{ matrix.mysql-version }}"
137+
image: 'mysql:${{ matrix.mysql-version }}'
138138
options: >-
139139
--health-cmd "mysqladmin ping --silent"
140140
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes
141141
-e MYSQL_DATABASE=default
142142
ports:
143-
- "3306:3306"
143+
- '3306:3306'
144144
steps:
145145
- uses: actions/checkout@v2
146146
- name: Use Node.js ${{ matrix.node-version }}
@@ -150,7 +150,7 @@ jobs:
150150
- name: Cache node_modules
151151
uses: actions/cache@v1
152152
with:
153-
path: "**/node_modules"
153+
path: '**/node_modules'
154154
key: ${{ runner.os }}-mysql-node_modules-${{ hashFiles('**/package-lock.json') }}
155155
- name: npm install
156156
run: npm ci
@@ -178,7 +178,7 @@ jobs:
178178
- name: Cache node_modules
179179
uses: actions/cache@v1
180180
with:
181-
path: "**/node_modules"
181+
path: '**/node_modules'
182182
key: ${{ runner.os }}-sqlite-node_modules-${{ hashFiles('**/package-lock.json') }}
183183
- name: npm install
184184
run: npm ci
@@ -197,7 +197,7 @@ jobs:
197197
strategy:
198198
matrix:
199199
node-version: [20.6.0]
200-
mongo-version: [ 4.0 ]
200+
mongo-version: [4.0]
201201
services:
202202
# this is used for the simple-auth test
203203
mongo:
@@ -224,7 +224,7 @@ jobs:
224224
- name: Cache node_modules
225225
uses: actions/cache@v1
226226
with:
227-
path: "**/node_modules"
227+
path: '**/node_modules'
228228
key: ${{ runner.os }}-mongo-node_modules-${{ hashFiles('**/package-lock.json') }}
229229
- name: npm install
230230
run: npm ci

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
legacy-peer-deps=true

.prettierrc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"plugins": ["@trivago/prettier-plugin-sort-imports"],
3+
"trailingComma": "all",
4+
"bracketSpacing": true,
5+
"tabWidth": 2,
6+
"singleQuote": true,
7+
"arrowParens": "avoid",
8+
"endOfLine": "lf",
9+
"importOrderSeparation": true,
10+
"importOrderSortSpecifiers": true,
11+
"overrides": [
12+
{
13+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
14+
"options": {
15+
"tabWidth": 4
16+
}
17+
}
18+
]
19+
}

commitlint.config.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const {
2+
utils: { getPackages },
3+
} = require('@commitlint/config-lerna-scopes');
4+
5+
const customScopes = ['deps'];
6+
7+
module.exports = {
8+
extends: ['@commitlint/config-conventional', '@commitlint/config-lerna-scopes'],
9+
ignores: [
10+
message =>
11+
message.startsWith('Merge') ||
12+
message.startsWith('Revert'),
13+
],
14+
rules: {
15+
'header-max-length': [0, 'always', 125],
16+
'footer-max-line-length': [0, 'always', Infinity],
17+
'body-max-line-length': [0, 'always', Infinity],
18+
'scope-enum': async ctx => [
19+
2,
20+
'always',
21+
[...customScopes, ...(await getPackages(ctx))],
22+
],
23+
},
24+
};

lefthook.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md
2+
commit-msg:
3+
commands:
4+
commitlint:
5+
run: npx commitlint --edit {1}
6+
pre-commit:
7+
commands:
8+
github-actions:
9+
glob: '*.{yaml,yml}'
10+
root: '.github'
11+
run: echo {staged_files} && actionlint
12+
prettier:
13+
glob: '[*.{json,yml,yaml,html,ts,tsx,js,jsx},!./package-lock.json]'
14+
run: npx prettier --write {staged_files} && git add {staged_files}

0 commit comments

Comments
 (0)