Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter for optional DB init scripts. #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');