Skip to content

Commit 7cca8f4

Browse files
authored
chore: run tests on macos in ci (#479)
1 parent 1d7c885 commit 7cca8f4

File tree

3 files changed

+93
-64
lines changed

3 files changed

+93
-64
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Setup Postgres
2+
description: Setup Postgres across operating systems
3+
inputs:
4+
postgres-version:
5+
description: Postgres Version
6+
default: 15
7+
8+
runs:
9+
using: composite
10+
steps:
11+
# For Windows and macOS, use the action since
12+
# PostgreSQL Docker image doesn't support Windows containers and
13+
# macOS runners do not support Docker
14+
- name: Setup postgres (Windows)
15+
if: runner.os == 'Windows' || runner.os == 'macOS'
16+
id: postgres
17+
uses: ikalnytskyi/action-setup-postgres@v7
18+
with:
19+
postgres-version: ${{ inputs.postgres-version }}
20+
username: postgres
21+
password: postgres
22+
database: postgres
23+
port: 5432
24+
25+
# Install the pglpgsql_check extension on macOS (Part 1)
26+
- name: Install and compile plpgsql_check
27+
if: runner.os == 'macOS'
28+
shell: bash
29+
run: |
30+
# First, ensure we're using the same PostgreSQL that the action installed
31+
export PATH="$(pg_config --bindir):$PATH"
32+
33+
# Verify we're targeting the right PostgreSQL installation
34+
echo "PostgreSQL version: $(pg_config --version)"
35+
echo "Extension directory: $(pg_config --sharedir)/extension"
36+
echo "Library directory: $(pg_config --pkglibdir)"
37+
38+
# Clone and build plpgsql_check
39+
git clone https://github.com/okbob/plpgsql_check.git
40+
cd plpgsql_check
41+
42+
# Clean and compile
43+
make USE_PGXS=1 clean
44+
make USE_PGXS=1 all
45+
46+
# Install (may need sudo depending on permissions)
47+
sudo make USE_PGXS=1 install
48+
49+
# Verify installation
50+
echo "Extension control files:"
51+
ls -la "$(pg_config --sharedir)/extension/" | grep plpgsql || echo "No plpgsql_check found"
52+
53+
echo "Extension library files:"
54+
ls -la "$(pg_config --pkglibdir)/" | grep plpgsql || echo "No plpgsql_check library found"
55+
56+
# Install the pglpgsql_check extension on macOS (Part 2)
57+
- name: Create extension in database
58+
if: runner.os == 'macOS'
59+
shell: bash
60+
env:
61+
PGSERVICE: ${{ steps.postgres.outputs.service-name }}
62+
run: |
63+
psql -c "CREATE EXTENSION plpgsql_check;"
64+
65+
# Verify installation
66+
psql -c "SELECT extname, extversion FROM pg_extension WHERE extname = 'plpgsql_check';"
67+
68+
# For Linux, use custom Docker image with plpgsql_check
69+
- name: Build and start PostgreSQL with plpgsql_check
70+
if: runner.os == 'Linux'
71+
shell: bash
72+
run: |
73+
docker build -t postgres-plpgsql-check:latest .
74+
docker run -d --name postgres \
75+
-e POSTGRES_USER=postgres \
76+
-e POSTGRES_PASSWORD=postgres \
77+
-e POSTGRES_DB=postgres \
78+
-p 5432:5432 \
79+
postgres-plpgsql-check:latest
80+
# Wait for postgres to be ready
81+
for _ in {1..30}; do
82+
if docker exec postgres pg_isready -U postgres; then
83+
break
84+
fi
85+
sleep 1
86+
done
87+

.github/workflows/pull_request.yml

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ jobs:
149149
# use the same images we use for compiling
150150
- os: windows-2022
151151
- os: ubuntu-22.04
152+
- os: macos-14
152153
steps:
153154
- name: Checkout PR branch
154155
uses: actions/checkout@v4
@@ -163,37 +164,9 @@ jobs:
163164
env:
164165
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
165166

166-
# For Linux, use custom Docker image with plpgsql_check
167-
- name: Build and start PostgreSQL with plpgsql_check
168-
if: runner.os == 'Linux'
169-
run: |
170-
docker build -t postgres-plpgsql-check:latest .
171-
docker run -d --name postgres \
172-
-e POSTGRES_USER=postgres \
173-
-e POSTGRES_PASSWORD=postgres \
174-
-e POSTGRES_DB=postgres \
175-
-p 5432:5432 \
176-
postgres-plpgsql-check:latest
177-
# Wait for postgres to be ready
178-
for _ in {1..30}; do
179-
if docker exec postgres pg_isready -U postgres; then
180-
break
181-
fi
182-
sleep 1
183-
done
184-
# For Windows, use the action since PostgreSQL Docker image doesn't support Windows containers
185-
- name: Setup postgres (Windows)
186-
if: runner.os == 'Windows'
187-
id: postgres
188-
uses: ikalnytskyi/action-setup-postgres@v7
189-
- name: Print Roles
190-
run: |
191-
if [[ "$RUNNER_OS" == "Linux" ]]; then
192-
docker exec postgres psql -U postgres -c "select rolname from pg_roles;"
193-
else
194-
psql ${{ steps.postgres.outputs.connection-uri }} -c "select rolname from pg_roles;"
195-
fi
196-
shell: bash
167+
- name: Setup Postgres
168+
uses: ./.github/actions/setup-postgres
169+
197170
- name: Run tests
198171
run: cargo test --workspace
199172

.github/workflows/release.yml

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,39 +67,8 @@ jobs:
6767
sudo apt-get update
6868
sudo apt-get install -y gcc-aarch64-linux-gnu
6969
70-
# The Docker runtime is not available by default on macOS runners
71-
# https://github.com/actions/runner-images/issues/2150
72-
# https://blog.netnerds.net/2022/11/docker-macos-github-actions/
73-
- name: Install Docker
74-
if: runner.os == 'macOS'
75-
run: |
76-
brew install docker
77-
colima start
78-
79-
# For Linux, use custom Docker image with plpgsql_check
80-
- name: Build and start PostgreSQL with plpgsql_check
81-
if: runner.os == 'macOS' || runner.os == 'Linux'
82-
run: |
83-
docker build -t postgres-plpgsql-check:latest .
84-
docker run -d --name postgres \
85-
-e POSTGRES_USER=postgres \
86-
-e POSTGRES_PASSWORD=postgres \
87-
-e POSTGRES_DB=postgres \
88-
-p 5432:5432 \
89-
postgres-plpgsql-check:latest
90-
# Wait for postgres to be ready
91-
for _ in {1..30}; do
92-
if docker exec postgres pg_isready -U postgres; then
93-
break
94-
fi
95-
sleep 1
96-
done
97-
98-
# For Windows, use the action since PostgreSQL Docker image doesn't support Windows containers
99-
- name: Setup postgres (Windows)
100-
if: runner.os == 'Windows'
101-
id: postgres
102-
uses: ikalnytskyi/action-setup-postgres@v7
70+
- name: Setup Postgres
71+
uses: ./.github/actions/setup-postgres
10372

10473
- name: 🧪 Run Tests
10574
run: cargo test --release

0 commit comments

Comments
 (0)