Add and view a spares definition #1161 #4284
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # 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@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # v5 | |
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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # 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@6f51ac03b9356f520e9adb1b1b7802705f340c2b # 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@cbb722410c2e876e24abbe8de2cc27693e501dcb | |
with: | |
repository: ral-facilities/inventory-management-system-api | |
ref: develop | |
- name: Set up Python | |
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # 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@6f51ac03b9356f520e9adb1b1b7802705f340c2b # 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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- 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@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1 | |
with: | |
images: ${{ secrets.HARBOR_URL }}/ims | |
- name: Build and push Docker image to Harbor | |
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0 | |
with: | |
context: . | |
file: ./Dockerfile.prod | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |