This GitHub Action starts a MongoDB server or MongoDB replica set on the default port 27017.
This is useful when running tests against a MongoDB database.
A code example says more than a 1000 words. Here’s an exemplary GitHub Action using a MongoDB server in versions 4.0 and 4.2 to test a Node.js app:
name: Run testson: [push]jobs:
build:
runs-on: ubuntu-lateststrategy:
matrix:
node-version: [12.x, 14.x]mongodb-version: [4.0, 4.2, 4.4]steps:
- name: Git checkoutuses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}uses: actions/setup-node@v1with:
node-version: ${{ matrix.node-version }}
- name: Start MongoDBuses: supercharge/mongodb-github-action@1.3.0with:
mongodb-version: ${{ matrix.mongodb-version }}
- run: npm install
- run: npm testenv:
CI: trueYou can run your tests against a MongoDB replica set by adding the mongodb-replica-set: your-replicate-set-name input. The value for mongodb-replica-set defines the name of your replica set. Replace your-replicate-set-name with the replica set name you want to use in your tests.
The following example uses the replica set name test-rs:
name: Run testson: [push]jobs:
build:
runs-on: ubuntu-lateststrategy:
matrix:
node-version: [12.x, 14.x]mongodb-version: [4.0, 4.2, 4.4]steps:
- name: Git checkoutuses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}uses: actions/setup-node@v1with:
node-version: ${{ matrix.node-version }}
- name: Start MongoDBuses: supercharge/mongodb-github-action@1.3.0with:
mongodb-version: ${{ matrix.mongodb-version }}mongodb-replica-set: test-rs
- name: Install dependenciesrun: npm install
- name: Run testsrun: npm testenv:
CI: trueMIT © Supercharge
superchargejs.com · GitHub @supercharge · Twitter @superchargejs