Skip to content

Update react monorepo (develop) #3914

Update react monorepo (develop)

Update react monorepo (develop) #3914

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@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Setup Node.js
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # 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@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # 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@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Setup Node.js
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # 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@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # 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@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
with:
repository: ral-facilities/inventory-management-system-api
ref: develop
- name: Set up Python
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.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
# 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__HOST_AND_OPTIONS="localhost:27017/?authMechanism=SCRAM-SHA-256&authSource=admin" \
--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@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Setup Node.js
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # 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 ims_api_mongodb_container
- name: Output docker logs (api)
if: failure()
run: docker logs inventory_management_system_api_container
- name: Upload Cypress screenshots
if: failure()
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # 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@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- name: Login to Harbor
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.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@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: ${{ secrets.HARBOR_URL }}/ims
- name: Build and push Docker image to Harbor
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
with:
context: .
file: ./Dockerfile.prod
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}