diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ddb3cb..e6fa307 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 diff --git a/README.md b/README.md index 18b8f1e..df1d9c0 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: diff --git a/action.yml b/action.yml index 2d41b20..28a212d 100644 --- a/action.yml +++ b/action.yml @@ -9,6 +9,28 @@ inputs: runs: using: 'composite' steps: + - name: Get cache directory + id: cache-dir + run: | + 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" + fi + echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT" + shell: bash + + - 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 }} + restore-keys: | + ${{ runner.os }}-postgresql- + - run: | bash $GITHUB_ACTION_PATH/entrypoint.sh shell: bash @@ -16,6 +38,16 @@ runs: # 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 diff --git a/entrypoint.sh b/entrypoint.sh index 2eef567..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" @@ -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