neofinancial / mongo-memory-server-action

GitHub Action that creates a MongoDB memory-server for DB-dependent CI steps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mongo-memory-server-action

Build status coverage Test status Publish status

Provides a CI-time MongoDB memory database using mongodb-memory-server, sets your specified environment variable to the new server's connection string, and executes your specified script. Created to support CI-time testing of:

  • seed and migration scripts,
  • complex queries,
  • schema implementation,
  • or any MongoDB-dependent process where a mock database might not be suitable.

Usage

In your .github/workflows folder, add a new job step to the appropriate workflow:

- uses: neofinancial/mongo-memory-server-action@v1.0.2
  with:
    db-connection-env-var: MONGODB_CONNECTION_STRING
    run-command: yarn use:database
    binary-version: 4.4.6
    instance-dbName: validation
    instance-port: 27017
    instance-storageEngine: wiredTiger
    mongoms-debug: 1
Input Description
db-connection-env-var required: the ENV variable that the action will set to provide the DB connection string to your script
run-command required: the shell command the action will execute once the database is available
binary-version specify a version of the database engine - defaults to 4.0.25 as per the mongodb-memory-server library app defaults
instance-dbName a database name (defaults to a random string)
instance-port the port the DB will listen on (defaults to "27017")
instance-storageEngine the storage engine (defaults to "ephemeralForTest"; alternatively, use "wiredTiger")
mongoms-debug if provided and given any value, sets the ENV variable used by mongodb-memory-server for Debug mode

Implementation

In the example, the run-command parameter value ("yarn use:database") is executed synchronously by the action using a child process. That script is therefore responsible for reading the ENV variable MONGODB_CONNECTION_STRING and configuring MongoDB client(s) accordingly.

The memory-server is stopped (and destroyed) subsequent to the completion of this command, so the command's process should encompass all interactions with it.

Contributing

Testing

This repository's CI workflow has a 'validate' job @ src/validate.ts (technically, build/validate.js) for internal, CI-time testing of the action's functionality; this simply opens and closes a connection to the memory-server to ensure the validity of the provided ENV variable. There are also a small number of unit tests to ensure the memory-server's configuration values are passed to the memory-server appropriately.

  • please try to cover the new capability when making small changes
  • as necessary, add validation for variables passed directly to the initialization of the memory-server

Versioning

Semantic versioning should be applied via the CI workflow by updating the version in package.json (and the reference to it in this README.md). The publish workflow will be triggered on the merge into master, generating a tag name from the package version.

About

GitHub Action that creates a MongoDB memory-server for DB-dependent CI steps.

License:MIT License


Languages

Language:TypeScript 58.6%Language:JavaScript 41.4%