diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ced9df2..c0abdd7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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;' diff --git a/README.md b/README.md index 31bdbec..5674d2e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/action.yml b/action.yml index f04320b..bf39919 100644 --- a/action.yml +++ b/action.yml @@ -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: @@ -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' @@ -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 }} diff --git a/scripts/install-macos.sh b/scripts/install-macos.sh index 0bf00f6..d68a37d 100644 --- a/scripts/install-macos.sh +++ b/scripts/install-macos.sh @@ -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';" diff --git a/scripts/install-pgvector-windows.bat b/scripts/install-pgvector-windows.bat deleted file mode 100644 index f862cf0..0000000 --- a/scripts/install-pgvector-windows.bat +++ /dev/null @@ -1,19 +0,0 @@ -@echo off -setlocal - -set PG_VERSION=%1 -set PGVECTOR_VERSION=%2 -set VS_VERSION=%3 - -if "%VS_VERSION%"=="2019" ( - call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" -) else ( - call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" -) - -cd %TEMP% -git clone --branch v%PGVECTOR_VERSION% https://github.com/pgvector/pgvector.git -cd pgvector -set PATH=C:\Program Files\PostgreSQL\%PG_VERSION%\bin;C:\Program Files\PostgreSQL\%PG_VERSION%\lib;%PATH% -nmake /NOLOGO /F Makefile.win -nmake /NOLOGO /F Makefile.win install diff --git a/scripts/install-ubuntu.sh b/scripts/install-ubuntu.sh index 984b4ef..08a23e5 100644 --- a/scripts/install-ubuntu.sh +++ b/scripts/install-ubuntu.sh @@ -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 @@ -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';" diff --git a/scripts/install-windows.ps1 b/scripts/install-windows.ps1 deleted file mode 100644 index 67ad2ca..0000000 --- a/scripts/install-windows.ps1 +++ /dev/null @@ -1,17 +0,0 @@ -param( - [string]$PostgresVersion, - [string]$PgVectorVersion -) - -# Install PostgreSQL -choco install postgresql$PostgresVersion --params '/Password:postgres' -$pgPath = "C:\Program Files\PostgreSQL\$PostgresVersion" -echo "$pgPath\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append -echo "$pgPath\lib" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append -refreshenv - -# Start PostgreSQL service -Start-Service postgresql-x64-$PostgresVersion -Start-Sleep -s 3 # Wait for PostgreSQL to start -$env:PGPASSWORD = 'postgres' -psql -U postgres -c "SELECT version();" diff --git a/scripts/install-windows.sh b/scripts/install-windows.sh index b8b27a0..c44a5bf 100644 --- a/scripts/install-windows.sh +++ b/scripts/install-windows.sh @@ -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} # Add PostgreSQL binaries to PATH export PATH="/mingw64/bin:$PATH" @@ -11,21 +15,22 @@ export PKG_CONFIG_PATH="/mingw64/lib/pkgconfig:$PKG_CONFIG_PATH" # Initialize PostgreSQL database export PGDATA=/c/data/postgres export PGHOST=localhost -export PGUSER=postgres +export PGUSER=$PGUSER +export PGPASSWORD=$PGPASSWORD # Ensure data directory exists and is empty rm -rf $PGDATA mkdir -p $PGDATA echo "Initializing PostgreSQL database..." -initdb -U postgres --encoding=UTF8 --locale=C --auth=trust +initdb -U $PGUSER --encoding=UTF8 --locale=C --auth=trust # Configure PostgreSQL cat > $PGDATA/pg_hba.conf << EOL # TYPE DATABASE USER ADDRESS METHOD -local all all trust -host all all 127.0.0.1/32 trust -host all all ::1/128 trust +local all all md5 +host all all 127.0.0.1/32 md5 +host all all ::1/128 md5 EOL # Configure postgresql.conf @@ -73,19 +78,11 @@ sleep 3 echo "PostgreSQL log content:" cat $PGDATA/log/postgresql-*.log || true -# Verify PostgreSQL is running -echo "Verifying PostgreSQL connection..." -for i in {1..5}; do - if psql -h localhost -U postgres -c "SELECT version();" 2>/dev/null; then - break - fi - echo "Waiting for PostgreSQL to start (attempt $i)..." - sleep 2 -done - -# Get PostgreSQL version -PG_ACTUAL_VERSION=$(psql -h localhost -U postgres -t -c "SHOW server_version;" | xargs) -echo "PostgreSQL actual version: ${PG_ACTUAL_VERSION}" +# Set password and create database +psql -h localhost -U $PGUSER -d postgres -c "ALTER USER $PGUSER WITH PASSWORD '$PGPASSWORD';" +if [ "$PGDATABASE" != "postgres" ]; then + createdb -h localhost -U $PGUSER $PGDATABASE +fi # Build and install pgvector echo "Building pgvector..." @@ -99,17 +96,19 @@ rm -rf pgvector # Create and configure pgvector extension echo "Creating pgvector extension..." -psql -h localhost -U postgres -d postgres -c "CREATE EXTENSION IF NOT EXISTS vector;" +psql -h localhost -U $PGUSER -d $PGDATABASE -c "CREATE EXTENSION IF NOT EXISTS vector;" # Export environment variables for PowerShell echo "PGDATA=$PGDATA" >> $GITHUB_ENV 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 -h localhost -U postgres -d postgres -c "SELECT version();" +psql -h localhost -U $PGUSER -d $PGDATABASE -c "SELECT version();" echo "Checking available extensions..." -psql -h localhost -U postgres -d postgres -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';" +psql -h localhost -U $PGUSER -d $PGDATABASE -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';" echo "Checking installed extensions..." -psql -h localhost -U postgres -d postgres -c "SELECT * FROM pg_extension WHERE extname = 'vector';" +psql -h localhost -U $PGUSER -d $PGDATABASE -c "SELECT * FROM pg_extension WHERE extname = 'vector';"