-
Notifications
You must be signed in to change notification settings - Fork 0
184 lines (153 loc) · 5.98 KB
/
ci-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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@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@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@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@11bd71901bbe5b1630ceea73d27597364c9af683
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@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@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@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 }}