Skip to content

Commit 4bc33c6

Browse files
committed
Why
1 parent b16ca24 commit 4bc33c6

1 file changed

Lines changed: 32 additions & 21 deletions

File tree

.github/workflows/swift.yml

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
name: build_test
2-
3-
on:
4-
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches: [ main ]
81

92
jobs:
103
build_test:
@@ -22,6 +15,28 @@ jobs:
2215

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

18+
# --- NEW SERVICE CONTAINER BLOCK ---
19+
# Service containers are only supported on Linux
20+
services:
21+
# Label used to access the service container
22+
postgres:
23+
if: matrix.os == 'ubuntu-latest'
24+
# Docker Hub image
25+
image: postgres
26+
# Use 'trust' auth to allow password-less connections,
27+
# matching the test's connection string.
28+
env:
29+
POSTGRES_HOST_AUTH_METHOD: trust
30+
# Set health checks to wait until postgres has started
31+
options: >-
32+
--health-cmd pg_isready
33+
--health-interval 10s
34+
--health-timeout 5s
35+
--health-retries 5
36+
ports:
37+
# Maps tcp port 5432 on service container to the host
38+
- 5432:5432
39+
2540
env:
2641
SWIFT_VERSION: 6.1
2742

@@ -40,23 +55,18 @@ jobs:
4055
mv swift-${SWIFT_VERSION}-RELEASE-ubuntu22.04 /opt/swift
4156
rm swift-${SWIFT_VERSION}-RELEASE-ubuntu22.04.tar.gz
4257
export PATH="/opt/swift/usr/bin:${PATH}"
58+
- uses: actions/checkout@v2
4359

44-
- name: Start PostgreSQL and create database (Linux)
60+
# --- MODIFIED STEP FOR LINUX ---
61+
# This step just creates the DB in the service container.
62+
- name: Create PostgreSQL database (Linux)
4563
if: runner.os == 'Linux'
4664
run: |
47-
sudo systemctl start postgresql
48-
# Find the active pg_hba.conf file
49-
HBA_CONF=$(sudo -u postgres psql -t -P format=unaligned -c 'SHOW hba_file;')
50-
# Add a line to allow all local users to connect without a password (trust auth)
51-
# This is safe in a CI environment
52-
echo "local all all trust" | sudo tee -a $HBA_CONF
53-
# Restart postgres to apply the new auth setting
54-
sudo systemctl restart postgresql
55-
# Wait for restart
56-
sleep 2
57-
# Create the 'fuzzilli' database. The 'runner' user can now connect.
58-
createdb fuzzilli
65+
# The service container is running on localhost:5432
66+
# We just need to create the database. Auth is 'trust'.
67+
createdb -h localhost -p 5432 fuzzilli
5968
69+
# --- UNCHANGED STEP FOR MACOS ---
6070
- name: Start PostgreSQL and create database (macOS)
6171
if: runner.os == 'macOS'
6272
run: |
@@ -68,7 +78,8 @@ jobs:
6878
# On macOS/brew, this usually works without password auth by default for the current user.
6979
createdb fuzzilli
7080
71-
- uses: actions/checkout@v2
81+
# --- END OF NEW STEPS ---
82+
7283
- name: Build
7384
run: swift build -c ${{ matrix.kind }} -v
7485
- name: Run tests with Node.js

0 commit comments

Comments
 (0)