Skip to content

Commit b859f56

Browse files
Merge pull request #1 from SoftwareparkVeroo/master
Add parameter for optional DB init scripts.
2 parents 0be19fa + c62ec79 commit b859f56

File tree

8 files changed

+201
-0
lines changed

8 files changed

+201
-0
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v1
10+
11+
- uses: ./
12+
with:
13+
postgresql password: test
14+
postgresql init scripts: test/sql
15+
16+
- uses: actions/setup-node@v1
17+
18+
- run: npm ci
19+
working-directory: test
20+
21+
- run: node index.js
22+
working-directory: test

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ inputs:
2323
description: 'POSTGRES_PASSWORD - superuser password'
2424
required: false
2525
default: ''
26+
postgresql init scripts:
27+
description: 'POSTGRES_INIT_SCRIPTS - directory containing DB init scripts'
28+
required: false
29+
default: ''
2630
runs:
2731
using: 'docker'
2832
image: 'Dockerfile'

entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ docker_run="docker run"
44
docker_run="$docker_run -e POSTGRES_DB=$INPUT_POSTGRESQL_DB"
55
docker_run="$docker_run -e POSTGRES_USER=$INPUT_POSTGRESQL_USER"
66
docker_run="$docker_run -e POSTGRES_PASSWORD=$INPUT_POSTGRESQL_PASSWORD"
7+
8+
if [ ! -z "$INPUT_POSTGRESQL_INIT_SCRIPTS" ]
9+
then
10+
REPO=`echo "$GITHUB_REPOSITORY" | cut -d "/" -f 2`
11+
INIT_SCRIPT_PATH="/home/runner/work/$REPO/$REPO/$INPUT_POSTGRESQL_INIT_SCRIPTS"
12+
docker_run="$docker_run -v $INIT_SCRIPT_PATH:/docker-entrypoint-initdb.d"
13+
fi
14+
715
docker_run="$docker_run -d -p 5432:5432 postgres:$INPUT_POSTGRESQL_VERSION"
816

917
sh -c "$docker_run"

test/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

test/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const { Client } = require('pg')
2+
3+
async function run() {
4+
const client = new Client({
5+
host: 'localhost',
6+
user: 'postgres',
7+
database: 'postgres',
8+
password: 'test',
9+
port: 5432
10+
})
11+
await client.connect()
12+
const res = await client.query('SELECT * FROM Persons')
13+
const data = res.rows[0]
14+
if (data.personid != 1) {
15+
throw new Error("Unexpected PersonId")
16+
}
17+
await client.end()
18+
}
19+
20+
async function sleep(ms) {
21+
return new Promise(resolve => {
22+
setTimeout(resolve, ms)
23+
})
24+
}
25+
26+
run().catch((err) => {
27+
console.error(err)
28+
process.exit(1)
29+
})

test/package-lock.json

Lines changed: 113 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"pg": "^7.13.0"
14+
}
15+
}

test/sql/001.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CREATE TABLE Persons (
2+
PersonID int,
3+
LastName varchar(255),
4+
FirstName varchar(255),
5+
Address varchar(255),
6+
City varchar(255)
7+
);
8+
9+
INSERT INTO Persons VALUES (1, 'Last', 'First', 'TestAddress', 'TestCity');

0 commit comments

Comments
 (0)