Skip to content

Commit 3f90d9d

Browse files
committed
chore: resolve merge conflict, keep monorepo files
2 parents 956fdc1 + 39f04e5 commit 3f90d9d

21 files changed

Lines changed: 822 additions & 0 deletions

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Database
2+
DATABASE_URL=postgresql://USER:PASSWORD@HOST:5432/DB?schema=post

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
9+
jobs:
10+
lint-and-build:
11+
name: Lint, Format & Build
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 20
22+
registry-url: https://npm.pkg.github.com
23+
scope: "@backendworks"
24+
cache: npm
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
env:
29+
NODE_AUTH_TOKEN: ${{ secrets.GH_TOKEN }}
30+
31+
- name: Generate Prisma client
32+
run: npx prisma generate
33+
34+
- name: Lint
35+
run: npm run lint
36+
37+
- name: Format check
38+
run: npx prettier --check "src/**/*.ts"
39+
40+
- name: Build
41+
run: npm run build

.github/workflows/deploy.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Deploy (GitHub Packages)
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_bump:
7+
description: "Version bump type"
8+
required: true
9+
default: patch
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
push:
16+
branches:
17+
- main
18+
paths:
19+
- "src/**"
20+
- "prisma/**"
21+
- "package.json"
22+
23+
permissions:
24+
contents: write
25+
packages: write
26+
27+
jobs:
28+
publish:
29+
name: Publish to GitHub Packages
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
with:
36+
token: ${{ secrets.GH_TOKEN }}
37+
fetch-depth: 0
38+
39+
- name: Setup Node
40+
uses: actions/setup-node@v4
41+
with:
42+
node-version: 20
43+
registry-url: https://npm.pkg.github.com
44+
scope: "@backendworks"
45+
cache: npm
46+
47+
- name: Install dependencies
48+
run: npm ci
49+
env:
50+
NODE_AUTH_TOKEN: ${{ secrets.GH_TOKEN }}
51+
52+
- name: Generate Prisma client
53+
run: npx prisma generate
54+
55+
- name: Build
56+
run: npm run build
57+
58+
- name: Configure git
59+
run: |
60+
git config user.name "github-actions[bot]"
61+
git config user.email "github-actions[bot]@users.noreply.github.com"
62+
63+
- name: Determine version bump
64+
id: bump
65+
run: |
66+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
67+
echo "type=${{ inputs.version_bump }}" >> $GITHUB_OUTPUT
68+
else
69+
echo "type=patch" >> $GITHUB_OUTPUT
70+
fi
71+
72+
- name: Bump version
73+
id: version
74+
run: |
75+
npm version ${{ steps.bump.outputs.type }} --no-git-tag-version
76+
VERSION=$(node -p "require('./package.json').version")
77+
echo "new_version=$VERSION" >> $GITHUB_OUTPUT
78+
79+
- name: Commit and tag version
80+
run: |
81+
git add package.json
82+
git commit -m "chore(release): @backendworks/post-db@${{ steps.version.outputs.new_version }}"
83+
git tag "v${{ steps.version.outputs.new_version }}"
84+
git push origin HEAD:main --follow-tags
85+
86+
- name: Publish to GitHub Packages
87+
run: npm publish
88+
env:
89+
NODE_AUTH_TOKEN: ${{ secrets.GH_TOKEN }}
90+
91+
- name: Create GitHub Release
92+
uses: softprops/action-gh-release@v2
93+
with:
94+
tag_name: v${{ steps.version.outputs.new_version }}
95+
name: "@backendworks/post-db v${{ steps.version.outputs.new_version }}"
96+
body: |
97+
## @backendworks/post-db v${{ steps.version.outputs.new_version }}
98+
99+
Published to [GitHub Packages](https://github.com/orgs/backendworks/packages).
100+
101+
### Install
102+
```bash
103+
npm install @backendworks/post-db@${{ steps.version.outputs.new_version }}
104+
```
105+
generate_release_notes: true
106+
token: ${{ secrets.GH_TOKEN }}

.github/workflows/publish.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Reusable workflow: build, bump version, publish to GitHub Packages, create GitHub Release
2+
# Called by release.yml in each package repo
3+
name: Publish Package (reusable)
4+
5+
on:
6+
workflow_call:
7+
inputs:
8+
package-path:
9+
description: "Relative path to the package directory (e.g. packages/post-db)"
10+
required: true
11+
type: string
12+
package-name:
13+
description: "npm package name (e.g. @backendworks/post-db)"
14+
required: true
15+
type: string
16+
bump:
17+
description: "Version bump type: patch | minor | major"
18+
required: false
19+
type: string
20+
default: "patch"
21+
secrets:
22+
GH_TOKEN:
23+
required: true
24+
25+
jobs:
26+
publish:
27+
name: Build & Publish ${{ inputs.package-name }}
28+
runs-on: ubuntu-latest
29+
permissions:
30+
contents: write # push version tag + commit
31+
packages: write # publish to GitHub Packages
32+
id-token: write # provenance attestation
33+
34+
defaults:
35+
run:
36+
working-directory: ${{ inputs.package-path }}
37+
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v4
41+
with:
42+
token: ${{ secrets.GH_TOKEN }}
43+
fetch-depth: 0
44+
45+
- name: Setup Node
46+
uses: actions/setup-node@v4
47+
with:
48+
node-version: 20
49+
registry-url: "https://npm.pkg.github.com"
50+
scope: "@backendworks"
51+
52+
- name: Install dependencies
53+
run: npm ci
54+
55+
- name: Generate Prisma client
56+
run: npx prisma generate
57+
58+
- name: Build
59+
run: npm run build
60+
61+
- name: Configure git
62+
run: |
63+
git config user.name "github-actions[bot]"
64+
git config user.email "github-actions[bot]@users.noreply.github.com"
65+
66+
- name: Bump version
67+
id: bump
68+
run: |
69+
npm version ${{ inputs.bump }} --no-git-tag-version
70+
VERSION=$(node -p "require('./package.json').version")
71+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
72+
73+
- name: Commit & tag
74+
run: |
75+
git add package.json
76+
git commit -m "chore(release): ${{ inputs.package-name }}@${{ steps.bump.outputs.version }}"
77+
git tag "${{ inputs.package-name }}@${{ steps.bump.outputs.version }}"
78+
git push origin HEAD --follow-tags
79+
env:
80+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
81+
82+
- name: Publish to GitHub Packages
83+
run: npm publish
84+
env:
85+
NODE_AUTH_TOKEN: ${{ secrets.GH_TOKEN }}
86+
87+
- name: Create GitHub Release
88+
uses: softprops/action-gh-release@v2
89+
with:
90+
tag_name: "${{ inputs.package-name }}@${{ steps.bump.outputs.version }}"
91+
name: "${{ inputs.package-name }} v${{ steps.bump.outputs.version }}"
92+
generate_release_notes: true
93+
token: ${{ secrets.GH_TOKEN }}

.github/workflows/release.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Publish @backendworks/post-db
2+
3+
on:
4+
# Manual trigger with bump type selection
5+
workflow_dispatch:
6+
inputs:
7+
bump:
8+
description: "Version bump (patch = bug fix | minor = schema/feature | major = breaking)"
9+
required: true
10+
default: patch
11+
type: choice
12+
options:
13+
- patch
14+
- minor
15+
- major
16+
17+
# Automatic patch on push to main when src/ or prisma/ changes
18+
push:
19+
branches:
20+
- main
21+
paths:
22+
- "src/**"
23+
- "prisma/**"
24+
- "package.json"
25+
26+
jobs:
27+
publish:
28+
uses: ./.github/workflows/publish.yml
29+
with:
30+
package-path: "packages/post-db"
31+
package-name: "@backendworks/post-db"
32+
bump: ${{ github.event.inputs.bump || 'patch' }}
33+
secrets:
34+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
9+
jobs:
10+
unit-tests:
11+
name: Unit Tests
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 20
22+
registry-url: https://npm.pkg.github.com
23+
scope: "@backendworks"
24+
cache: npm
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
env:
29+
NODE_AUTH_TOKEN: ${{ secrets.GH_TOKEN }}
30+
31+
- name: Generate Prisma client
32+
run: npx prisma generate
33+
34+
- name: Run unit tests with coverage
35+
run: npm test
36+
env:
37+
NODE_ENV: test
38+
39+
- name: Upload coverage report
40+
uses: actions/upload-artifact@v4
41+
if: always()
42+
with:
43+
name: post-db-coverage
44+
path: coverage/
45+
retention-days: 7

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# GitHub Packages registry for @backendworks scope
2+
@backendworks:registry=https://npm.pkg.github.com

eslint.config.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// @ts-check
2+
import eslint from "@eslint/js";
3+
import tseslint from "typescript-eslint";
4+
import eslintConfigPrettier from "eslint-config-prettier";
5+
import prettierPlugin from "eslint-plugin-prettier";
6+
7+
export default tseslint.config(
8+
eslint.configs.recommended,
9+
...tseslint.configs.recommended,
10+
eslintConfigPrettier,
11+
{
12+
plugins: { prettier: prettierPlugin },
13+
rules: {
14+
"prettier/prettier": "error",
15+
"@typescript-eslint/no-explicit-any": "off",
16+
"@typescript-eslint/no-unused-vars": [
17+
"error",
18+
{ argsIgnorePattern: "^_" },
19+
],
20+
},
21+
},
22+
);

package.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "@backendworks/post-db",
3+
"version": "1.0.0",
4+
"description": "ORM-agnostic database package for the post domain (Post)",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"files": [
8+
"dist/**/*"
9+
],
10+
"publishConfig": {
11+
"registry": "https://npm.pkg.github.com"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/BackendWorks/post-db.git"
16+
},
17+
"scripts": {
18+
"build": "rimraf dist && tsc -p tsconfig.build.json",
19+
"prisma:generate": "dotenv -e .env.docker -- prisma generate",
20+
"prisma:migrate": "dotenv -e .env.docker -- prisma migrate dev",
21+
"prisma:migrate:prod": "dotenv -e .env.docker -- prisma migrate deploy",
22+
"prisma:studio": "dotenv -e .env.docker -- prisma studio",
23+
"lint": "eslint \"src/**/*.ts\" --fix",
24+
"format": "prettier --write \"src/**/*.ts\""
25+
},
26+
"dependencies": {
27+
"@prisma/client": "^5.21.1"
28+
},
29+
"devDependencies": {
30+
"@types/node": "^22.8.5",
31+
"dotenv-cli": "^8.0.0",
32+
"eslint": "^9.0.0",
33+
"eslint-config-prettier": "^10.1.5",
34+
"eslint-plugin-prettier": "^5.2.1",
35+
"prettier": "^3.3.3",
36+
"prisma": "^5.21.1",
37+
"rimraf": "^6.0.1",
38+
"typescript": "^5.6.3"
39+
},
40+
"engines": {
41+
"node": ">=18.0.0"
42+
}
43+
}

0 commit comments

Comments
 (0)