Skip to content

Commit fec0a57

Browse files
authored
finish action (#1)
* finish action
1 parent 38fb3b4 commit fec0a57

6 files changed

Lines changed: 577 additions & 72 deletions

File tree

.github/workflows/ci.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
continue-on-error: true
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
postgres-version: [14, 15, 16, 17]
16+
os: [ubuntu-latest, ubuntu-24.04, windows-latest, windows-2019, macos-latest, macos-13]
17+
18+
runs-on: ${{ matrix.os }}
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Setup pgvector
24+
uses: ./
25+
with:
26+
postgres-version: ${{ matrix.postgres-version }}
27+
postgres-user: testuser
28+
postgres-password: testpass
29+
postgres-db: testdb
30+
31+
- name: Test Extension (Unix)
32+
if: runner.os != 'Windows'
33+
env:
34+
PGPASSWORD: testpass
35+
run: |
36+
psql -h localhost -U testuser -d testdb -c 'CREATE EXTENSION IF NOT EXISTS vector;'
37+
psql -h localhost -U testuser -d testdb -c 'CREATE TABLE IF NOT EXISTS items (id bigserial PRIMARY KEY, embedding vector(3));'
38+
psql -h localhost -U testuser -d testdb -c "INSERT INTO items (embedding) VALUES ('[1,2,3]');"
39+
psql -h localhost -U testuser -d testdb -c 'SELECT * FROM items;'
40+
41+
- name: Test Extension (Windows PowerShell)
42+
if: runner.os == 'Windows'
43+
shell: pwsh
44+
env:
45+
PGPASSWORD: testpass
46+
run: |
47+
psql -h localhost -U testuser -d testdb -c 'CREATE EXTENSION IF NOT EXISTS vector;'
48+
psql -h localhost -U testuser -d testdb -c 'CREATE TABLE IF NOT EXISTS items (id bigserial PRIMARY KEY, embedding vector(3));'
49+
psql -h localhost -U testuser -d testdb -c "INSERT INTO items (embedding) VALUES ('[1,2,3]');"
50+
psql -h localhost -U testuser -d testdb -c 'SELECT * FROM items;'
51+
52+
- name: Test Extension (Windows CMD)
53+
if: runner.os == 'Windows'
54+
shell: cmd
55+
env:
56+
PGPASSWORD: testpass
57+
run: psql -h localhost -U testuser -d testdb -c "SELECT * FROM items;"
58+
59+
- name: Test Extension (Windows MSYS2)
60+
if: runner.os == 'Windows'
61+
shell: msys2 {0}
62+
env:
63+
PGPASSWORD: testpass
64+
run: psql -h localhost -U testuser -d testdb -c 'SELECT * FROM items;'

README.md

Lines changed: 124 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,149 @@
1-
# Setup pgvector Action
1+
# Setup pgvector
22

3-
This action sets up [pgvector](https://github.com/pgvector/pgvector) in your GitHub Actions workflow. It uses the preinstalled PostgreSQL on GitHub runners and installs pgvector using platform-specific methods.
3+
GitHub Action and scripts to set up PostgreSQL with pgvector extension for vector similarity search.
44

5-
## Usage
5+
## Features
6+
7+
- 🚀 Quick setup of PostgreSQL with pgvector extension
8+
- 🔄 Supports both GitHub Actions and local installation
9+
- 🛠️ Customizable PostgreSQL and pgvector versions
10+
- 🔐 Secure password authentication
11+
- 🌐 Cross-platform support: Ubuntu, Windows (MSYS2), and macOS
12+
- 🏗️ Builds pgvector from source for maximum compatibility
13+
14+
## Supported Platforms
15+
16+
The following table shows the compatibility matrix for different PostgreSQL versions and platforms:
17+
18+
| Platform | Architecture | PostgreSQL 14 | PostgreSQL 15 | PostgreSQL 16 | PostgreSQL 17 |
19+
|----------|-------------|:-------------:|:-------------:|:-------------:|:-------------:|
20+
| Ubuntu Latest | x86_64 |||||
21+
| Ubuntu 24.04 | x86_64 |||||
22+
| Windows Latest | x86_64 |||||
23+
| Windows 2019 | x86_64 |||||
24+
| macOS Latest | arm64 |||||
25+
| macOS 13 | x86_64 |||||
26+
27+
## Quick Start
28+
29+
### GitHub Actions
630

731
```yaml
832
steps:
9-
- uses: actions/checkout@v4
10-
- uses: cpunion/setup-pgvector@v1
33+
- uses: cpunion/setup-pgvector@main
1134
with:
12-
postgres-version: '17' # optional, defaults to 17. Use 14 for ubuntu-22.04 and ubuntu-20.04
35+
postgres-version: '17'
36+
postgres-user: 'myuser'
37+
postgres-password: 'mypassword'
38+
postgres-db: 'mydb'
39+
40+
- name: Test pgvector
41+
env:
42+
PGPASSWORD: mypassword
43+
run: |
44+
psql -h localhost -U myuser -d mydb -c 'CREATE EXTENSION vector;'
1345
```
1446
15-
## Inputs
47+
### Local Installation
1648
17-
- `postgres-version`: PostgreSQL version to use (default: '17'). Note: Use '14' for ubuntu-22.04 and ubuntu-20.04.
49+
#### Method 1: Direct Installation
1850
19-
## Platform Support
51+
```bash
52+
# Ubuntu
53+
curl -fsSL https://raw.githubusercontent.com/cpunion/setup-pgvector/main/scripts/install-ubuntu.sh | bash
2054

21-
This action supports all major GitHub Actions platforms:
22-
- Ubuntu (using postgresql-xx-pgvector package)
23-
- macOS (using Homebrew)
24-
- Windows (building from source using Visual Studio Build Tools)
55+
# macOS
56+
curl -fsSL https://raw.githubusercontent.com/cpunion/setup-pgvector/main/scripts/install-macos.sh | bash
2557

26-
## CI Status
58+
# Windows (MSYS2)
59+
curl -fsSL https://raw.githubusercontent.com/cpunion/setup-pgvector/main/scripts/install-windows.sh | bash
60+
```
2761

28-
The action is tested on the following platforms:
29-
- Ubuntu: ubuntu-latest, ubuntu-24.04
30-
- Windows: windows-latest, windows-2019
31-
- macOS: macos-latest, macos-13
62+
With custom parameters:
63+
```bash
64+
# Format: curl ... | bash -s [PG_VERSION] [PGVECTOR_VERSION] [PGUSER] [PGPASSWORD] [PGDATABASE]
65+
curl -fsSL https://raw.githubusercontent.com/cpunion/setup-pgvector/main/scripts/install-ubuntu.sh | bash -s 17 0.8.0 myuser mypassword mydb
66+
```
3267

33-
## Example workflows
68+
#### Method 2: Clone and Run
3469

35-
### Ubuntu
36-
```yaml
37-
name: Test Ubuntu
38-
39-
on: [push]
40-
41-
jobs:
42-
test:
43-
runs-on: ubuntu-latest # or ubuntu-22.04, ubuntu-20.04
44-
steps:
45-
- uses: actions/checkout@v4
46-
- name: Setup pgvector
47-
uses: cpunion/setup-pgvector@v1
48-
with:
49-
postgres-version: '17' # Use '14' for ubuntu-22.04 and ubuntu-20.04
50-
- name: Create extension
51-
run: |
52-
sudo -u postgres psql -c 'CREATE EXTENSION vector;'
70+
```bash
71+
# Ubuntu
72+
./scripts/install-ubuntu.sh
73+
74+
# macOS
75+
./scripts/install-macos.sh
76+
77+
# Windows (MSYS2)
78+
./scripts/install-windows.sh
5379
```
5480

55-
### macOS
81+
## Requirements
82+
83+
- Ubuntu: No additional requirements
84+
- Windows: MSYS2 environment
85+
- macOS: Homebrew
86+
- Git (for building pgvector)
87+
88+
## Detailed Usage
89+
90+
### GitHub Actions
91+
5692
```yaml
57-
name: Test macOS
58-
59-
on: [push]
60-
61-
jobs:
62-
test:
63-
runs-on: macos-latest # or macos-13
64-
steps:
65-
- uses: actions/checkout@v4
66-
- name: Setup pgvector
67-
uses: cpunion/setup-pgvector@v1
68-
- name: Create extension
69-
run: |
70-
psql postgres -c 'CREATE EXTENSION vector;'
93+
steps:
94+
- uses: cpunion/setup-pgvector@main
95+
with:
96+
# PostgreSQL version to install (default: 17)
97+
postgres-version: '17'
98+
# pgvector version to install (default: 0.8.0)
99+
pgvector-version: '0.8.0'
100+
# PostgreSQL user to create (default: postgres)
101+
postgres-user: 'myuser'
102+
# Password for the PostgreSQL user (default: postgres)
103+
postgres-password: 'mypassword'
104+
# Database to create (default: postgres)
105+
postgres-db: 'mydb'
106+
107+
- name: Test pgvector
108+
env:
109+
PGPASSWORD: mypassword
110+
run: |
111+
psql -h localhost -U myuser -d mydb -c 'CREATE EXTENSION vector;'
112+
psql -h localhost -U myuser -d mydb -c 'CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));'
113+
psql -h localhost -U myuser -d mydb -c "INSERT INTO items (embedding) VALUES ('[1,2,3]');"
114+
psql -h localhost -U myuser -d mydb -c 'SELECT * FROM items;'
71115
```
72116
73-
### Windows
74-
```yaml
75-
name: Test Windows
76-
77-
on: [push]
78-
79-
jobs:
80-
test:
81-
strategy:
82-
matrix:
83-
os: [windows-latest, windows-2019]
84-
runs-on: ${{ matrix.os }}
85-
steps:
86-
- uses: actions/checkout@v4
87-
- name: Setup pgvector
88-
uses: cpunion/setup-pgvector@v1
89-
- name: Create extension
90-
shell: cmd
91-
run: |
92-
psql -U postgres -c "CREATE EXTENSION vector;"
117+
### Script Parameters
118+
119+
All installation scripts accept the following parameters:
120+
121+
1. `PG_VERSION` (default: 17) - PostgreSQL version to install
122+
2. `PGVECTOR_VERSION` (default: 0.8.0) - pgvector version to install
123+
3. `PGUSER` (default: postgres) - PostgreSQL user to create
124+
4. `PGPASSWORD` (default: postgres) - Password for the PostgreSQL user
125+
5. `PGDATABASE` (default: postgres) - Database to create
126+
127+
### Connection Details
128+
129+
After installation, you can connect to PostgreSQL using:
130+
131+
```bash
132+
# Using password from environment variable
133+
export PGPASSWORD=mypassword
134+
psql -h localhost -U myuser -d mydb
135+
136+
# Or using password prompt
137+
psql -h localhost -U myuser -d mydb
93138
```
94139

140+
## Notes
141+
142+
- The scripts will install PostgreSQL if not already installed
143+
- The scripts will create the specified user and database if they don't exist
144+
- The scripts will build and install pgvector from source
145+
- All connections are configured to use password authentication
146+
95147
## License
96148

97149
MIT

action.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: 'Setup pgvector'
2+
description: 'Setup pgvector in GitHub Actions'
3+
inputs:
4+
postgres-version:
5+
description: 'PostgreSQL version to use'
6+
required: false
7+
default: '17'
8+
pgvector-version:
9+
description: 'pgvector version to install'
10+
required: false
11+
default: '0.8.0'
12+
postgres-user:
13+
description: 'PostgreSQL user to create'
14+
required: false
15+
default: 'postgres'
16+
postgres-password:
17+
description: 'PostgreSQL user password'
18+
required: false
19+
default: 'postgres'
20+
postgres-db:
21+
description: 'PostgreSQL database to create'
22+
required: false
23+
default: 'postgres'
24+
runs:
25+
using: "composite"
26+
steps:
27+
- name: Install and Configure PostgreSQL on Ubuntu
28+
if: runner.os == 'Linux'
29+
shell: bash
30+
run: |
31+
chmod +x ${{ github.action_path }}/scripts/install-ubuntu.sh
32+
${{ github.action_path }}/scripts/install-ubuntu.sh \
33+
${{ inputs.postgres-version }} \
34+
${{ inputs.pgvector-version }} \
35+
${{ inputs.postgres-user }} \
36+
${{ inputs.postgres-password }} \
37+
${{ inputs.postgres-db }}
38+
39+
- name: Install and Configure PostgreSQL on macOS
40+
if: runner.os == 'macOS'
41+
shell: bash
42+
run: |
43+
chmod +x ${{ github.action_path }}/scripts/install-macos.sh
44+
${{ github.action_path }}/scripts/install-macos.sh \
45+
${{ inputs.postgres-version }} \
46+
${{ inputs.pgvector-version }} \
47+
${{ inputs.postgres-user }} \
48+
${{ inputs.postgres-password }} \
49+
${{ inputs.postgres-db }}
50+
51+
- name: Setup MSYS2
52+
if: runner.os == 'Windows'
53+
uses: msys2/setup-msys2@v2
54+
with:
55+
msystem: MINGW64
56+
update: true
57+
install: >-
58+
mingw-w64-x86_64-postgresql
59+
mingw-w64-x86_64-gcc
60+
mingw-w64-x86_64-make
61+
mingw-w64-x86_64-tools-git
62+
make
63+
diffutils
64+
git
65+
66+
- name: Add MSYS2 to PATH
67+
if: runner.os == 'Windows'
68+
shell: pwsh
69+
run: |
70+
echo "D:\a\_temp\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
71+
echo "D:\a\_temp\msys64\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
72+
73+
- name: Install and Configure PostgreSQL on Windows
74+
if: runner.os == 'Windows'
75+
shell: msys2 {0}
76+
env:
77+
MSYSTEM: MINGW64
78+
CHERE_INVOKING: 1
79+
run: |
80+
SCRIPT_PATH=$(echo "${{ github.action_path }}/scripts/install-windows.sh" | sed 's/\\/\//g')
81+
chmod +x "$SCRIPT_PATH"
82+
"$SCRIPT_PATH" \
83+
${{ inputs.postgres-version }} \
84+
${{ inputs.pgvector-version }} \
85+
${{ inputs.postgres-user }} \
86+
${{ inputs.postgres-password }} \
87+
${{ inputs.postgres-db }}

0 commit comments

Comments
 (0)