@@ -24,7 +24,10 @@ inputs:
2424outputs :
2525 connection-uri :
2626 description : The connection URI to connect to PostgreSQL.
27- value : ${{ steps.connection-uri.outputs.value }}
27+ value : ${{ steps.set-outputs.outputs.connection-uri }}
28+ service-name :
29+ description : The service name with connection parameters.
30+ value : ${{ steps.set-outputs.outputs.service-name }}
2831runs :
2932 using : composite
3033 steps :
@@ -71,21 +74,27 @@ runs:
7174 echo "port = ${{ inputs.port }}" >> "$PGDATA/postgresql.conf"
7275 pg_ctl start
7376
74- # Set environment variables for PostgreSQL client applications [1] such
75- # as 'psql' or 'createuser'.
77+ # Save required connection parameters for created superuser to the
78+ # connection service file [1]. This allows using these connection
79+ # parameters by setting 'PGSERVICE' environment variable or by
80+ # requesting them via connection string.
7681 #
77- # PGHOST is required for Linux/macOS because we turned off unix sockets
78- # and they use them by default .
82+ # HOST is required for Linux/macOS because these OS-es default to unix
83+ # sockets but we turned them off .
7984 #
80- # PGPORT, PGUSER, PGPASSWORD and PGDATABASE are required because they
81- # could be parametrized via action input parameters.
85+ # PORT, USER, PASSWORD and DBNAME are required because they could be
86+ # parametrized via action input parameters.
8287 #
83- # [1] https://www.postgresql.org/docs/15/reference-client.html
84- echo "PGHOST=localhost" >> $GITHUB_ENV
85- echo "PGPORT=${{ inputs.port }}" >> $GITHUB_ENV
86- echo "PGUSER=${{ inputs.username }}" >> $GITHUB_ENV
87- echo "PGPASSWORD=${{ inputs.password }}" >> $GITHUB_ENV
88- echo "PGDATABASE=${{ inputs.database }}" >> $GITHUB_ENV
88+ # [1] https://www.postgresql.org/docs/15/libpq-pgservice.html
89+ cat <<EOF > "$PGDATA/pg_service.conf"
90+ [${{ inputs.username }}]
91+ host=localhost
92+ port=${{ inputs.port }}
93+ user=${{ inputs.username }}
94+ password=${{ inputs.password }}
95+ dbname=${{ inputs.database }}
96+ EOF
97+ echo "PGSERVICEFILE=$PGDATA/pg_service.conf" >> $GITHUB_ENV
8998 shell : bash
9099
91100 - name : Setup PostgreSQL database
@@ -97,11 +106,15 @@ runs:
97106 if [ "${{ inputs.database }}" != "postgres" ]; then
98107 createdb -O "${{ inputs.username }}" "${{ inputs.database }}"
99108 fi
109+ env :
110+ PGSERVICE : ${{ inputs.username }}
100111 shell : bash
101112
102- - name : Expose connection URI
113+ - name : Set action outputs
103114 run : |
104- CONNECTION_URI="postgresql://${{ inputs.username }}:${{ inputs.password }}@localhost:${{inputs.port}}/${{ inputs.database }}"
105- echo "value=$CONNECTION_URI" >> $GITHUB_OUTPUT
115+ CONNECTION_URI="postgresql://${{ inputs.username }}:${{ inputs.password }}@localhost:${{ inputs.port }}/${{ inputs.database }}"
116+
117+ echo "connection-uri=$CONNECTION_URI" >> $GITHUB_OUTPUT
118+ echo "service-name=${{ inputs.username }}" >> $GITHUB_OUTPUT
106119 shell : bash
107- id : connection-uri
120+ id : set-outputs
0 commit comments