Skip to content

Commit

Permalink
try fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cpunion committed Dec 9, 2024
1 parent 751a48b commit 65988e5
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 89 deletions.
48 changes: 32 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,54 @@ jobs:
postgres-version: '17'

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- name: Setup pgvector
uses: ./
with:
postgres-version: ${{ matrix.postgres-version }}

postgres-user: testuser
postgres-password: testpass
postgres-db: testdb

- name: Test Extension (Unix)
if: runner.os != 'Windows'
env:
PGUSER: testuser
PGPASSWORD: testpass
PGDATABASE: testdb
run: |
psql -d postgres -c 'CREATE EXTENSION IF NOT EXISTS vector;'
psql -d postgres -c 'CREATE TABLE IF NOT EXISTS items (id bigserial PRIMARY KEY, embedding vector(3));'
psql -d postgres -c "INSERT INTO items (embedding) VALUES ('[1,2,3]');"
psql -d postgres -c 'SELECT * FROM items;'
psql -c 'CREATE EXTENSION IF NOT EXISTS vector;'
psql -c 'CREATE TABLE IF NOT EXISTS items (id bigserial PRIMARY KEY, embedding vector(3));'
psql -c "INSERT INTO items (embedding) VALUES ('[1,2,3]');"
psql -c 'SELECT * FROM items;'
- name: Setup Test Data (Windows)
- name: Test Extension (Windows PowerShell)
if: runner.os == 'Windows'
shell: pwsh
env:
PGUSER: testuser
PGPASSWORD: testpass
PGDATABASE: testdb
run: |
psql -d postgres -c 'CREATE EXTENSION IF NOT EXISTS vector;'
psql -d postgres -c 'CREATE TABLE IF NOT EXISTS items (id bigserial PRIMARY KEY, embedding vector(3));'
psql -d postgres -c "INSERT INTO items (embedding) VALUES ('[1,2,3]');"
psql -d postgres -c 'SELECT * FROM items;'
psql -c 'SELECT * FROM items;'
- name: Test Query (Windows CMD)
- name: Test Extension (Windows CMD)
if: runner.os == 'Windows'
shell: cmd
run: psql -d postgres -c "SELECT * FROM items;"
env:
PGUSER: testuser
PGPASSWORD: testpass
PGDATABASE: testdb
run: psql -c "SELECT * FROM items;"

- name: Test Query (Windows MSYS2)
- name: Test Extension (Windows MSYS2)
if: runner.os == 'Windows'
shell: msys2 {0}
run: psql -d postgres -c 'SELECT * FROM items;'
env:
PGUSER: testuser
PGPASSWORD: testpass
PGDATABASE: testdb
run: psql -c 'SELECT * FROM items;'
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ steps:
with:
postgres-version: '17' # optional, defaults to 17. Use 14 for ubuntu-22.04 and ubuntu-20.04
pgvector-version: '0.8.0' # optional, defaults to 0.8.0
postgres-user: 'myuser' # optional, defaults to 'postgres'
postgres-password: 'mypassword' # optional, defaults to 'postgres'
postgres-db: 'mydb' # optional, defaults to 'postgres'
```
## Inputs
- `postgres-version`: PostgreSQL version to use (default: '17'). Note: Use '14' for ubuntu-22.04 and ubuntu-20.04.
- `pgvector-version`: pgvector version to install (default: '0.8.0')
- `postgres-user`: PostgreSQL user to create (default: 'postgres')
- `postgres-password`: PostgreSQL user password (default: 'postgres')
- `postgres-db`: PostgreSQL database to create (default: 'postgres')

## Platform Support

Expand Down Expand Up @@ -50,9 +56,19 @@ jobs:
with:
postgres-version: '17' # Use '14' for ubuntu-22.04 and ubuntu-20.04
pgvector-version: '0.8.0'
postgres-user: 'myuser'
postgres-password: 'mypassword'
postgres-db: 'mydb'
- name: Create extension
run: |
sudo -u postgres psql -c 'CREATE EXTENSION vector;'
- name: Test Connection
env:
PGUSER: myuser
PGPASSWORD: mypassword
PGDATABASE: mydb
run: |
psql -c 'SELECT version();'
```

### macOS
Expand All @@ -70,9 +86,19 @@ jobs:
uses: cpunion/setup-pgvector@v1
with:
pgvector-version: '0.8.0'
postgres-user: 'myuser'
postgres-password: 'mypassword'
postgres-db: 'mydb'
- name: Create extension
run: |
psql postgres -c 'CREATE EXTENSION vector;'
- name: Test Connection
env:
PGUSER: myuser
PGPASSWORD: mypassword
PGDATABASE: mydb
run: |
psql -c 'SELECT version();'
```

### Windows
Expand All @@ -93,10 +119,20 @@ jobs:
uses: cpunion/setup-pgvector@v1
with:
pgvector-version: '0.8.0'
postgres-user: 'myuser'
postgres-password: 'mypassword'
postgres-db: 'mydb'
- name: Create extension
shell: cmd
run: |
psql -U postgres -c "CREATE EXTENSION vector;"
- name: Test Connection
env:
PGUSER: myuser
PGPASSWORD: mypassword
PGDATABASE: mydb
run: |
psql -c "SELECT version();"
```

## License
Expand Down
33 changes: 30 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ inputs:
description: 'pgvector version to install'
required: false
default: '0.8.0'
postgres-user:
description: 'PostgreSQL user to create'
required: false
default: 'postgres'
postgres-password:
description: 'PostgreSQL user password'
required: false
default: 'postgres'
postgres-db:
description: 'PostgreSQL database to create'
required: false
default: 'postgres'
runs:
using: "composite"
steps:
Expand All @@ -17,14 +29,24 @@ runs:
shell: bash
run: |
chmod +x ${{ github.action_path }}/scripts/install-ubuntu.sh
${{ github.action_path }}/scripts/install-ubuntu.sh ${{ inputs.postgres-version }} ${{ inputs.pgvector-version }}
${{ github.action_path }}/scripts/install-ubuntu.sh \
${{ inputs.postgres-version }} \
${{ inputs.pgvector-version }} \
${{ inputs.postgres-user }} \
${{ inputs.postgres-password }} \
${{ inputs.postgres-db }}
- name: Install and Configure PostgreSQL on macOS
if: runner.os == 'macOS'
shell: bash
run: |
chmod +x ${{ github.action_path }}/scripts/install-macos.sh
${{ github.action_path }}/scripts/install-macos.sh ${{ inputs.postgres-version }} ${{ inputs.pgvector-version }}
${{ github.action_path }}/scripts/install-macos.sh \
${{ inputs.postgres-version }} \
${{ inputs.pgvector-version }} \
${{ inputs.postgres-user }} \
${{ inputs.postgres-password }} \
${{ inputs.postgres-db }}
- name: Setup MSYS2
if: runner.os == 'Windows'
Expand Down Expand Up @@ -57,4 +79,9 @@ runs:
run: |
SCRIPT_PATH=$(echo "${{ github.action_path }}/scripts/install-windows.sh" | sed 's/\\/\//g')
chmod +x "$SCRIPT_PATH"
"$SCRIPT_PATH" ${{ inputs.postgres-version }} ${{ inputs.pgvector-version }}
"$SCRIPT_PATH" \
${{ inputs.postgres-version }} \
${{ inputs.pgvector-version }} \
${{ inputs.postgres-user }} \
${{ inputs.postgres-password }} \
${{ inputs.postgres-db }}
58 changes: 50 additions & 8 deletions scripts/install-macos.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,56 @@
#!/bin/bash
set -ex

PG_VERSION=$1
# Default versions if not provided
PG_VERSION=${1:-17}
PGVECTOR_VERSION=${2:-0.8.0}
PGUSER=${3:-postgres}
PGPASSWORD=${4:-postgres}
PGDATABASE=${5:-postgres}

brew install postgresql@${PG_VERSION}
brew link postgresql@${PG_VERSION}
echo "/usr/local/opt/postgresql@${PG_VERSION}/bin" >> $GITHUB_PATH
# Install PostgreSQL
brew install "postgresql@$PG_VERSION"
brew services start "postgresql@$PG_VERSION"

brew services start postgresql@${PG_VERSION}
sleep 3 # wait for PostgreSQL to start
# Add PostgreSQL binaries to PATH
export PATH="/opt/homebrew/opt/postgresql@$PG_VERSION/bin:$PATH"

createdb $USER || true
brew install pgvector
# Wait for PostgreSQL to start
sleep 3

# Set password and create database/user
createuser -s $PGUSER || true
psql -d postgres -c "ALTER USER $PGUSER WITH PASSWORD '$PGPASSWORD';"
if [ "$PGDATABASE" != "postgres" ]; then
createdb -O $PGUSER $PGDATABASE
fi

# Build and install pgvector
git clone --branch "v$PGVECTOR_VERSION" https://github.com/pgvector/pgvector.git
cd pgvector
make
make install
cd ..
rm -rf pgvector

# Create and configure pgvector extension
psql -d $PGDATABASE -c 'CREATE EXTENSION IF NOT EXISTS vector;'

# Export environment variables
export PGHOST=localhost
export PGUSER=$PGUSER
export PGPASSWORD=$PGPASSWORD
export PGDATABASE=$PGDATABASE

echo "PGHOST=$PGHOST" >> $GITHUB_ENV
echo "PGUSER=$PGUSER" >> $GITHUB_ENV
echo "PGPASSWORD=$PGPASSWORD" >> $GITHUB_ENV
echo "PGDATABASE=$PGDATABASE" >> $GITHUB_ENV

# Verify installation
echo "Checking PostgreSQL installation..."
psql -d $PGDATABASE -c "SELECT version();"
echo "Checking available extensions..."
psql -d $PGDATABASE -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';"
echo "Checking installed extensions..."
psql -d $PGDATABASE -c "SELECT * FROM pg_extension WHERE extname = 'vector';"
19 changes: 0 additions & 19 deletions scripts/install-pgvector-windows.bat

This file was deleted.

40 changes: 38 additions & 2 deletions scripts/install-ubuntu.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/bash
set -ex

PG_VERSION=$1
PGVECTOR_VERSION=$2
# Default versions if not provided
PG_VERSION=${1:-17}
PGVECTOR_VERSION=${2:-0.8.0}
PGUSER=${3:-postgres}
PGPASSWORD=${4:-postgres}
PGDATABASE=${5:-postgres}

echo "Installing PostgreSQL ${PG_VERSION}..."
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
Expand Down Expand Up @@ -63,3 +67,35 @@ echo "PostgreSQL ${PG_MAJOR_VERSION} extension directory:"
ls -la /usr/share/postgresql/${PG_MAJOR_VERSION}/extension/ || true
echo "PostgreSQL ${PG_MAJOR_VERSION} lib directory:"
ls -la /usr/lib/postgresql/${PG_MAJOR_VERSION}/lib/ || true

# Set password and create database
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$PGPASSWORD';"
if [ "$PGUSER" != "postgres" ]; then
sudo -u postgres createuser -s $PGUSER
sudo -u postgres psql -c "ALTER USER $PGUSER WITH PASSWORD '$PGPASSWORD';"
fi
if [ "$PGDATABASE" != "postgres" ]; then
sudo -u postgres createdb -O $PGUSER $PGDATABASE
fi

# Create and configure pgvector extension
sudo -u postgres psql -d $PGDATABASE -c "CREATE EXTENSION IF NOT EXISTS vector;"

# Export environment variables
export PGHOST=localhost
export PGUSER=$PGUSER
export PGPASSWORD=$PGPASSWORD
export PGDATABASE=$PGDATABASE

echo "PGHOST=$PGHOST" >> $GITHUB_ENV
echo "PGUSER=$PGUSER" >> $GITHUB_ENV
echo "PGPASSWORD=$PGPASSWORD" >> $GITHUB_ENV
echo "PGDATABASE=$PGDATABASE" >> $GITHUB_ENV

# Verify installation
echo "Checking PostgreSQL installation..."
psql -d $PGDATABASE -c "SELECT version();"
echo "Checking available extensions..."
psql -d $PGDATABASE -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';"
echo "Checking installed extensions..."
psql -d $PGDATABASE -c "SELECT * FROM pg_extension WHERE extname = 'vector';"
17 changes: 0 additions & 17 deletions scripts/install-windows.ps1

This file was deleted.

Loading

0 comments on commit 65988e5

Please sign in to comment.