-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from xsnippet/setup-postgres
Add 'setup-postgres' action
- Loading branch information
Showing
2 changed files
with
76 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: Setup PostgreSQL | ||
description: | | ||
Setup a PostgreSQL for Linux, macOS and Windows machines. Runs natively, no | ||
Docker containers are involved. | ||
inputs: | ||
username: | ||
description: A username of the user to setup. | ||
default: postgres | ||
password: | ||
description: A password of the user to setup. | ||
default: postgres | ||
database: | ||
description: A database name to setup and grant permissions to created user. | ||
default: postgres | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Prerequisites | ||
run: | | ||
if [ "$RUNNER_OS" == "Linux" ]; then | ||
echo "$(pg_config --bindir)" >> $GITHUB_PATH | ||
elif [ "$RUNNER_OS" == "Windows" ]; then | ||
echo "$PGBIN" >> $GITHUB_PATH | ||
echo "PQ_LIB_DIR=$PGROOT\lib" >> $GITHUB_ENV | ||
fi | ||
shell: bash | ||
|
||
|
||
- name: Setup and start PostgreSQL | ||
run: | | ||
export PGDATA="$RUNNER_TEMP/pgdata" | ||
pg_ctl init | ||
# Forbid creating unix sockets since they are created by default in the | ||
# directory we don't have permissions to. | ||
echo "unix_socket_directories = ''" >> "$PGDATA/postgresql.conf" | ||
pg_ctl start | ||
# Both PGHOST and PGUSER are used by PostgreSQL tooling such as 'psql' | ||
# or 'createuser'. Since PostgreSQL data has been resetup, we cannot | ||
# rely on defaults anymore. | ||
# | ||
# PGHOST is required for Linux and macOS since they default to unix | ||
# sockets, and we have turned them off. | ||
# | ||
# PGUSER is required for Windows since default the tooling's default | ||
# user is 'postgres', while 'pg_ctl init' creates one with the name of | ||
# the current user. | ||
echo "PGHOST=localhost" >> $GITHUB_ENV | ||
echo "PGUSER=${USER:-$USERNAME}" >> $GITHUB_ENV | ||
shell: bash | ||
|
||
- name: Setup PostgreSQL user and database | ||
run: | | ||
createuser ${{ inputs.username }} | ||
if [ "${{ inputs.database}}" != "postgres" ]; then | ||
createdb -O ${{ inputs.username }} ${{ inputs.database }} | ||
fi | ||
psql -c "ALTER USER ${{ inputs.username }} PASSWORD '${{ inputs.password }}';" ${{ inputs.database }} | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters