From 6b1b8678fb0bb4b6ddc7a556f6ff93614261b897 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 7 Sep 2023 19:13:46 -0600 Subject: [PATCH 01/17] feat: add support for installing postgresql --- action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/action.yml b/action.yml index 190ac03..1e3f6b1 100644 --- a/action.yml +++ b/action.yml @@ -2,6 +2,9 @@ name: pg-dump description: Run pg_dump to generate a backup author: tj-actions inputs: + postgresql_version: + description: 'Version of PostgreSQL. e.g 15' + required: false database_url: description: 'Database URL' required: true From ccd8792e2444caa46ba4d282b9950890acd36150 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 7 Sep 2023 19:15:09 -0600 Subject: [PATCH 02/17] Create entrypoint.sh --- entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 entrypoint.sh diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..5b2371c --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +set -euo pipefail From 68260fe40866eded09e10e604e7438bc3669c3c4 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 8 Sep 2023 01:26:39 +0000 Subject: [PATCH 03/17] Updated the script --- .github/workflows/test.yml | 9 +++++++++ action.yml | 10 ++++++++-- entrypoint.sh | 17 +++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) mode change 100644 => 100755 entrypoint.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8374b2e..0aaec1d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,6 +9,15 @@ on: - main jobs: + shellcheck: + name: Run shellcheck + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 + - name: shellcheck + uses: reviewdog/action-shellcheck@v1.19 test: runs-on: ubuntu-latest name: Test postgres-restore diff --git a/action.yml b/action.yml index 1e3f6b1..95e6f6a 100644 --- a/action.yml +++ b/action.yml @@ -20,9 +20,15 @@ runs: using: 'composite' steps: - run: | - mkdir -p $(dirname "${{ inputs.path }}") - pg_dump ${{ inputs.options }} -d "${{ inputs.database_url }}" > "${{ inputs.path }}" + bash $GITHUB_ACTION_PATH/entrypoint.sh shell: bash + env: + # INPUT_ is not available in Composite run steps + # https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611 + INPUT_POSTGRESQL_VERSION: ${{ inputs.postgresql_version }} + INPUT_PATH: ${{ inputs.path }} + INPUT_DATABASE_URL: ${{ inputs.database_url }} + INPUT_OPTIONS: ${{ inputs.options }} branding: icon: hard-drive color: white diff --git a/entrypoint.sh b/entrypoint.sh old mode 100644 new mode 100755 index 5b2371c..a8c7df5 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,3 +1,20 @@ #!/usr/bin/env bash set -euo pipefail + +echo "::group::pg-dump" + +echo "Creating the output directory..." + +mkdir -p $(dirname "$INPUT_PATH") + +echo "Created the output directory" + +echo "Running pg_dump..." + +# shellcheck disable=SC2086 +pg_dump $INPUT_OPTIONS -d "$INPUT_DATABASE_URL" > "$INPUT_PATH" + +echo "Complete" + +echo "::endgroup::" \ No newline at end of file From 9e8e19cd583a8372c422146dd44fd83a8401aaf4 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 8 Sep 2023 01:34:20 +0000 Subject: [PATCH 04/17] Updated script --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index a8c7df5..c97f4f7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,7 +6,7 @@ echo "::group::pg-dump" echo "Creating the output directory..." -mkdir -p $(dirname "$INPUT_PATH") +mkdir -p "$(dirname "$INPUT_PATH")" echo "Created the output directory" From acc4f6cabe23a65100ae46b376386af63c623506 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 8 Sep 2023 01:48:27 +0000 Subject: [PATCH 05/17] Added support for install postgresql --- entrypoint.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index c97f4f7..e223795 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,6 +10,47 @@ mkdir -p "$(dirname "$INPUT_PATH")" echo "Created the output directory" +if [[ -n "$INPUT_POSTGRESQL_VERSION" ]]; then + echo "Verifying version" + + # Check if the input is an integer + if ! [[ "$INPUT_POSTGRESQL_VERSION" =~ ^[0-9]+$ ]]; then + echo "Error: $INPUT_POSTGRESQL_VERSION is not a valid integer." + exit 1 + fi + + # Check if the input is between 10 and 15 (inclusive) + if (( $INPUT_POSTGRESQL_VERSION < 10 || $INPUT_POSTGRESQL_VERSION > 15 )); then + echo "Error: $INPUT_POSTGRESQL_VERSION is not between 10 and 15 (inclusive)." + exit 1 + fi + + echo "Validated postgresql version: $INPUT_POSTGRESQL_VERSION" + + echo "Installing postgresql..." + + if [[ "$(uname -s)" == "Linux" ]]; then + sudo apt-get update + sudo apt-get install -y "postgresql-$INPUT_POSTGRESQL_VERSION" + elif [[ "$(uname -s)" == "NT"* ]]; then + choco install postgresql --version="$INPUT_POSTGRESQL_VERSION" -y + elif [[ "$(uname -s)" == "Darwin" ]]; then + brew update + brew install "postgresql@$INPUT_POSTGRESQL_VERSION" + else + echo "Unsupported OS" + exit 1 + fi + + if [[ "$(uname -s)" == "NT"* ]]; then + echo "/Program Files/PostgreSQL/15/bin" >> $GITHUB_PATH + else + echo "/usr/lib/postgresql/15/bin" >> $GITHUB_PATH + fi + + echo "Installed postgresql" +fi + echo "Running pg_dump..." # shellcheck disable=SC2086 From a03f8dcfc8e0d6e11e1749eaa018fc4c3bcc95dd Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 7 Sep 2023 19:49:52 -0600 Subject: [PATCH 06/17] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index e223795..05d0772 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -43,9 +43,9 @@ if [[ -n "$INPUT_POSTGRESQL_VERSION" ]]; then fi if [[ "$(uname -s)" == "NT"* ]]; then - echo "/Program Files/PostgreSQL/15/bin" >> $GITHUB_PATH + echo "/Program Files/PostgreSQL/15/bin" >> "$GITHUB_PATH" else - echo "/usr/lib/postgresql/15/bin" >> $GITHUB_PATH + echo "/usr/lib/postgresql/15/bin" >> "$GITHUB_PATH" fi echo "Installed postgresql" From 04f93bed1f4f36769be67234bc8e5500142da868 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 7 Sep 2023 19:51:12 -0600 Subject: [PATCH 07/17] Update entrypoint.sh --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 05d0772..dbab0e2 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -20,7 +20,7 @@ if [[ -n "$INPUT_POSTGRESQL_VERSION" ]]; then fi # Check if the input is between 10 and 15 (inclusive) - if (( $INPUT_POSTGRESQL_VERSION < 10 || $INPUT_POSTGRESQL_VERSION > 15 )); then + if (( INPUT_POSTGRESQL_VERSION < 10 || INPUT_POSTGRESQL_VERSION > 15 )); then echo "Error: $INPUT_POSTGRESQL_VERSION is not between 10 and 15 (inclusive)." exit 1 fi @@ -58,4 +58,4 @@ pg_dump $INPUT_OPTIONS -d "$INPUT_DATABASE_URL" > "$INPUT_PATH" echo "Complete" -echo "::endgroup::" \ No newline at end of file +echo "::endgroup::" From f2a266a51d7f6cc7f24a076d28a154aeaedea66f Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 8 Sep 2023 01:54:30 +0000 Subject: [PATCH 08/17] Updated to check for the output dir --- entrypoint.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index dbab0e2..c18968d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,11 +4,15 @@ set -euo pipefail echo "::group::pg-dump" -echo "Creating the output directory..." +echo "Checking if the output directory exists..." -mkdir -p "$(dirname "$INPUT_PATH")" - -echo "Created the output directory" +if [ ! -d "$(dirname "$INPUT_PATH")" ]; then + echo "The output directory does not exist. Creating it..." + mkdir -p "$(dirname "$INPUT_PATH")" + echo "Created the output directory" +else + echo "The output directory already exists" +fi if [[ -n "$INPUT_POSTGRESQL_VERSION" ]]; then echo "Verifying version" From 20af281a067beffadcbd01670cca6e13f55761f5 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 7 Sep 2023 20:05:14 -0600 Subject: [PATCH 09/17] Update test.yml --- .github/workflows/test.yml | 56 +++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0aaec1d..84f26f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,9 +18,63 @@ jobs: uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 - name: shellcheck uses: reviewdog/action-shellcheck@v1.19 + test-postgresql: + name: Test pg_dump with PostgreSQL version + runs-on: ${{ matrix.platform }} + strategy: + fail-fast: false + matrix: + platform: [ubuntu-latest, windows-latest, macos-latest, macos-11, windows-2022] + postgresql_version: [12, 14, 15] + services: + postgres: + image: postgres:${{ matrix.postgresql_version }} + env: + POSTGRES_USER: test_user + POSTGRES_PASSWORD: test_user_password + POSTGRES_DB: testdb + ports: + - 5432:5432 + # needed because the postgres container does not provide a healthcheck + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token + - name: Run pg_dump + uses: ./ + with: + database_url: "postgres://test_user:test_user_password@localhost:5432/testdb" + postgresql_version: ${{ matrix.postgresql_version }} + path: "backups/${{ matrix.postgresql_version }}/backup.sql" + - name: Check changes to the backup file. + id: changed_backup + if: matrix.platform == 'ubuntu-latest' + uses: tj-actions/verify-changed-files@v16 + with: + files: backups/${{ matrix.postgresql_version }}/backup.sql + + - name: Commit changes to backup file. + if: steps.changed_backup.outputs.files_changed == 'true' && matrix.platform == 'ubuntu-latest' + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git add backups/${{ matrix.postgresql_version }}/backup.sql + git commit -m "Auto updated backup.sql." + + - name: Push changes + if: steps.changed_backup.outputs.files_changed == 'true' && matrix.platform == 'ubuntu-latest' + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.PAT_TOKEN }} + branch: ${{ github.head_ref }} + test: runs-on: ubuntu-latest - name: Test postgres-restore + name: Test pg_dump services: postgres: image: postgres:9.6.24 From b71b2581cd34108e95da510ea7bce49160f95f5b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 8 Sep 2023 02:06:04 +0000 Subject: [PATCH 10/17] Auto updated backup.sql. --- backups/14/backup.sql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 backups/14/backup.sql diff --git a/backups/14/backup.sql b/backups/14/backup.sql new file mode 100644 index 0000000..7033057 --- /dev/null +++ b/backups/14/backup.sql @@ -0,0 +1,22 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 14.9 (Debian 14.9-1.pgdg120+1) +-- Dumped by pg_dump version 14.9 (Ubuntu 14.9-1.pgdg22.04+1) + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +-- +-- PostgreSQL database dump complete +-- + From a3b4512d8addc208367ef7f77f6344e174c6a681 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 7 Sep 2023 20:11:01 -0600 Subject: [PATCH 11/17] Update entrypoint.sh --- entrypoint.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index c18968d..fb85c65 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -34,7 +34,16 @@ if [[ -n "$INPUT_POSTGRESQL_VERSION" ]]; then echo "Installing postgresql..." if [[ "$(uname -s)" == "Linux" ]]; then + # Create the file repository configuration: + sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' + + # Import the repository signing key: + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - + + # Update the package lists: sudo apt-get update + + # Install PostgreSQL sudo apt-get install -y "postgresql-$INPUT_POSTGRESQL_VERSION" elif [[ "$(uname -s)" == "NT"* ]]; then choco install postgresql --version="$INPUT_POSTGRESQL_VERSION" -y From 2774405629b473e5ae29bba2eda4b7c353ddbcfb Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 8 Sep 2023 02:11:57 +0000 Subject: [PATCH 12/17] Auto updated backup.sql. --- backups/12/backup.sql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 backups/12/backup.sql diff --git a/backups/12/backup.sql b/backups/12/backup.sql new file mode 100644 index 0000000..147545d --- /dev/null +++ b/backups/12/backup.sql @@ -0,0 +1,22 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 12.16 (Debian 12.16-1.pgdg120+1) +-- Dumped by pg_dump version 14.9 (Ubuntu 14.9-1.pgdg22.04+1) + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +-- +-- PostgreSQL database dump complete +-- + From 36c0d6ee6be27a450e03770b1cea1fde04a721fa Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 7 Sep 2023 20:19:35 -0600 Subject: [PATCH 13/17] Update entrypoint.sh --- entrypoint.sh | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index fb85c65..3c0c14d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -55,20 +55,27 @@ if [[ -n "$INPUT_POSTGRESQL_VERSION" ]]; then exit 1 fi - if [[ "$(uname -s)" == "NT"* ]]; then - echo "/Program Files/PostgreSQL/15/bin" >> "$GITHUB_PATH" - else - echo "/usr/lib/postgresql/15/bin" >> "$GITHUB_PATH" - fi - echo "Installed postgresql" + + echo "Running pg_dump..." + + # Verify installation by running pg_dump directly + if [[ "$(uname -s)" == "NT"* ]]; then + "/Program Files/PostgreSQL/15/bin/pg_dump" --version + # shellcheck disable=SC2086 + "/Program Files/PostgreSQL/15/bin/pg_dump" $INPUT_OPTIONS -d "$INPUT_DATABASE_URL" > "$INPUT_PATH" + else + "/usr/lib/postgresql/15/bin/pg_dump" --version + # shellcheck disable=SC2086 + "/usr/lib/postgresql/15/bin/pg_dump" $INPUT_OPTIONS -d "$INPUT_DATABASE_URL" > "$INPUT_PATH" + fi +else + echo "Running pg_dump..." + + # shellcheck disable=SC2086 + pg_dump $INPUT_OPTIONS -d "$INPUT_DATABASE_URL" > "$INPUT_PATH" fi -echo "Running pg_dump..." - -# shellcheck disable=SC2086 -pg_dump $INPUT_OPTIONS -d "$INPUT_DATABASE_URL" > "$INPUT_PATH" - echo "Complete" echo "::endgroup::" From 339a7cc8b31578c2cbd54f93f41aad90d5e10694 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 8 Sep 2023 02:20:30 +0000 Subject: [PATCH 14/17] Auto updated backup.sql. --- backups/15/backup.sql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 backups/15/backup.sql diff --git a/backups/15/backup.sql b/backups/15/backup.sql new file mode 100644 index 0000000..912adc1 --- /dev/null +++ b/backups/15/backup.sql @@ -0,0 +1,22 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 15.4 (Debian 15.4-1.pgdg120+1) +-- Dumped by pg_dump version 15.4 (Ubuntu 15.4-1.pgdg22.04+1) + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +-- +-- PostgreSQL database dump complete +-- + From 91010d584c5555855bf4ee6cfe8c713d7b2d7bbb Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 7 Sep 2023 20:22:38 -0600 Subject: [PATCH 15/17] Update entrypoint.sh --- entrypoint.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3c0c14d..bb77739 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -61,13 +61,13 @@ if [[ -n "$INPUT_POSTGRESQL_VERSION" ]]; then # Verify installation by running pg_dump directly if [[ "$(uname -s)" == "NT"* ]]; then - "/Program Files/PostgreSQL/15/bin/pg_dump" --version + "/Program Files/PostgreSQL/$INPUT_POSTGRESQL_VERSION/bin/pg_dump" --version # shellcheck disable=SC2086 - "/Program Files/PostgreSQL/15/bin/pg_dump" $INPUT_OPTIONS -d "$INPUT_DATABASE_URL" > "$INPUT_PATH" + "/Program Files/PostgreSQL/$INPUT_POSTGRESQL_VERSION/bin/pg_dump" $INPUT_OPTIONS -d "$INPUT_DATABASE_URL" > "$INPUT_PATH" else - "/usr/lib/postgresql/15/bin/pg_dump" --version + "/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin/pg_dump" --version # shellcheck disable=SC2086 - "/usr/lib/postgresql/15/bin/pg_dump" $INPUT_OPTIONS -d "$INPUT_DATABASE_URL" > "$INPUT_PATH" + "/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin/pg_dump" $INPUT_OPTIONS -d "$INPUT_DATABASE_URL" > "$INPUT_PATH" fi else echo "Running pg_dump..." From a943f3446949f2ad7459798a362740e7a9e6f22f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 8 Sep 2023 02:23:38 +0000 Subject: [PATCH 16/17] Auto updated backup.sql. --- backups/12/backup.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backups/12/backup.sql b/backups/12/backup.sql index 147545d..a0cd17a 100644 --- a/backups/12/backup.sql +++ b/backups/12/backup.sql @@ -3,7 +3,7 @@ -- -- Dumped from database version 12.16 (Debian 12.16-1.pgdg120+1) --- Dumped by pg_dump version 14.9 (Ubuntu 14.9-1.pgdg22.04+1) +-- Dumped by pg_dump version 12.16 (Ubuntu 12.16-1.pgdg22.04+1) SET statement_timeout = 0; SET lock_timeout = 0; From b325dee4892044f4feef05063bd350e4836ee635 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 12 Sep 2023 12:50:13 -0600 Subject: [PATCH 17/17] Updated action --- entrypoint.sh | 63 +++------------------------------------------------ 1 file changed, 3 insertions(+), 60 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index bb77739..6afb598 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -14,67 +14,10 @@ else echo "The output directory already exists" fi -if [[ -n "$INPUT_POSTGRESQL_VERSION" ]]; then - echo "Verifying version" +echo "Running pg_dump..." - # Check if the input is an integer - if ! [[ "$INPUT_POSTGRESQL_VERSION" =~ ^[0-9]+$ ]]; then - echo "Error: $INPUT_POSTGRESQL_VERSION is not a valid integer." - exit 1 - fi - - # Check if the input is between 10 and 15 (inclusive) - if (( INPUT_POSTGRESQL_VERSION < 10 || INPUT_POSTGRESQL_VERSION > 15 )); then - echo "Error: $INPUT_POSTGRESQL_VERSION is not between 10 and 15 (inclusive)." - exit 1 - fi - - echo "Validated postgresql version: $INPUT_POSTGRESQL_VERSION" - - echo "Installing postgresql..." - - if [[ "$(uname -s)" == "Linux" ]]; then - # Create the file repository configuration: - sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' - - # Import the repository signing key: - wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - - - # Update the package lists: - sudo apt-get update - - # Install PostgreSQL - sudo apt-get install -y "postgresql-$INPUT_POSTGRESQL_VERSION" - elif [[ "$(uname -s)" == "NT"* ]]; then - choco install postgresql --version="$INPUT_POSTGRESQL_VERSION" -y - elif [[ "$(uname -s)" == "Darwin" ]]; then - brew update - brew install "postgresql@$INPUT_POSTGRESQL_VERSION" - else - echo "Unsupported OS" - exit 1 - fi - - echo "Installed postgresql" - - echo "Running pg_dump..." - - # Verify installation by running pg_dump directly - if [[ "$(uname -s)" == "NT"* ]]; then - "/Program Files/PostgreSQL/$INPUT_POSTGRESQL_VERSION/bin/pg_dump" --version - # shellcheck disable=SC2086 - "/Program Files/PostgreSQL/$INPUT_POSTGRESQL_VERSION/bin/pg_dump" $INPUT_OPTIONS -d "$INPUT_DATABASE_URL" > "$INPUT_PATH" - else - "/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin/pg_dump" --version - # shellcheck disable=SC2086 - "/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin/pg_dump" $INPUT_OPTIONS -d "$INPUT_DATABASE_URL" > "$INPUT_PATH" - fi -else - echo "Running pg_dump..." - - # shellcheck disable=SC2086 - pg_dump $INPUT_OPTIONS -d "$INPUT_DATABASE_URL" > "$INPUT_PATH" -fi +# shellcheck disable=SC2086 +pg_dump $INPUT_OPTIONS -d "$INPUT_DATABASE_URL" > "$INPUT_PATH" echo "Complete"