Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
add CI (#3)
Browse files Browse the repository at this point in the history
* trying out some CI

* adding postgres

* already have postgres running

* updating postgres setup for mock

* install dbmate

* trying defaults life

* add loading of did of server for test

* wait for server to amp up

* Update src/main.ts

Co-authored-by: Moe Jangda <[email protected]>

* move server-did to config

* typo

* tidy up env

* cleaning up a bit more

---------

Co-authored-by: Moe Jangda <[email protected]>
  • Loading branch information
michaelneale and mistermoe authored Nov 9, 2023
1 parent 2a0e514 commit 519d44a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Node.js CI with PostgreSQL

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build_and_test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: tbd
POSTGRES_DB: mockpfi
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
node-version: ['20.4.0']

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Install dbmate
run: |
curl -fsSL https://github.com/amacneil/dbmate/releases/download/v1.12.1/dbmate-linux-amd64 -o dbmate
chmod +x dbmate
sudo mv dbmate /usr/local/bin
- name: Run migration scripts
run: |
./db/scripts/migrate
- name: Seed offerings
run: npm run seed-offerings
- name: Run server and tests
run: |
npm run server &
SERVER_PID=$!
sleep 5
npm run test
kill $SERVER_PID
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules/
.env
.DS_STORE
alice.json
issuer.json
issuer.json
server-did.txt
5 changes: 4 additions & 1 deletion src/client-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import fs from 'fs/promises'
// Replace this with the DID of the PFI you want to connect to.
// Get this from the console of the server once you launch it.
//
const PFI_DID = 'did:ion:EiDgs_F6pK672qmdJP2n8-LY4MjhPSehDl1I6y1nfrSW3g:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoiNnpYZ3VBZW1XZHBDYVVkYjE2Rjl4czFmU3JBUEZ2MmZlcFE0SGJoM2QxNCJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbeyJpZCI6InBmaSIsInNlcnZpY2VFbmRwb2ludCI6Imh0dHA6Ly9sb2NhbGhvc3Q6OTAwMCIsInR5cGUiOiJQRkkifV19fV0sInVwZGF0ZUNvbW1pdG1lbnQiOiJFaUJOV21uNlV1c3hrczBTalhPTzBSUUZVbnR3dGxzczFjLVlBTFpJQ01BQUNBIn0sInN1ZmZpeERhdGEiOnsiZGVsdGFIYXNoIjoiRWlEOU50cWVXbzNMOXNJdHBRRHQzazlIaEVpcDhZMk9UZk00QWJCTFNXeWpmZyIsInJlY292ZXJ5Q29tbWl0bWVudCI6IkVpQUxqei1rNWtaZlBmQTJEWUcwY2V1Rk9tbGhUN0VDM1F0ZUVxR2tOeXM0cFEifX0'

// load server-did (this will be created when you run server did, or you can copy/paste one):
let PFI_DID = await fs.readFile('server-did.txt', 'utf-8')


//
//
Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { PoolConfig } from 'pg'

import type { LogLevelDesc } from 'loglevel'
import fs from 'node:fs'

import 'dotenv/config'

Expand Down Expand Up @@ -51,7 +52,9 @@ if (!config.did.id) {
services: [{ id: 'pfi', type: 'PFI', serviceEndpoint: config.host }]
})


config.did.id = DidIon.did
fs.writeFileSync('server-did.txt', config.did.id)
config.did.privateKey = DidIon.keySet.verificationMethodKeys[0].privateKeyJwk
config.did.kid = `${config.did.id}#${config.did.privateKey.kid}`
}
3 changes: 1 addition & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Postgres, ExchangeRespository, OfferingRepository } from './db/index.js
import { HttpServerShutdownHandler } from './http-shutdown-handler.js'
import { TbdexHttpServer } from '@tbdex/http-server'


process.on('unhandledRejection', (reason: any, promise) => {
log.error(`Unhandled promise rejection. Reason: ${reason}. Promise: ${JSON.stringify(promise)}. Stack: ${reason.stack}`)
})
Expand All @@ -31,8 +32,6 @@ process.on('SIGTERM', async () => {
gracefulShutdown()
})

// await Postgres.ping()

const httpApi = new TbdexHttpServer({ exchangesApi: ExchangeRespository, offeringsApi: OfferingRepository })

httpApi.submit('rfq', async (ctx, rfq) => {
Expand Down

0 comments on commit 519d44a

Please sign in to comment.