Skip to content

Use replica set for MongoDB in e2e api tests on CI #499 #2073

Use replica set for MongoDB in e2e api tests on CI #499

Use replica set for MongoDB in e2e api tests on CI #499 #2073

Workflow file for this run

name: CI Build
on:
pull_request:
push:
branches:
- main
- develop
jobs:
lint-and-unit-test:
name: Lint & Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version: 20
cache: 'yarn'
- name: Install dependencies
run: |
sudo apt-get install libgconf-2-4
yarn --immutable
- name: Run linting
run: yarn lint
- name: Run unit tests
run: yarn test
- name: Upload coverage reports to Codecov
if: success()
uses: codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed # v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
e2e-tests:
name: End-to-End (with mock data) Tests
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version: 20
cache: 'yarn'
- name: Install dependencies
run: |
sudo apt-get install libgconf-2-4
yarn --immutable
- name: Run e2e tests
run: yarn e2e
- name: Upload Cypress screenshots
if: failure()
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
with:
name: Inventory management system Screenshots
path: cypress/screenshots
e2e-tests-api:
name: End-to-End (with api) Tests
runs-on: ubuntu-latest
steps:
- name: Clone api repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
repository: ral-facilities/inventory-management-system-api
ref: develop
- name: Set up Python
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: '3.12'
# This is required as need to setup api in a different directory as checkout will attempt delete
# all existing files which in this case will include a data directory created by docker causing
# a permission error (checkout action also can't specify a different directory to clone into)
- name: Move api repo
run: |
cd ..
mkdir inventory-management-system-api
mv -v inventory-management-system/* inventory-management-system-api/
cd inventory-management-system-api/
- name: Setup MongoDB
working-directory: ../inventory-management-system-api
run: |
python ./scripts/dev_cli.py --ci db-init --replicaSetMemberHost localhost
python ./scripts/dev_cli.py --ci db-import
# Use docker run here to test the actual built image
# Use same network as the MongoDB instance (which is generated by docker compose based on the folder
# name)
- name: Start inventory-management-system-api
run: |
docker run -d --network=host \
--name inventory_management_system_api_container \
--env AUTHENTICATION__ENABLED=false \
--env API__TITLE="Inventory Management System API" \
--env API__DESCRIPTION="This is the API for the Inventory Management System" \
--env DATABASE__PROTOCOL="mongodb" \
--env DATABASE__USERNAME="root" \
--env DATABASE__PASSWORD="example" \
--env DATABASE__HOSTNAME="localhost" \
--env DATABASE__PORT=27017 \
--env DATABASE__NAME="ims" \
--env API__ALLOWED_CORS_HEADERS='["*"]' \
--env API__ALLOWED_CORS_ORIGINS='["*"]' \
--env API__ALLOWED_CORS_METHODS='["*"]' \
harbor.stfc.ac.uk/inventory-management-system/ims-api:develop
- name: Checkout repo
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version: 20
cache: 'yarn'
- name: Install dependencies
run: |
sudo apt-get install libgconf-2-4
yarn --immutable
- name: Run e2e tests
run: yarn e2e:api
- name: Output docker logs (mongodb)
if: failure()
run: docker logs mongodb_container
- name: Output docker logs (api)
if: failure()
run: docker logs inventory_management_system_api
- name: Upload Cypress screenshots
if: failure()
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
with:
name: Inventory management system (with api) Screenshots
path: cypress/screenshots
docker:
# This job triggers only if all the other jobs succeed. It builds the Docker image and if successful,
# it pushes it to Harbor.
needs: [lint-and-unit-test, e2e-tests, e2e-tests-api]
name: Docker
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Login to Harbor
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
with:
registry: ${{ secrets.HARBOR_URL }}
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c # v5.5.0
with:
images: ${{ secrets.HARBOR_URL }}/ims
- name: Build and push Docker image to Harbor
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
with:
context: .
file: ./Dockerfile.prod
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}