Skip to content

Commit

Permalink
add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdickinson committed Jul 6, 2024
1 parent ffa3870 commit 80fb4a2
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 27 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: XTP CI

on:
workflow_dispatch:
push:

jobs:
build:
runs-on: ubuntu-latest

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
env:
PGURL: postgres://postgres:postgres@localhost:5432/postgres
FORCE_PRETTY_OUTPUT: true

steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x'

- name: cache npm dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-discordbot-npm-cache-${{ hashFiles('service/api/package-lock.json') }}
restore-keys: |
${{ runner.os }}-discordbot-npm-cache-
- name: install deps
run: |
npm ci
- name: migrate
run: |
npm run migrate
- name: run tests
run: |
TEST_LOG=1 npm t
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
},
"dependencies": {
"@dylibso/xtp": "0.0.0-rc4",
"@electric-sql/pglite": "^0.1.1",
"@extism/extism": "^1.0.2",
"@fastify/cookie": "^9.3.1",
"@fastify/oauth2": "^7.8.0",
Expand Down
31 changes: 12 additions & 19 deletions src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,19 @@ export async function getDatabaseConnection() {
return db
}

if (!PGURL.startsWith('file://')) {
db = new pg.Pool({ connectionString: PGURL })

db.transaction = async <T>(fn: (db: pg.Client) => Promise<T>) => {
const client = await db.connect()
await client.query(`BEGIN;`)
try {
const xs = await fn(client)
await client.query(`COMMIT;`)
return xs
} catch {
await client.query(`ROLLBACK;`)
}
};
return db
}

const { PGlite } = await import('@electric-sql/pglite')
db = new PGlite(PGURL)
db = new pg.Pool({ connectionString: PGURL })

db.transaction = async <T>(fn: (db: pg.Client) => Promise<T>) => {
const client = await db.connect()
await client.query(`BEGIN;`)
try {
const xs = await fn(client)
await client.query(`COMMIT;`)
return xs
} catch {
await client.query(`ROLLBACK;`)
}
};
return db
}

Expand Down
2 changes: 1 addition & 1 deletion src/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ migrations().then(async last => {
console.log(`ran up to ${last}`)

const pg = await getDatabaseConnection()
pg.close()
pg.end()
}).catch(err => {
console.error(err.stack)
process.exit(1)
Expand Down

0 comments on commit 80fb4a2

Please sign in to comment.