From fcd2d09e4bc4a884526f3b877fc085bc9d30673a Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 19:32:39 -0600 Subject: [PATCH 01/30] feat: add support for caching --- action.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/action.yml b/action.yml index 3de8805..1b79464 100644 --- a/action.yml +++ b/action.yml @@ -9,6 +9,27 @@ inputs: runs: using: 'composite' steps: + - name: Get cache directory + id: cache-dir + run: | + if [[ "${{ runner.os }}" == "Linux" ]]; then + cache_dir=$(apt-cache policy postgresql-${{ inputs.postgresql_version }} | awk '/Filename/ {print $2}') + elif [[ "${{ runner.os }}" == "macOS" ]]; then + cache_dir=$(brew --cache postgresql@${{ inputs.postgresql_version }}) + elif [[ "${{ runner.os }}" == "Windows" ]]; then + cache_dir=$(choco search postgresql${{ inputs.postgresql_version }} --exact --limit-output | grep "^postgresql " | awk '{print $NF}') + fi + echo "::set-output name=cache_dir::$cache_dir" + shell: bash + + - name: Cache + uses: actions/cache@v3 + with: + path: ${{ steps.cache-dir.outputs.cache_dir }} + key: ${{ runner.os }}-postgresql-${{ inputs.postgresql_version }} + restore-keys: | + ${{ runner.os }}-postgresql- + - run: | bash $GITHUB_ACTION_PATH/entrypoint.sh shell: bash From b57977ae8ce9f8a1ced86782910b1f440ec792ad Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 19:49:09 -0600 Subject: [PATCH 02/30] Updated command --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 1b79464..739d33d 100644 --- a/action.yml +++ b/action.yml @@ -19,7 +19,7 @@ runs: elif [[ "${{ runner.os }}" == "Windows" ]]; then cache_dir=$(choco search postgresql${{ inputs.postgresql_version }} --exact --limit-output | grep "^postgresql " | awk '{print $NF}') fi - echo "::set-output name=cache_dir::$cache_dir" + echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT" shell: bash - name: Cache From 3e974ef08f174b5f82c66cac07fe20b1f2441be9 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 19:56:33 -0600 Subject: [PATCH 03/30] Enable debug mode --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index 739d33d..79d9aa2 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,7 @@ runs: - name: Get cache directory id: cache-dir run: | + set -x if [[ "${{ runner.os }}" == "Linux" ]]; then cache_dir=$(apt-cache policy postgresql-${{ inputs.postgresql_version }} | awk '/Filename/ {print $2}') elif [[ "${{ runner.os }}" == "macOS" ]]; then From 95ffbd5bd3404e8e29ddf9cebb490af038aca0b2 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 19:58:31 -0600 Subject: [PATCH 04/30] Add support for canceling other jobs --- .github/workflows/test.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eb83f1d..01b7fdb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,6 +12,9 @@ jobs: shellcheck: name: Run shellcheck runs-on: ubuntu-latest + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true steps: - name: Checkout to branch @@ -23,6 +26,9 @@ jobs: test: name: Test setup-postgresql runs-on: ${{ matrix.platform }} + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true strategy: fail-fast: false matrix: From e96635ed27d63af488323b6319a0487f15037d20 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 19:59:18 -0600 Subject: [PATCH 05/30] Add support for canceling other jobs --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 01b7fdb..fe5db9d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: name: Run shellcheck runs-on: ubuntu-latest concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }} cancel-in-progress: true steps: @@ -27,7 +27,7 @@ jobs: name: Test setup-postgresql runs-on: ${{ matrix.platform }} concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }} cancel-in-progress: true strategy: fail-fast: false From 9bc78da19393904bb3b2934d7fe6a48c8c5181a3 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 20:03:33 -0600 Subject: [PATCH 06/30] Add support for canceling other jobs --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fe5db9d..bf3737c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: name: Run shellcheck runs-on: ubuntu-latest concurrency: - group: ${{ github.workflow }} + group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true steps: From c9e37a78f986e7554714db45ade490167000ce74 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 20:04:11 -0600 Subject: [PATCH 07/30] Add support for canceling other jobs --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bf3737c..981d960 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,7 @@ jobs: name: Test setup-postgresql runs-on: ${{ matrix.platform }} concurrency: - group: ${{ github.workflow }} + group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.platform }} cancel-in-progress: true strategy: fail-fast: false From 8d053155908d90dc552972ee5cd164d05efff8af Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 20:04:40 -0600 Subject: [PATCH 08/30] Add support for canceling other jobs --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 981d960..01b7fdb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,7 @@ jobs: name: Test setup-postgresql runs-on: ${{ matrix.platform }} concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.platform }} + group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true strategy: fail-fast: false From 39e764703d6d131aec605315844cb1a20696f8e5 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 20:06:01 -0600 Subject: [PATCH 09/30] Add support for canceling other jobs --- .github/workflows/test.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 01b7fdb..eb83f1d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,9 +12,6 @@ jobs: shellcheck: name: Run shellcheck runs-on: ubuntu-latest - concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true steps: - name: Checkout to branch @@ -26,9 +23,6 @@ jobs: test: name: Test setup-postgresql runs-on: ${{ matrix.platform }} - concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true strategy: fail-fast: false matrix: From 3f1b044b5739b7f7ab28c9f6cf3b872b00bf679c Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 20:06:10 -0600 Subject: [PATCH 10/30] Add support for canceling other jobs --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eb83f1d..e8c9451 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,6 @@ jobs: shellcheck: name: Run shellcheck runs-on: ubuntu-latest - steps: - name: Checkout to branch uses: actions/checkout@v4 From 242b4d6e4bb9de68aba9e3619fb4bc6b56e0ca1b Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 20:23:01 -0600 Subject: [PATCH 11/30] Add support for canceling other jobs --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 79d9aa2..f006025 100644 --- a/action.yml +++ b/action.yml @@ -18,7 +18,8 @@ runs: elif [[ "${{ runner.os }}" == "macOS" ]]; then cache_dir=$(brew --cache postgresql@${{ inputs.postgresql_version }}) elif [[ "${{ runner.os }}" == "Windows" ]]; then - cache_dir=$(choco search postgresql${{ inputs.postgresql_version }} --exact --limit-output | grep "^postgresql " | awk '{print $NF}') + choco cache list + cache_dir=$(choco cache list | grep 'postgresql${{ inputs.postgresql_version }}') fi echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT" shell: bash From dce70a13b673b54d858098f9a2c8eee5cbb6aa70 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 20:34:01 -0600 Subject: [PATCH 12/30] Updated cache location for windows --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f006025..94ac954 100644 --- a/action.yml +++ b/action.yml @@ -18,7 +18,8 @@ runs: elif [[ "${{ runner.os }}" == "macOS" ]]; then cache_dir=$(brew --cache postgresql@${{ inputs.postgresql_version }}) elif [[ "${{ runner.os }}" == "Windows" ]]; then - choco cache list + choco config get cacheLocation + ls -al $(choco config get cacheLocation) cache_dir=$(choco cache list | grep 'postgresql${{ inputs.postgresql_version }}') fi echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT" From c00d9b21722b774d42275771b43f465df6d5d7e2 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 20:37:44 -0600 Subject: [PATCH 13/30] Updated cache location for windows --- action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 94ac954..7f37dba 100644 --- a/action.yml +++ b/action.yml @@ -18,8 +18,7 @@ runs: elif [[ "${{ runner.os }}" == "macOS" ]]; then cache_dir=$(brew --cache postgresql@${{ inputs.postgresql_version }}) elif [[ "${{ runner.os }}" == "Windows" ]]; then - choco config get cacheLocation - ls -al $(choco config get cacheLocation) + choco search postgresql --exact --all-versions --limit-output --order-by-popularity --by-id-only --approved-only --download-cache cache_dir=$(choco cache list | grep 'postgresql${{ inputs.postgresql_version }}') fi echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT" From 50ccdd3b84a3c66fa651e9c67dc05749aae8cfa5 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 20:39:16 -0600 Subject: [PATCH 14/30] Updated cache location for windows --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 7f37dba..201a8c9 100644 --- a/action.yml +++ b/action.yml @@ -18,7 +18,7 @@ runs: elif [[ "${{ runner.os }}" == "macOS" ]]; then cache_dir=$(brew --cache postgresql@${{ inputs.postgresql_version }}) elif [[ "${{ runner.os }}" == "Windows" ]]; then - choco search postgresql --exact --all-versions --limit-output --order-by-popularity --by-id-only --approved-only --download-cache + choco search postgresql --download-cache cache_dir=$(choco cache list | grep 'postgresql${{ inputs.postgresql_version }}') fi echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT" From 485db8ac03ced001cbbdcb8f9a7d3c80586fcc98 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 20:43:51 -0600 Subject: [PATCH 15/30] Updated cache location for windows --- action.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 201a8c9..990de1d 100644 --- a/action.yml +++ b/action.yml @@ -14,12 +14,11 @@ runs: run: | set -x if [[ "${{ runner.os }}" == "Linux" ]]; then - cache_dir=$(apt-cache policy postgresql-${{ inputs.postgresql_version }} | awk '/Filename/ {print $2}') + cache_dir="$(apt-cache policy postgresql-${{ inputs.postgresql_version }} | awk '/Filename/ {print $2}')" elif [[ "${{ runner.os }}" == "macOS" ]]; then - cache_dir=$(brew --cache postgresql@${{ inputs.postgresql_version }}) + cache_dir="$(brew --cache postgresql@${{ inputs.postgresql_version }})" elif [[ "${{ runner.os }}" == "Windows" ]]; then - choco search postgresql --download-cache - cache_dir=$(choco cache list | grep 'postgresql${{ inputs.postgresql_version }}') + cache_dir="~/AppData/Local/Temp/chocolatey/postgresql-${{ inputs.postgresql_version }}" fi echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT" shell: bash From f5b80f433c58de88c86121e9e27f36ab635ebd5c Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 20:45:23 -0600 Subject: [PATCH 16/30] Updated cache location for windows --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 990de1d..d78e0a5 100644 --- a/action.yml +++ b/action.yml @@ -18,7 +18,7 @@ runs: elif [[ "${{ runner.os }}" == "macOS" ]]; then cache_dir="$(brew --cache postgresql@${{ inputs.postgresql_version }})" elif [[ "${{ runner.os }}" == "Windows" ]]; then - cache_dir="~/AppData/Local/Temp/chocolatey/postgresql-${{ inputs.postgresql_version }}" + cache_dir="~\AppData\Local\Temp\chocolatey\postgresql-${{ inputs.postgresql_version }}" fi echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT" shell: bash From 21f166ec887fc773598096f5015f68491ae62f45 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 20:55:58 -0600 Subject: [PATCH 17/30] Updated the test --- .github/workflows/test.yml | 5 +++++ entrypoint.sh | 3 --- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e8c9451..e6fa307 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,3 +34,8 @@ jobs: uses: ./ with: postgresql_version: ${{ matrix.postgresql_version }} + - name: Verify PostgreSQL + run: | + pg_dump --version + psql --version + pg_restore --version diff --git a/entrypoint.sh b/entrypoint.sh index 9290fe7..4812762 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -52,13 +52,10 @@ echo "Verifying installation..." # Verify installation by running pg_dump directly if [[ "$(uname -s)" == "NT"* ]] || [[ "$(uname -s)" == "MINGW"* ]] || [[ "$(uname -s)" == *"MSYS"* ]]; then - "C:\\Program Files\\PostgreSQL\\$INPUT_POSTGRESQL_VERSION\\bin\\pg_dump" --version echo "C:\\Program Files\\PostgreSQL\\$INPUT_POSTGRESQL_VERSION\\bin" >> $GITHUB_PATH elif [[ "$(uname -s)" == "Darwin" ]]; then - "/usr/local/opt/postgresql@${INPUT_POSTGRESQL_VERSION}/bin/pg_dump" --version echo "/usr/local/opt/postgresql@${INPUT_POSTGRESQL_VERSION}/bin" >> $GITHUB_PATH else - "/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin/pg_dump" --version echo "/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin" >> $GITHUB_PATH fi From c2c46a23cd560b986312e888fd3298e8ed28db03 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 20:59:46 -0600 Subject: [PATCH 18/30] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- entrypoint.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 4812762..bfdb7a7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -52,11 +52,11 @@ echo "Verifying installation..." # Verify installation by running pg_dump directly if [[ "$(uname -s)" == "NT"* ]] || [[ "$(uname -s)" == "MINGW"* ]] || [[ "$(uname -s)" == *"MSYS"* ]]; then - echo "C:\\Program Files\\PostgreSQL\\$INPUT_POSTGRESQL_VERSION\\bin" >> $GITHUB_PATH + echo "C:\\Program Files\\PostgreSQL\\$INPUT_POSTGRESQL_VERSION\\bin" >> "$GITHUB_PATH" elif [[ "$(uname -s)" == "Darwin" ]]; then - echo "/usr/local/opt/postgresql@${INPUT_POSTGRESQL_VERSION}/bin" >> $GITHUB_PATH + echo "/usr/local/opt/postgresql@${INPUT_POSTGRESQL_VERSION}/bin" >> "$GITHUB_PATH" else - echo "/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin" >> $GITHUB_PATH + echo "/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin" >> "$GITHUB_PATH" fi echo "Complete" From 91c902361b9490a8533b92f00a6e8ef92a746ba6 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 11 Sep 2023 21:03:36 -0600 Subject: [PATCH 19/30] Updated to fix lint errors --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index bfdb7a7..2eef567 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -52,6 +52,7 @@ echo "Verifying installation..." # Verify installation by running pg_dump directly if [[ "$(uname -s)" == "NT"* ]] || [[ "$(uname -s)" == "MINGW"* ]] || [[ "$(uname -s)" == *"MSYS"* ]]; then + # shellcheck disable=SC2028 echo "C:\\Program Files\\PostgreSQL\\$INPUT_POSTGRESQL_VERSION\\bin" >> "$GITHUB_PATH" elif [[ "$(uname -s)" == "Darwin" ]]; then echo "/usr/local/opt/postgresql@${INPUT_POSTGRESQL_VERSION}/bin" >> "$GITHUB_PATH" From e93d0bc2a598163568ab3232ab0b900f63e260aa Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 12 Sep 2023 10:06:07 -0600 Subject: [PATCH 20/30] Updated the install location --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2eef567..364d8e7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -35,7 +35,7 @@ if [[ "$(uname -s)" == "Linux" ]]; then sudo apt-get update # Install PostgreSQL - sudo apt-get install -y "postgresql-$INPUT_POSTGRESQL_VERSION" + sudo apt-get apt-get -o Dir::Cache::Archives=/tmp install -y "postgresql-$INPUT_POSTGRESQL_VERSION" elif [[ "$(uname -s)" == "NT"* ]] || [[ "$(uname -s)" == "MINGW"* ]] || [[ "$(uname -s)" == *"MSYS"* ]]; then choco install "postgresql$INPUT_POSTGRESQL_VERSION" -y --no-progress elif [[ "$(uname -s)" == "Darwin" ]]; then @@ -48,7 +48,7 @@ fi echo "Installed postgresql" -echo "Verifying installation..." +echo "Updating PATH..." # Verify installation by running pg_dump directly if [[ "$(uname -s)" == "NT"* ]] || [[ "$(uname -s)" == "MINGW"* ]] || [[ "$(uname -s)" == *"MSYS"* ]]; then From 72dd9bcd9541c3e5c70bc5f88c3f1b3d257590d8 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 12 Sep 2023 10:10:25 -0600 Subject: [PATCH 21/30] Update the cache-location --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 364d8e7..df9f59d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -37,7 +37,7 @@ if [[ "$(uname -s)" == "Linux" ]]; then # Install PostgreSQL sudo apt-get apt-get -o Dir::Cache::Archives=/tmp install -y "postgresql-$INPUT_POSTGRESQL_VERSION" elif [[ "$(uname -s)" == "NT"* ]] || [[ "$(uname -s)" == "MINGW"* ]] || [[ "$(uname -s)" == *"MSYS"* ]]; then - choco install "postgresql$INPUT_POSTGRESQL_VERSION" -y --no-progress + choco install "postgresql$INPUT_POSTGRESQL_VERSION" -y --no-progress --cache-location="C:\\ProgramData\\chocolatey\\cache" elif [[ "$(uname -s)" == "Darwin" ]]; then brew update brew install "postgresql@$INPUT_POSTGRESQL_VERSION" From 4601cdae13783b887b7c6fbe9c4756985e857627 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 12 Sep 2023 10:14:41 -0600 Subject: [PATCH 22/30] Updated cache location --- action.yml | 4 ++-- entrypoint.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 8ddca84..0dada4a 100644 --- a/action.yml +++ b/action.yml @@ -14,11 +14,11 @@ runs: run: | set -x if [[ "${{ runner.os }}" == "Linux" ]]; then - cache_dir="$(apt-cache policy postgresql-${{ inputs.postgresql_version }} | awk '/Filename/ {print $2}')" + cache_dir="/var/cache/apt/archives/" elif [[ "${{ runner.os }}" == "macOS" ]]; then cache_dir="$(brew --cache postgresql@${{ inputs.postgresql_version }})" elif [[ "${{ runner.os }}" == "Windows" ]]; then - cache_dir="~\AppData\Local\Temp\chocolatey\postgresql-${{ inputs.postgresql_version }}" + cache_dir="~\AppData\Local\Temp\chocolatey" fi echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT" shell: bash diff --git a/entrypoint.sh b/entrypoint.sh index df9f59d..d3dc836 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -35,9 +35,9 @@ if [[ "$(uname -s)" == "Linux" ]]; then sudo apt-get update # Install PostgreSQL - sudo apt-get apt-get -o Dir::Cache::Archives=/tmp install -y "postgresql-$INPUT_POSTGRESQL_VERSION" + sudo apt-get apt-get install -y "postgresql-$INPUT_POSTGRESQL_VERSION" elif [[ "$(uname -s)" == "NT"* ]] || [[ "$(uname -s)" == "MINGW"* ]] || [[ "$(uname -s)" == *"MSYS"* ]]; then - choco install "postgresql$INPUT_POSTGRESQL_VERSION" -y --no-progress --cache-location="C:\\ProgramData\\chocolatey\\cache" + choco install "postgresql$INPUT_POSTGRESQL_VERSION" -y --no-progress elif [[ "$(uname -s)" == "Darwin" ]]; then brew update brew install "postgresql@$INPUT_POSTGRESQL_VERSION" From 5b0f08362acd081facb164824af1c202a8a22611 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 12 Sep 2023 10:28:12 -0600 Subject: [PATCH 23/30] Fixed typo --- action.yml | 1 - entrypoint.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 0dada4a..3541e6c 100644 --- a/action.yml +++ b/action.yml @@ -12,7 +12,6 @@ runs: - name: Get cache directory id: cache-dir run: | - set -x if [[ "${{ runner.os }}" == "Linux" ]]; then cache_dir="/var/cache/apt/archives/" elif [[ "${{ runner.os }}" == "macOS" ]]; then diff --git a/entrypoint.sh b/entrypoint.sh index d3dc836..bc424d6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -35,7 +35,7 @@ if [[ "$(uname -s)" == "Linux" ]]; then sudo apt-get update # Install PostgreSQL - sudo apt-get apt-get install -y "postgresql-$INPUT_POSTGRESQL_VERSION" + sudo apt-get install -y "postgresql-$INPUT_POSTGRESQL_VERSION" elif [[ "$(uname -s)" == "NT"* ]] || [[ "$(uname -s)" == "MINGW"* ]] || [[ "$(uname -s)" == *"MSYS"* ]]; then choco install "postgresql$INPUT_POSTGRESQL_VERSION" -y --no-progress elif [[ "$(uname -s)" == "Darwin" ]]; then From 792069e9f322d5c7a1bdf89c9cc26d65f6577a4a Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 12 Sep 2023 10:41:29 -0600 Subject: [PATCH 24/30] Add support for validating the postgresql version --- action.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 3541e6c..ee7bb84 100644 --- a/action.yml +++ b/action.yml @@ -12,9 +12,8 @@ runs: - name: Get cache directory id: cache-dir run: | - if [[ "${{ runner.os }}" == "Linux" ]]; then - cache_dir="/var/cache/apt/archives/" - elif [[ "${{ runner.os }}" == "macOS" ]]; then + cache_dir="" + if [[ "${{ runner.os }}" == "macOS" ]]; then cache_dir="$(brew --cache postgresql@${{ inputs.postgresql_version }})" elif [[ "${{ runner.os }}" == "Windows" ]]; then cache_dir="~\AppData\Local\Temp\chocolatey" @@ -24,6 +23,8 @@ runs: - name: Cache uses: actions/cache@v3 + id: cache-postgresql + if: steps.cache-dir.outputs.cache_dir != '' with: path: ${{ steps.cache-dir.outputs.cache_dir }} key: ${{ runner.os }}-postgresql-${{ inputs.postgresql_version }} @@ -33,10 +34,21 @@ runs: - run: | bash $GITHUB_ACTION_PATH/entrypoint.sh shell: bash + if: steps.cache-postgresql.outputs.cache-hit != 'true' 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 }} + + - name: Verify PostgreSQL + run: | + # Check the postgresql version + POSTGRESQL_VERSION=$(psql --version | awk '{print $3}') + if [[ "$POSTGRESQL_VERSION" != "${{ inputs.postgresql_version }}."* ]]; then + echo "PostgreSQL version $POSTGRESQL_VERSION does not match the expected version ${{ inputs.postgresql_version }}.*" + exit 1 + fi + shell: bash branding: icon: hard-drive color: white From fef22a2be788150474c58cab06260f6c4e94fb35 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 12 Sep 2023 10:45:38 -0600 Subject: [PATCH 25/30] Updated to not skip cache --- action.yml | 1 - entrypoint.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/action.yml b/action.yml index ee7bb84..28a212d 100644 --- a/action.yml +++ b/action.yml @@ -34,7 +34,6 @@ runs: - run: | bash $GITHUB_ACTION_PATH/entrypoint.sh shell: bash - if: steps.cache-postgresql.outputs.cache-hit != 'true' env: # INPUT_ is not available in Composite run steps # https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611 diff --git a/entrypoint.sh b/entrypoint.sh index bc424d6..351ce61 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -37,7 +37,7 @@ if [[ "$(uname -s)" == "Linux" ]]; then # Install PostgreSQL sudo apt-get install -y "postgresql-$INPUT_POSTGRESQL_VERSION" elif [[ "$(uname -s)" == "NT"* ]] || [[ "$(uname -s)" == "MINGW"* ]] || [[ "$(uname -s)" == *"MSYS"* ]]; then - choco install "postgresql$INPUT_POSTGRESQL_VERSION" -y --no-progress + choco install "postgresql$INPUT_POSTGRESQL_VERSION" -y --no-progress --use-download-cache elif [[ "$(uname -s)" == "Darwin" ]]; then brew update brew install "postgresql@$INPUT_POSTGRESQL_VERSION" From e9a909669043422e08eb9b7b4e573c18874c6569 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 12 Sep 2023 11:00:57 -0600 Subject: [PATCH 26/30] Add support for skipping cache for windows --- action.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/action.yml b/action.yml index 28a212d..117f5ba 100644 --- a/action.yml +++ b/action.yml @@ -34,6 +34,15 @@ runs: - run: | bash $GITHUB_ACTION_PATH/entrypoint.sh shell: bash + # Skip if cache hit and it's on Windows + if: | + ( + runner.os == 'Windows' && steps.cache-postgresql.outputs.cache-hit != 'true' + ) + || + ( + runner.os != 'Windows' + ) env: # INPUT_ is not available in Composite run steps # https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611 From 8e47058fa9ed23724032d8ebd6d5038b0354d13f Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 12 Sep 2023 11:11:05 -0600 Subject: [PATCH 27/30] Updated the PATH regardless of cache hit outcome --- action.yml | 9 +++++++++ entrypoint.sh | 14 -------------- update-path.sh | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 update-path.sh diff --git a/action.yml b/action.yml index 117f5ba..11d1f31 100644 --- a/action.yml +++ b/action.yml @@ -48,6 +48,15 @@ runs: # https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611 INPUT_POSTGRESQL_VERSION: ${{ inputs.postgresql_version }} + - name: Update PATH + run: | + bash $GITHUB_ACTION_PATH/update-path.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 }} + - name: Verify PostgreSQL run: | # Check the postgresql version diff --git a/entrypoint.sh b/entrypoint.sh index 351ce61..db9cef9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -48,18 +48,4 @@ fi echo "Installed postgresql" -echo "Updating PATH..." - -# Verify installation by running pg_dump directly -if [[ "$(uname -s)" == "NT"* ]] || [[ "$(uname -s)" == "MINGW"* ]] || [[ "$(uname -s)" == *"MSYS"* ]]; then - # shellcheck disable=SC2028 - echo "C:\\Program Files\\PostgreSQL\\$INPUT_POSTGRESQL_VERSION\\bin" >> "$GITHUB_PATH" -elif [[ "$(uname -s)" == "Darwin" ]]; then - echo "/usr/local/opt/postgresql@${INPUT_POSTGRESQL_VERSION}/bin" >> "$GITHUB_PATH" -else - echo "/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin" >> "$GITHUB_PATH" -fi - -echo "Complete" - echo "::endgroup::" diff --git a/update-path.sh b/update-path.sh new file mode 100644 index 0000000..2519e37 --- /dev/null +++ b/update-path.sh @@ -0,0 +1,17 @@ +echo "::group::set-postgres-path" + +echo "Updating PATH..." + +# Verify installation by running pg_dump directly +if [[ "$(uname -s)" == "NT"* ]] || [[ "$(uname -s)" == "MINGW"* ]] || [[ "$(uname -s)" == *"MSYS"* ]]; then + # shellcheck disable=SC2028 + echo "C:\\Program Files\\PostgreSQL\\$INPUT_POSTGRESQL_VERSION\\bin" >> "$GITHUB_PATH" +elif [[ "$(uname -s)" == "Darwin" ]]; then + echo "/usr/local/opt/postgresql@${INPUT_POSTGRESQL_VERSION}/bin" >> "$GITHUB_PATH" +else + echo "/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin" >> "$GITHUB_PATH" +fi + +echo "Complete" + +echo "::endgroup::" \ No newline at end of file From 98feacd4214266231cc14ba814f58c5fa0edb712 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 12 Sep 2023 11:13:30 -0600 Subject: [PATCH 28/30] Remove unused code --- action.yml | 18 ------------------ entrypoint.sh | 14 ++++++++++++++ update-path.sh | 17 ----------------- 3 files changed, 14 insertions(+), 35 deletions(-) delete mode 100644 update-path.sh diff --git a/action.yml b/action.yml index 11d1f31..28a212d 100644 --- a/action.yml +++ b/action.yml @@ -34,24 +34,6 @@ runs: - run: | bash $GITHUB_ACTION_PATH/entrypoint.sh shell: bash - # Skip if cache hit and it's on Windows - if: | - ( - runner.os == 'Windows' && steps.cache-postgresql.outputs.cache-hit != 'true' - ) - || - ( - runner.os != 'Windows' - ) - 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 }} - - - name: Update PATH - run: | - bash $GITHUB_ACTION_PATH/update-path.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 diff --git a/entrypoint.sh b/entrypoint.sh index db9cef9..351ce61 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -48,4 +48,18 @@ fi echo "Installed postgresql" +echo "Updating PATH..." + +# Verify installation by running pg_dump directly +if [[ "$(uname -s)" == "NT"* ]] || [[ "$(uname -s)" == "MINGW"* ]] || [[ "$(uname -s)" == *"MSYS"* ]]; then + # shellcheck disable=SC2028 + echo "C:\\Program Files\\PostgreSQL\\$INPUT_POSTGRESQL_VERSION\\bin" >> "$GITHUB_PATH" +elif [[ "$(uname -s)" == "Darwin" ]]; then + echo "/usr/local/opt/postgresql@${INPUT_POSTGRESQL_VERSION}/bin" >> "$GITHUB_PATH" +else + echo "/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin" >> "$GITHUB_PATH" +fi + +echo "Complete" + echo "::endgroup::" diff --git a/update-path.sh b/update-path.sh deleted file mode 100644 index 2519e37..0000000 --- a/update-path.sh +++ /dev/null @@ -1,17 +0,0 @@ -echo "::group::set-postgres-path" - -echo "Updating PATH..." - -# Verify installation by running pg_dump directly -if [[ "$(uname -s)" == "NT"* ]] || [[ "$(uname -s)" == "MINGW"* ]] || [[ "$(uname -s)" == *"MSYS"* ]]; then - # shellcheck disable=SC2028 - echo "C:\\Program Files\\PostgreSQL\\$INPUT_POSTGRESQL_VERSION\\bin" >> "$GITHUB_PATH" -elif [[ "$(uname -s)" == "Darwin" ]]; then - echo "/usr/local/opt/postgresql@${INPUT_POSTGRESQL_VERSION}/bin" >> "$GITHUB_PATH" -else - echo "/usr/lib/postgresql/$INPUT_POSTGRESQL_VERSION/bin" >> "$GITHUB_PATH" -fi - -echo "Complete" - -echo "::endgroup::" \ No newline at end of file From 9253832bfdb7168bfbe7beccdd802512de9e1d59 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 12 Sep 2023 11:15:24 -0600 Subject: [PATCH 29/30] Added a known limitation --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 18b8f1e..4676734 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,13 @@ This Github action installs PostgreSQL on the GitHub actions runner and verifies + +## Known Limitations + +> **Warning** +> +> Slow to install on Windows runners. + * Free software: [MIT license](LICENSE) If you feel generous and want to show some extra appreciation: From d744a533135207cc69497a949c7e6f70ab46a0c3 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 12 Sep 2023 11:15:53 -0600 Subject: [PATCH 30/30] Updated known limitation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4676734..df1d9c0 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ This Github action installs PostgreSQL on the GitHub actions runner and verifies > **Warning** > -> Slow to install on Windows runners. +> * Slow to install on Windows runners. * Free software: [MIT license](LICENSE)