Skip to content

Commit d5fa7f7

Browse files
committed
👷 Separate PostgreSQL pipeline
1 parent c3a9386 commit d5fa7f7

5 files changed

Lines changed: 126 additions & 48 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: 'Create project'
2+
description: 'Runs create-node-project and performs tests'
3+
inputs:
4+
options:
5+
description: 'create-node-app options'
6+
required: true
7+
dbConnection:
8+
description: 'DB_CONNECTION_STRING env var'
9+
default: 'postgresql://postgres:postgres@localhost:5432/postgres'
10+
runs:
11+
using: 'composite'
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
16+
- name: Cache dependencies
17+
uses: actions/cache@v3
18+
with:
19+
path: ~/.npm
20+
key: npm-${{ hashFiles('package-lock.json') }}
21+
restore-keys: npm-
22+
23+
- name: Install dependencies
24+
run: npm ci --ignore-scripts
25+
shell: bash
26+
27+
- name: Build the project
28+
run: npm run build
29+
shell: bash
30+
31+
- name: Run npm link
32+
run: npm link
33+
shell: bash
34+
35+
- name: Create project
36+
run: create-node-app ${{ inputs.options }}
37+
shell: bash
38+
39+
- name: Build created project
40+
working-directory: ./node-app
41+
run: npm run build
42+
shell: bash
43+
44+
- name: Run lint
45+
working-directory: ./node-app
46+
run: npm run ci-lint
47+
shell: bash
48+
49+
- name: Wait for PostgreSQL
50+
if: ${{ contains(inputs.options, '--database postgres-knex') }}
51+
run: |
52+
until pg_isready -h localhost -p 5432 -U postgres; do
53+
echo "Waiting for PostgreSQL to be ready..."
54+
sleep 2
55+
done
56+
echo "PostgreSQL is ready!"
57+
shell: bash
58+
59+
- name: Run tests
60+
working-directory: ./node-app
61+
run: npm run ci-test
62+
shell: bash
63+
env:
64+
DB_CONNECTION_STRING: ${{inputs.dbConnection}}
65+
66+
- name: Run start
67+
if: ${{ !contains(inputs.options, '--api none') }}
68+
working-directory: ./node-app
69+
run: |
70+
npm run start &
71+
start_pid=$!
72+
sleep 10
73+
kill $start_pid
74+
shell: bash
75+
env:
76+
DB_CONNECTION_STRING: ${{inputs.dbConnection}}
77+
78+
- name: Run start
79+
if: ${{ contains(inputs.options, '--api none') }}
80+
working-directory: ./node-app
81+
shell: bash
82+
run: npm run start
83+
env:
84+
DB_CONNECTION_STRING: ${{inputs.dbConnection}}

‎.github/workflows/create-projects.yml‎

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,48 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
create-app-command:
21-
- "create-node-app -f --api rest --database postgres-knex --pipeline cloudrun-gitlab"
22-
- "create-node-app -f --api graphql --database postgres-knex --pipeline cloudrun-gitlab"
23-
- "create-node-app -f --api rest --database none --pipeline cloudrun-gitlab"
24-
- "create-node-app -f --api graphql --database none --pipeline cloudrun-gitlab"
25-
- "create-node-app -f --api rest --database none --pipeline none"
26-
- "create-node-app -f --api none --database none --pipeline cloudrun-gitlab"
20+
create-app-options:
21+
- "--api rest --database none --pipeline cloudrun-gitlab"
22+
- "--api graphql --database none --pipeline cloudrun-gitlab"
23+
- "--api rest --database none --pipeline none"
24+
- "--api none --database none --pipeline cloudrun-gitlab"
2725
runs-on: ubuntu-latest
2826

2927
steps:
30-
- name: Checkout
31-
uses: actions/checkout@v3
32-
33-
- name: Cache dependencies
34-
uses: actions/cache@v3
28+
- uses: actions/checkout@v4
29+
- id: create-node-app
30+
uses: ./.github/actions/test-create-project
3531
with:
36-
path: ~/.npm
37-
key: npm-${{ hashFiles('package-lock.json') }}
38-
restore-keys: npm-
39-
40-
- name: Install dependencies
41-
run: npm ci --ignore-scripts
42-
43-
- name: Build the project
44-
run: npm run build
45-
46-
- name: Run npm link
47-
run: npm link
48-
49-
- name: Create project
50-
run: ${{ matrix.create-app-command }}
51-
52-
- name: Build created project
53-
working-directory: ./node-app
54-
run: npm run build
32+
options: ${{ matrix.create-app-options }}
5533

56-
- name: Run lint
57-
working-directory: ./node-app
58-
run: npm run ci-lint
34+
create-projects-with-postgres:
35+
needs: "build"
36+
services:
37+
postgres:
38+
image: postgres:17
39+
env:
40+
POSTGRES_PASSWORD: postgres
41+
POSTGRES_DB: postgres
42+
POSTGRES_USER: postgres
43+
options: >-
44+
--health-cmd pg_isready
45+
--health-interval 10s
46+
--health-timeout 5s
47+
--health-retries 5
48+
ports:
49+
- 5432:5432
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
create-app-options:
54+
- "--api none --database postgres-knex --pipeline none"
55+
- "--api rest --database postgres-knex --pipeline cloudrun-gitlab"
56+
- "--api graphql --database postgres-knex --pipeline cloudrun-gitlab"
57+
runs-on: ubuntu-latest
5958

60-
- name: Run tests
61-
working-directory: ./node-app
62-
run: npm run ci-test
63-
64-
- name: Run start
65-
working-directory: ./node-app
66-
run: |
67-
npm run start &
68-
start_pid=$!
69-
sleep 10
70-
kill $start_pid
59+
steps:
60+
- uses: actions/checkout@v4
61+
- id: create-node-app
62+
uses: ./.github/actions/test-create-project
63+
with:
64+
options: ${{ matrix.create-app-options }}

‎starter/_base/src/index.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { config } from './config.js'
21
import { createContainer } from './container.js'
32
import { RequestContext } from './context.js'
43

‎starter/infra/postgresql-knex/docker-compose/docker-compose.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.8'
22
services:
33
postgres:
4-
image: postgres:15
4+
image: postgres:17
55
environment:
66
- POSTGRES_DB={{PROJECT_NAME}}_docker
77
- POSTGRES_USER={{PROJECT_NAME}}_docker

‎starter/infra/postgresql-knex/src/adapters/knex.database.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ describe('knexConnection', () => {
1414
})
1515
)
1616
assert(db)
17-
await assert.doesNotReject(db.raw('SELECT version()'))
17+
const version = await db.raw('SELECT version()')
18+
assert(version.rows.length === 1)
1819
await assert.doesNotReject(knexConnection.disconnect(db))
1920
})
2021
})

0 commit comments

Comments
 (0)