mirror of
https://github.com/tj-actions/install-postgresql.git
synced 2024-12-20 01:18:18 +00:00
Merge pull request #3 from tj-actions/feat/add-support-for-caching
This commit is contained in:
commit
52c3783476
4 changed files with 41 additions and 3 deletions
1
.github/workflows/test.yml
vendored
1
.github/workflows/test.yml
vendored
|
@ -12,7 +12,6 @@ jobs:
|
|||
shellcheck:
|
||||
name: Run shellcheck
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout to branch
|
||||
uses: actions/checkout@v4
|
||||
|
|
|
@ -32,6 +32,13 @@ This Github action installs PostgreSQL on the GitHub actions runner and verifies
|
|||
|
||||
<!-- AUTO-DOC-INPUT:END -->
|
||||
|
||||
|
||||
## 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:
|
||||
|
|
32
action.yml
32
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_<VARIABLE_NAME> 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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue