Code Monkey home page Code Monkey logo

action-setup-postgres's Introduction

setup-postgres

This action sets up a PostgreSQL server for the rest of the job. Here are some key features:

Usage

Important

In order to connect to a PostgreSQL server, use either connection parameters from the table below (link), or retrieve a connection URI from the connection-uri output (link).

Tip

libpq-using applications may choose to set the PGSERVICE=postgres environment variable instead (link), where postgres is the service name extracted from the service-name output.

Connection parameters

Key Value
URI postgresql://postgres:postgres@localhost/postgres
Host localhost
Port 5432
Username postgres
Password postgres
Database postgres
Service postgres

User permissions

Key Value
usesuper true
usecreatedb true

Basic

steps:
  - uses: ikalnytskyi/action-setup-postgres@v6 

Advanced

steps:
  - uses: ikalnytskyi/action-setup-postgres@v6 
    with:
      username: ci
      password: sw0rdfish
      database: test
      port: 34837
      ssl: "on"
      # If ssl isn't "on", ca_file_output won't have any effect
      ca_file_output: "some_path_suitable_for_you"
    id: postgres

  - run: pytest -vv tests/
    env:
      CONNECTION_STR: ${{ steps.postgres.outputs.connection-uri }}

  - run: pytest -vv tests/
    env:
      CONNECTION_STR: service=${{ steps.postgres.outputs.service-name }}

Recipes

Create a new user w/ database via CLI

steps:
  - uses: ikalnytskyi/action-setup-postgres@v6 

  - run: |
      createuser myuser
      createdb --owner myuser mydatabase
      psql -c "ALTER USER myuser WITH PASSWORD 'mypassword'"
    env:
      # This activates connection parameters for the superuser created by
      # the action in the step above. It's mandatory to set this before using
      # createuser/psql and other libpq-using applications.
      #
      # The service name is the same as the username (i.e. 'postgres') but
      # it's recommended to use action's output to get the name in order to
      # be forward compatible.
      PGSERVICE: ${{ steps.postgres.outputs.service-name }}
    shell: bash

Create a new user w/ database via psycopg

steps:
  - uses: ikalnytskyi/action-setup-postgres@v6 
import psycopg

# 'postgres' is the username here, but it's recommended to use the
# action's 'service-name' output parameter here.
connection = psycopg.connect("service=postgres")

# CREATE/DROP USER statements don't work within transactions, and with
# autocommit disabled transactions are created by psycopg automatically.
connection.autocommit = True
connection.execute(f"CREATE USER myuser WITH PASSWORD 'mypassword'")
connection.execute(f"CREATE DATABASE mydatabase WITH OWNER 'myuser'")

Rationale

At the time of developing there were no GitHub Actions on the marketplace to setup a PostgreSQL server on Linux, Windows and macOS action runners. Most solutions suggest using Docker which is not available on macOS and Windows runners.

License

The scripts and documentation in this project are released under the MIT License.

action-setup-postgres's People

Contributors

ikalnytskyi avatar matt-42 avatar nyurik avatar chandr-andr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.