Skip to content

Commit 0259e64

Browse files
Merge pull request #84 from square/qian/PLAT-20542
Enable automated tests for PRs
2 parents 3c65de0 + 0edf653 commit 0259e64

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
branches: [ main, master ]
5+
6+
jobs:
7+
test:
8+
name: Run Tests
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Check out code
13+
uses: actions/checkout@v4
14+
15+
- name: Install Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version: '1.23'
19+
20+
- name: Install MongoDB Shell
21+
run: |
22+
sudo apt-get install gnupg
23+
wget -qO - https://www.mongodb.org/static/pgp/server-8.0.asc | sudo tee /etc/apt/trusted.gpg.d/server-8.0.asc
24+
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
25+
sudo apt-get update
26+
sudo apt-get install -y mongodb-mongosh
27+
mongosh --version
28+
29+
- name: Start MongoDB
30+
run: docker run -d -p 27017:27017 --name mongo mongo:6.0 --replSet rs0 --bind_ip_all
31+
32+
- name: Initialize MongoDB Replica Set
33+
run: |
34+
sleep 10
35+
docker run --rm mongo:6.0 mongosh --host 172.17.0.1 --eval 'rs.initiate({_id: "rs0", members: [{_id: 0, host: "172.17.0.1:27017"}]})'
36+
37+
- name: Verify replica set health
38+
run: ./scripts/verify-mongo-health.sh
39+
40+
- name: Download Go dependencies
41+
run: go mod download
42+
43+
- name: Run tests
44+
run: go test -v ./...

scripts/verify-mongo-health.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
echo "Waiting for MongoDB to be ready..."
4+
until mongosh --eval "db.runCommand('ping').ok" > /dev/null 2>&1; do
5+
sleep 2
6+
done
7+
8+
echo "Waiting for replica set to be ready..."
9+
until mongosh --host "rs0/localhost:27017" --eval "rs.isMaster().ismaster" | grep -q "true"; do
10+
sleep 2
11+
done
12+
13+
echo "MongoDB replica set is ready!"

0 commit comments

Comments
 (0)