@@ -21,6 +21,10 @@ inputs:
2121 description : The server port to listen on.
2222 default : " 5432"
2323 required : false
24+ postgres-version :
25+ description : The PostgreSQL version (major) to install. E.g. "13" or "14".
26+ default : " 15"
27+ required : false
2428outputs :
2529 connection-uri :
2630 description : The connection URI to connect to PostgreSQL.
@@ -31,13 +35,45 @@ outputs:
3135runs :
3236 using : composite
3337 steps :
34- - name : Prerequisites
38+ - name : Install PostgreSQL
3539 run : |
3640 if [ "$RUNNER_OS" == "Linux" ]; then
37- echo "$(pg_config --bindir)" >> $GITHUB_PATH
41+ echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \
42+ | sudo tee /etc/apt/sources.list.d/pgdg.list
43+ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
44+ sudo apt-get update
45+ sudo apt-get -y install postgresql-${{ inputs.postgres-version }}
46+
47+ # Add PostgreSQL binaries to PATH, so they become globally available.
48+ /usr/lib/postgresql/${{ inputs.postgres-version }}/bin/pg_config --bindir >> $GITHUB_PATH
49+
50+ elif [ "$RUNNER_OS" == "macOS" ]; then
51+ brew install postgresql@${{ inputs.postgres-version }}
52+
53+ # Link PostgreSQL binaries to /usr/local/bin so they become globally
54+ # available. The overwrite option is required because they might be a
55+ # preinstalled linked bottle.
56+ brew link --overwrite postgresql@${{ inputs.postgres-version }}
57+
3858 elif [ "$RUNNER_OS" == "Windows" ]; then
39- echo "$PGBIN" >> $GITHUB_PATH
40- echo "PQ_LIB_DIR=$PGROOT\lib" >> $GITHUB_ENV
59+ # FIXME: Aargh! For reasons unknown the '--servicename' option is
60+ # ignored when installing a PostgreSQL version that is already
61+ # preinstalled on GitHub runners. In order to bypass the issue I'm
62+ # using default naming convention (i.e. with arch in the name).
63+ choco install postgresql${{ inputs.postgres-version }} \
64+ --ia "--servicename postgresql-${{ runner.arch }}-${{ inputs.postgres-version }}"
65+
66+ # Stop PostgreSQL that has been auto started after installation. This
67+ # action prepares new configuration and brings its own instance, and
68+ # we need a network port to be free.
69+ net stop postgresql-${{ runner.arch }}-${{ inputs.postgres-version }}
70+
71+ # Add PostgreSQL binaries to PATH, so they become globally available
72+ # and set path to LIBPQ to link against. On Windows it comes together
73+ # with PostgreSQL distribution.
74+ export PGROOT="$PROGRAMFILES/PostgreSQL/${{ inputs.postgres-version }}"
75+ "$PGROOT"/bin/pg_config.exe --bindir >> $GITHUB_PATH
76+ echo "PQ_LIB_DIR=$("$PGROOT"/bin/pg_config.exe --libdir)" >> $GITHUB_ENV
4177 fi
4278 shell : bash
4379
65101 --pwfile="$PWFILE" \
66102 --auth="scram-sha-256" \
67103 --encoding="UTF-8" \
68- --locale="en_US.UTF-8" \
69- --no-instructions
104+ --locale="en_US.UTF-8"
70105
71106 # Do not create unix sockets since they are created by default in the
72107 # directory we have no permissions to (owned by system postgres user).
0 commit comments