Skip to content

Commit 7ba3b51

Browse files
ci: Add Semantic release and linters [DEV-4801] (#273)
* Move tsconfig * Update package.json * Update .prettierignore * run format * Update package.json * bump packages * Update pull-request.yml * Create build.yml * Create staging.yml * add release * Update dispatch.yml * Replace linter file * renasme file * Update lint.yml * Update lint.yml * Switch to YAML * New file extension * Trying again * Create eslint.config.mjs * Fix eslint issue * Delete eslint.config.mjs * Update package.json * keep linter in root * Move eslint to root * Update lint.yml * Try switching config around * move again * Add DB migrations && set default success filter * Add semantic release configuration file * Fix incorrect path in migrations.yml file --------- Co-authored-by: filipdjokic <djokicf@protonmail.com>
1 parent 5d01d69 commit 7ba3b51

22 files changed

Lines changed: 14587 additions & 8262 deletions

.github/linters/.eslintrc.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/linters/eslint.config.mjs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { FlatCompat } from '@eslint/eslintrc';
2+
import js from '@eslint/js';
3+
import tsParser from '@typescript-eslint/parser';
4+
import typescriptEslint from '@typescript-eslint/eslint-plugin';
5+
import drizzle from 'eslint-plugin-drizzle';
6+
import globals from 'globals';
7+
import path from 'node:path';
8+
import { fileURLToPath } from 'node:url';
9+
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = path.dirname(__filename);
12+
const compat = new FlatCompat({
13+
baseDirectory: __dirname,
14+
recommendedConfig: js.configs.recommended,
15+
allConfig: js.configs.all,
16+
});
17+
18+
export default [
19+
...compat.extends(
20+
'eslint:recommended',
21+
'plugin:@typescript-eslint/recommended',
22+
'plugin:prettier/recommended',
23+
'plugin:drizzle/recommended'
24+
),
25+
{
26+
ignores: ['build/', 'dist/', 'node_nodules/', '.wrangler/', '*.ignore'],
27+
},
28+
{
29+
plugins: {
30+
'@typescript-eslint': typescriptEslint,
31+
drizzle,
32+
},
33+
languageOptions: {
34+
globals: {
35+
...globals.node,
36+
},
37+
parser: tsParser,
38+
ecmaVersion: 2018,
39+
sourceType: 'module',
40+
},
41+
rules: {
42+
'drizzle/enforce-delete-with-where': ['error', { drizzleObjectName: ['dbClient', 'db'] }],
43+
'drizzle/enforce-update-with-where': ['error', { drizzleObjectName: ['dbClient', 'db'] }],
44+
'@typescript-eslint/no-unused-vars': [
45+
'error',
46+
{
47+
args: 'all',
48+
argsIgnorePattern: '^_',
49+
caughtErrors: 'all',
50+
caughtErrorsIgnorePattern: '^_',
51+
destructuredArrayIgnorePattern: '^_',
52+
varsIgnorePattern: '^_',
53+
ignoreRestSiblings: true,
54+
},
55+
],
56+
},
57+
},
58+
];

.github/workflows/build.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "Build & Test"
2+
on:
3+
workflow_call:
4+
defaults:
5+
run:
6+
shell: bash
7+
8+
jobs:
9+
build:
10+
name: "Build Node.js"
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- uses: actions/setup-node@v4
17+
with:
18+
node-version: 20
19+
cache: "npm"
20+
21+
- name: "Execute build"
22+
run: |
23+
npm ci
24+
npm run build

.github/workflows/dispatch.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
name: "Workflow Dispatch"
22
on: push
3-
concurrency:
3+
concurrency:
44
group: ${{ github.workflow }}-${{ github.ref }}
55
cancel-in-progress: true
66

77
jobs:
8-
8+
99
call-lint:
1010
name: "Lint"
1111
uses: ./.github/workflows/lint.yml
1212

13-
call-deploy:
14-
name: "Deploy"
15-
needs: call-lint
16-
uses: ./.github/workflows/deploy.yml
13+
call-build:
14+
name: "Build & Test"
15+
uses: ./.github/workflows/build.yml
16+
17+
call-staging:
18+
name: "Deploy staging"
19+
if: ${{ github.ref_name != 'main' }}
20+
needs: [call-lint, call-build]
21+
uses: ./.github/workflows/staging.yml
22+
secrets: inherit
23+
24+
call-release:
25+
name: "Release"
26+
if: ${{ github.ref_protected == true }}
27+
needs: [call-lint, call-build]
28+
uses: ./.github/workflows/release.yml
1729
secrets: inherit

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ jobs:
3535
env:
3636
IGNORE_GITIGNORED_FILES: true
3737
DEFAULT_BRANCH: main
38-
LINTER_RULES_PATH: '.github/linters'
3938
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4039
LOG_LEVEL: WARN
4140
VALIDATE_ALL_CODEBASE: true
@@ -44,6 +43,7 @@ jobs:
4443
VALIDATE_GITHUB_ACTIONS: true
4544
VALIDATE_JAVASCRIPT_ES: true
4645
VALIDATE_JSONC: true
46+
VALIDATE_JSX: true
4747
VALIDATE_MARKDOWN: true
4848
VALIDATE_TSX: true
4949
VALIDATE_TYPESCRIPT_ES: true

.github/workflows/migrations.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: "Database migrations"
2+
on:
3+
workflow_dispatch:
4+
push:
5+
paths:
6+
- "src/database/migrations/*"
7+
branches:
8+
- develop
9+
- main
10+
defaults:
11+
run:
12+
shell: bash
13+
14+
jobs:
15+
16+
staging-migrations:
17+
name: "Staging DB migrations"
18+
runs-on: ubuntu-latest
19+
if: ${{ github.ref_name == 'develop' }}
20+
environment:
21+
name: staging
22+
url: https://data-api-staging.cheqd.io
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- uses: actions/setup-node@v4
28+
with:
29+
node-version: 20
30+
cache: "npm"
31+
32+
- name: "Store DO certificate"
33+
run: echo "${DO_CERTIFICATE}" > /tmp/do-cert.pem
34+
env:
35+
DO_CERTIFICATE: ${{ secrets.DO_CERT }}
36+
37+
- name: "Execute migrations and seed the static data"
38+
run: |
39+
npm ci
40+
npm run db:migrate:ci
41+
npm run db:seed
42+
env:
43+
DB_URL: ${{ secrets.DB_URL }}
44+
45+
production-migrations:
46+
name: "Production DB migrations"
47+
runs-on: ubuntu-latest
48+
if: ${{ github.ref_name == 'main' }}
49+
environment:
50+
name: production
51+
url: https://data-api.cheqd.io
52+
53+
steps:
54+
- uses: actions/checkout@v4
55+
56+
- uses: actions/setup-node@v4
57+
with:
58+
node-version: 20
59+
cache: "npm"
60+
61+
- name: "Store DO certificate"
62+
run: echo "${DO_CERTIFICATE}" > /tmp/do-cert.pem
63+
env:
64+
DO_CERTIFICATE: ${{ secrets.DO_CERT }}
65+
66+
- name: "Execute migrations and seed the static data"
67+
run: |
68+
npm ci
69+
npm run db:migrate:ci
70+
npm run db:seed
71+
env:
72+
DB_URL: ${{ secrets.DB_URL }}

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
steps:
2424
- uses: actions/checkout@v4
2525

26-
- uses: amannn/action-semantic-pull-request@v5.5.2
26+
- uses: amannn/action-semantic-pull-request@v5
2727
env:
2828
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2929
with:
Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Deploy"
1+
name: "Release"
22
on:
33
workflow_call:
44
defaults:
@@ -7,39 +7,42 @@ defaults:
77

88
jobs:
99

10-
staging-deploy:
11-
name: "Cloudflare - Staging"
10+
release-npm:
11+
name: "Semantic Release"
1212
runs-on: ubuntu-latest
13-
environment:
14-
name: staging
15-
url: https://data-api-staging.cheqd.io/
1613

1714
steps:
1815
- uses: actions/checkout@v4
1916
with:
17+
fetch-depth: 0
2018
persist-credentials: false
21-
19+
2220
- uses: actions/setup-node@v4
2321
with:
2422
node-version: 20
25-
cache: 'npm'
26-
cache-dependency-path: '**/package-lock.json'
23+
cache: "npm"
2724

28-
- name: Publish to Cloudflare
29-
uses: cloudflare/wrangler-action@v3
25+
- name: "Obtain Github App token"
26+
id: app-token
27+
uses: getsentry/action-github-app-token@v3.0.0
3028
with:
31-
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
32-
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
33-
wranglerVersion: '3.112.0'
34-
preCommands: npm ci
35-
command: publish --env staging
36-
secrets: |
37-
WEBHOOK_URL
29+
app_id: ${{ secrets.BOT_APP_ID }}
30+
private_key: ${{ secrets.BOT_APP_PRIVATE_KEY }}
31+
32+
- name: "Clean install dependencies"
33+
run: npm ci
34+
35+
- name: "Build"
36+
run: npm run build
37+
38+
- name: "Execute Semantic Release"
39+
run: npx semantic-release
3840
env:
39-
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
41+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
42+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
4043

4144
production-deploy:
42-
name: "Cloudflare - Production"
45+
name: "Deploy Production"
4346
if: ${{ github.ref_name == 'main' }}
4447
runs-on: ubuntu-latest
4548
environment:
@@ -49,7 +52,6 @@ jobs:
4952
steps:
5053
- uses: actions/checkout@v4
5154
with:
52-
fetch-depth: 0
5355
persist-credentials: false
5456

5557
- uses: actions/setup-node@v4

.github/workflows/staging.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "Deploy Staging"
2+
on:
3+
workflow_call:
4+
defaults:
5+
run:
6+
shell: bash
7+
8+
jobs:
9+
10+
staging-deploy:
11+
name: "Cloudflare - Staging"
12+
runs-on: ubuntu-latest
13+
environment:
14+
name: staging
15+
url: https://data-api-staging.cheqd.io/
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
persist-credentials: false
21+
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: 20
25+
cache: 'npm'
26+
27+
- name: Publish to Cloudflare
28+
uses: cloudflare/wrangler-action@v3
29+
with:
30+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
31+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
32+
wranglerVersion: '3.112.0'
33+
preCommands: npm ci
34+
command: publish --env staging
35+
secrets: |
36+
WEBHOOK_URL
37+
env:
38+
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}

.prettierignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# Ignore folders
22
.DS_Store
33
.github
4-
.svelte-kit
54
node_modules
65
build
76
dist
8-
package
97
playwright
108
playwright-report
119

0 commit comments

Comments
 (0)