Skip to content

Commit 000827f

Browse files
Move managed server startup to dedicated action
1 parent 7d5e851 commit 000827f

File tree

5 files changed

+57
-40
lines changed

5 files changed

+57
-40
lines changed

.github/actions/managed-version/action.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ inputs:
77
required: true
88
default: 'latest'
99
managed-versions:
10-
description: 'manged version json'
10+
description: 'managed version json'
1111
required: true
1212
key:
1313
description: 'the key to lookup'
1414
required: true
15-
default: '.database.mongodb'
1615

1716
outputs:
1817
managed-version:
@@ -28,7 +27,7 @@ runs:
2827
run: |
2928
MANAGED_VERSION=$(echo ${{inputs.managed-versions}} | jq -r '${{inputs.key}}["${{inputs.version}}"]')
3029
if [[ -z "$MANAGED_VERSION" ]] || [[ "$MANAGED_VERSION" == "null" ]]; then
31-
MANAGED_VERSION=${{inputs.version}}
30+
MANAGED_VERSION='${{inputs.version}}'
3231
fi
3332
echo "managed-version=$MANAGED_VERSION" >> $GITHUB_OUTPUT
3433

.github/actions/mongodb/action.yml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
name: MongoDB
2-
description: 'Set up a MongoDB server'
1+
name: Initialize MongoDB
2+
description: 'Initialize a MongoDB server looking up a configuration managed version pointing to a dedicated revision'
33

44
inputs:
5-
mongo-version:
6-
description: 'MongoDB Server version'
5+
managed-versions:
6+
description: 'managed version json to retrieve the target server version from'
77
required: true
8+
mongodb-server-version:
9+
description: 'The desired MongoDB Server version'
10+
required: false
11+
default: 'latest'
812
replica-set:
9-
description: 'Replica Set Name'
13+
description: 'Replica Set Name (if not provided Mongo will be started as a standalone instance)'
1014
required: false
11-
default: '_standalone_'
15+
1216
runs:
1317
using: composite
1418
steps:
15-
- name: Start MongoDB Standalone
16-
shell: bash
17-
if: ${{ inputs.replica-set == '_standalone_' }}
18-
run: docker run --rm -d -p 27017:27017 --name mongo mongo:${{ inputs.mongo-version }} --bind_ip_all
19-
- name: Start MongoDB Replica Set
20-
shell: bash
21-
if: ${{ inputs.replica-set != '_standalone_' }}
22-
run: |
23-
echo 'replica'
24-
docker run --rm -d -p 27017:27017 --name mongo mongo:${{ inputs.mongo-version }} --replSet ${{ inputs.replica-set }} --bind_ip_all
25-
sleep 5 # Give mongo a chance to start up
26-
docker run --rm mongo:${{ inputs.mongo-version }} mongosh --host 172.17.0.1 --eval 'rs.initiate({_id: "${{ inputs.replica-set }}", members: [{_id: 0, host: "172.17.0.1:27017"}]})'
19+
- name: Mongo Version
20+
id: determine-mongo-version
21+
uses: ./.github/actions/managed-version
22+
with:
23+
managed-versions: ${{ inputs.managed-versions }}
24+
key: '.database.mongodb'
25+
version: '${{ inputs.mongodb-server-version }}'
26+
- name: Initialize MongoDB
27+
uses: ./.github/actions/start-mongodb-server
28+
with:
29+
mongo-version: '${{ steps.determine-mongo-version.outputs.managed-version }}'
30+
replica-set: ${{ inputs.replica-set }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: MongoDB
2+
description: 'Start MongoDB server'
3+
4+
inputs:
5+
mongo-version:
6+
description: 'MongoDB Server version'
7+
required: true
8+
replica-set:
9+
description: 'Replica Set Name'
10+
required: false
11+
default: '_standalone_'
12+
runs:
13+
using: composite
14+
steps:
15+
- name: Start MongoDB Standalone
16+
shell: bash
17+
if: ${{ inputs.replica-set == '_standalone_' }}
18+
run: docker run --rm -d -p 27017:27017 --name mongo mongo:'${{ inputs.mongo-version }}' --bind_ip_all
19+
- name: Start MongoDB Replica Set
20+
shell: bash
21+
if: ${{ inputs.replica-set != '_standalone_' }}
22+
run: |
23+
echo 'replica'
24+
docker run --rm -d -p 27017:27017 --name mongo mongo:'${{ inputs.mongo-version }}' --replSet ${{ inputs.replica-set }} --bind_ip_all
25+
sleep 5 # Give mongo a chance to start up
26+
docker run --rm mongo:'${{ inputs.mongo-version }}' mongosh --host 172.17.0.1 --eval 'rs.initiate({_id: "${{ inputs.replica-set }}", members: [{_id: 0, host: "172.17.0.1:27017"}]})'

.github/workflows/ci.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
java-version: [ base, main ]
16-
mongo-version: [8.0]
16+
mongo-version: ['latest', '8.2', '8.0', '7.0']
1717
name: Build project
1818
runs-on: ubuntu-latest
1919
steps:
@@ -23,17 +23,11 @@ jobs:
2323
with:
2424
java-version: ${{ matrix.java-version }}
2525
develocity-access-key: '${{ secrets.DEVELOCITY_ACCESS_KEY }}'
26-
- name: Mongo Version
27-
id: determine-mongo-version
28-
uses: ./.github/actions/managed-version
29-
with:
30-
managed-versions: ${CONFIG_JSON}
31-
key: '.database.mongodb'
32-
version: '${{ matrix.mongo-version }}'
33-
- name: Initialize MongoDB
26+
- name: Initialize MongoDB Server
3427
uses: ./.github/actions/mongodb/
3528
with:
36-
mongo-version: ${{ steps.determine-mongo-version.outputs.managed-version }}
29+
managed-versions: ${CONFIG_JSON}
30+
mongodb-server-version: '${{ matrix.mongo-version }}'
3731
replica-set: 'rs0'
3832
- name: Build
3933
uses: spring-projects/spring-data-release/actions/maven-build@main

.github/workflows/snapshots.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,11 @@ jobs:
1818
uses: spring-projects/spring-data-release/actions/setup-maven@main
1919
with:
2020
develocity-access-key: '${{ secrets.DEVELOCITY_ACCESS_KEY }}'
21-
- name: Mongo Version
22-
id: determine-mongo-version
23-
uses: ./.github/actions/managed-version
24-
with:
25-
managed-versions: ${CONFIG_JSON}
26-
key: '.database.mongodb'
27-
version: 'latest'
28-
- name: Initialize MongoDB
21+
- name: Initialize MongoDB Server
2922
uses: ./.github/actions/mongodb/
3023
with:
31-
mongo-version: ${{ steps.determine-mongo-version.outputs.managed-version }}
24+
managed-versions: ${CONFIG_JSON}
25+
mongodb-server-version: 'latest'
3226
replica-set: 'rs0'
3327
- name: Deploy to Artifactory
3428
uses: spring-projects/spring-data-release/actions/maven-artifactory-deploy@main

0 commit comments

Comments
 (0)