-
Notifications
You must be signed in to change notification settings - Fork 3
162 lines (139 loc) · 5.25 KB
/
frontend-ci.yaml
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
name: Frontend CI
on:
push:
paths-ignore:
- '**/*.md'
- '**/**.png'
- '**/**.gif'
- .gitignore
pull_request:
paths-ignore:
- '**/*.md'
- '**/**.png'
- '**/**.gif'
- .gitignore
workflow_dispatch:
env:
CONTAINER_REGISTRY: rescabnamro
IMAGE_NAME: resc-frontend
permissions: read-all
jobs:
nodejs-basic-validation:
name: Build Nodejs
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [22.2.0]
outputs:
frontend_version: ${{ steps.getversion.outputs.frontend_version }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: |
npm install
- name: Npm Lint
run: |
npm run lint
- name: Run Type checking
run: |
npm run tsc
- name: Run Unit Tests with Vitest and coverage
run: |
npm run ut
- name: Run Software Composition Analysis using AuditJS
run: |
npx auditjs@latest ossi -q || true
## Removing the dir paths and making them relative paths.
- name: Fix coverage report
run: |
sed -i "s+/home/runner/work/resc-frontend/++g" tests/reports/coverage/lcov.info
cat tests/reports/coverage/lcov.info
# This step will only execute if PR is created internally.
- name: SonarCloud Scan
if: ${{ (github.event.pull_request.head.repo.full_name == 'abnamro/repository-scanner') || (github.ref == 'refs/heads/main') }}
uses: SonarSource/sonarcloud-github-action@master
with:
args: >
-Dsonar.organization=abnamro-resc
-Dsonar.projectKey=abnamro-resc_resc-frontend
-Dsonar.sourceEncoding=UTF-8
-Dsonar.projectName=resc-frontend
-Dsonar.groupid=resc
-Dsonar.sources=src/
-Dsonar.inclusions=**/*
-Dsonar.exclusions=**/__mocks__/*
-Dsonar.tests=tests/
-Dsonar.cpd.exclusions=**/*.example.js,**/*.spec.js,**/*.?spec.js
-Dsonar.coverage.exclusions=**/*.html,**/*.json,**/*.spec.js,**/*.?spec.js,**/main.*,**/i18n.js,**/router/index.js,**/configuration/*.js
-Dsonar.javascript.jstest.reportsPath=tests/reports/coverage
-Dsonar.javascript.lcov.reportPaths=tests/reports/coverage/lcov.info
-Dsonar.pdf.skip=true
-Dsonar.branch.target=*
-Dsonar.branch.name=*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.__SONAR_TOKEN_BACKEND__ }}
- id: getversion
name: Get package version
run: |
frontend_version=$(npm pkg get version | sed 's/"//g')
echo "frontend_version=$frontend_version" >> $GITHUB_OUTPUT
dockerize:
name: Build and Push Docker image
needs: nodejs-basic-validation
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Docker Lint
uses: hadolint/hadolint-action@v2.0.0
with:
dockerfile: ./Dockerfile
failure-threshold: error
- name: Build an image from Dockerfile
run: |
docker build -t ${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{needs.nodejs-basic-validation.outputs.frontend_version}} .
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{needs.nodejs-basic-validation.outputs.frontend_version}}
format: 'table'
exit-code: '0'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
- name: Get Branch Name
run: |
if [[ ${GITHUB_EVENT_NAME} == 'pull_request' ]]; then
echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF})" >> "$GITHUB_ENV"
elif [[ ${GITHUB_EVENT_NAME} == 'push' ]]; then
echo "BRANCH_NAME=$(echo ${GITHUB_REF_NAME})" >> "$GITHUB_ENV"
else
echo "Event is neither pull_request nor push"
fi
- name: Determine if image needs to be published
run: |
if [[ ${{ env.BRANCH_NAME }} == 'main' ]]; then
echo "PUBLISH_IMAGE=true" >> "$GITHUB_ENV"
echo "Going to publish image to registry"
else
echo "PUBLISH_IMAGE=false" >> "$GITHUB_ENV"
echo "Skipping publishing of image to registry"
fi
- name: Log in to Container Registry
if: ${{ env.PUBLISH_IMAGE == 'true' }}
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.__DOCKER_HUB_USER__ }}
password: ${{ secrets.__DOCKER_HUB_PASS__ }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ./
push: ${{ env.PUBLISH_IMAGE }}
tags: ${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest, ${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{needs.nodejs-basic-validation.outputs.frontend_version}}