Skip to content

Commit 0edf653

Browse files
committed
update mongodb in github actions
1 parent 4b182dc commit 0edf653

File tree

4 files changed

+35
-32
lines changed

4 files changed

+35
-32
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
name: CI
22
on:
3-
push:
4-
branches: [ main, master ]
53
pull_request:
64
branches: [ main, master ]
75

@@ -11,21 +9,35 @@ jobs:
119
runs-on: ubuntu-latest
1210

1311
steps:
14-
- name: Start MongoDB
15-
uses: supercharge/mongodb-github-action@1.12.0
16-
with:
17-
mongodb-version: '6.0'
18-
mongodb-replica-set: rs0
19-
2012
- name: Check out code
2113
uses: actions/checkout@v4
2214

2315
- name: Install Go
2416
uses: actions/setup-go@v5
2517
with:
2618
go-version: '1.23'
27-
28-
- name: Download dependencies
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
2941
run: go mod download
3042

3143
- name: Run tests

LICENSE-MIT

Lines changed: 0 additions & 21 deletions
This file was deleted.

NOTICE

Lines changed: 0 additions & 1 deletion
This file was deleted.

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)