This action handles the setup and teardown of a PostgreSQL database.
This action does not provision WSL or Docker itself. On Windows runners it requires setup-wsl-action to run first in the same job — that action provisions WSL2 + Docker, keeps the instance alive, and exports the WSL_DISTRIBUTION, WSL_IP, and WSL_TOOLS_MODULE_PATH environment variables this action relies on. On Linux runners setup-wsl-action is a no-op but should still be included so the workflow is uniform.
If setup-wsl-action has not run, the action fails fast with a clear error.
See action.yml
steps:
- name: Setup WSL
uses: Particular/setup-wsl-action@v1
- name: Setup Postgres
uses: Particular/setup-postgres-action@v1.0.0
with:
connection-string-name: <my connection string name>
init-script: /path/to/init-posgres.sql
registry-login-server: index.docker.io
registry-username: ${{ secrets.DOCKERHUB_USERNAME }}
registry-password: ${{ secrets.DOCKERHUB_TOKEN }}}} connection-string-name is required. init-script is optional.
For logging into a container registry when running on Windows:
registry-login-serverdefaults toindex.docker.ioand is not required if logging into Docker Hub.registry-usernameandregistry-passwordare optional and will result in pulling the container anonymously if omitted.
On Linux runners the PostgreSQL container runs directly through Docker. On Windows runners the Linux PostgreSQL container runs inside WSL2 provisioned by setup-wsl-action — run it first, see Prerequisites.
The scripts and documentation in this project are released under the MIT License.
Open the folder in Visual Studio Code. If you don't already have them, you will be prompted to install remote development extensions. After installing them, and re-opening the folder in a container, do the following:
Run the npm installation
npm installWhen changing index.js, either run npm run dev beforehand, which will watch the file for changes and automatically compile it, or run npm run prepare afterwards.
To test the setup action an .env.setup file in the root directory with the following content
# Input overrides
INPUT_CONNECTION-STRING-NAME=PostgresConnectionString
INPUT_TAG=setup-postgres-action
# Runner overrides
# Use LINUX to run on Linux, WINDOWS to run on Windows via WSL2
RUNNER_OS=WINDOWSthen execute the script
node -r dotenv/config dist/index.js dotenv_config_path=.env.setupTo test the cleanup action add a .env.cleanup file in the root directory with the following content
# State overrides
STATE_IsPost=true
STATE_containerName=nameOfPreviouslyCreatedContainernode -r dotenv/config dist/index.js dotenv_config_path=.env.cleanupTo test the setup action set the required environment variables and execute setup.ps1 with the desired parameters.
$Env:RUNNER_OS=Windows
.\setup.ps1 -ContainerName psw-postgres-1 -ConnectionStringName PostgresConnectionStringTo test the cleanup action set the required environment variables and execute cleanup.ps1 with the desired parameters.
$Env:RUNNER_OS=Windows
.\cleanup.ps1 -ContainerName psw-postgres-1Running
setup.ps1/cleanup.ps1directly on Windows requiresWSL_TOOLS_MODULE_PATHto point at setup-wsl-action'sWslToolsmodule (set it by running setup-wsl-action first).