Skip to content

Commit

Permalink
Merge pull request #1 from SoftwareparkVeroo/master
Browse files Browse the repository at this point in the history
Add parameter for optional DB init scripts.
  • Loading branch information
danielweller-swp authored Jan 7, 2020
2 parents 0be19fa + c62ec79 commit b859f56
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI

on: [push]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1

- uses: ./
with:
postgresql password: test
postgresql init scripts: test/sql

- uses: actions/setup-node@v1

- run: npm ci
working-directory: test

- run: node index.js
working-directory: test
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ inputs:
description: 'POSTGRES_PASSWORD - superuser password'
required: false
default: ''
postgresql init scripts:
description: 'POSTGRES_INIT_SCRIPTS - directory containing DB init scripts'
required: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
8 changes: 8 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ docker_run="docker run"
docker_run="$docker_run -e POSTGRES_DB=$INPUT_POSTGRESQL_DB"
docker_run="$docker_run -e POSTGRES_USER=$INPUT_POSTGRESQL_USER"
docker_run="$docker_run -e POSTGRES_PASSWORD=$INPUT_POSTGRESQL_PASSWORD"

if [ ! -z "$INPUT_POSTGRESQL_INIT_SCRIPTS" ]
then
REPO=`echo "$GITHUB_REPOSITORY" | cut -d "/" -f 2`
INIT_SCRIPT_PATH="/home/runner/work/$REPO/$REPO/$INPUT_POSTGRESQL_INIT_SCRIPTS"
docker_run="$docker_run -v $INIT_SCRIPT_PATH:/docker-entrypoint-initdb.d"
fi

docker_run="$docker_run -d -p 5432:5432 postgres:$INPUT_POSTGRESQL_VERSION"

sh -c "$docker_run"
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
29 changes: 29 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { Client } = require('pg')

async function run() {
const client = new Client({
host: 'localhost',
user: 'postgres',
database: 'postgres',
password: 'test',
port: 5432
})
await client.connect()
const res = await client.query('SELECT * FROM Persons')
const data = res.rows[0]
if (data.personid != 1) {
throw new Error("Unexpected PersonId")
}
await client.end()
}

async function sleep(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
}

run().catch((err) => {
console.error(err)
process.exit(1)
})
113 changes: 113 additions & 0 deletions test/package-lock.json

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

15 changes: 15 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"pg": "^7.13.0"
}
}
9 changes: 9 additions & 0 deletions test/sql/001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE Persons (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);

INSERT INTO Persons VALUES (1, 'Last', 'First', 'TestAddress', 'TestCity');

0 comments on commit b859f56

Please sign in to comment.