-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
163 lines (151 loc) · 4.59 KB
/
.gitlab-ci.yml
File metadata and controls
163 lines (151 loc) · 4.59 KB
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
stages:
- check
- test
- analysis
- build
variables:
# Set PROJECT_NAME to the name of the project folder.
# Do not touch the other variables.
PROJECT_NAME: sindit-frontend
ROOTDIR: $CI_PROJECT_DIR/projects/$PROJECT_NAME
RULES_CHANGES_PATH: $ROOTDIR/**/*
CI_REGISTRY: gitlab.sintef.no:5050
IMAGE_PATH: $CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME
DOCKER_TLS_CERTDIR: ''
PUBLIC_SINDIT_BACKEND_API: http://0.0.0.0:9017
PUBLIC_SINDIT_BACKEND_API_BASE_URI: http://
before_script:
- cd projects/$PROJECT_NAME
- echo $SONAR_HOST_URL
.base-rules:
rules:
# Always run on default branch (main)
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
# Run on merge requests
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: always
allow_failure: false
# Run when triggered by parent pipeline
- if: $CI_PIPELINE_SOURCE == "parent_pipeline"
# Avoid duplicate jobs on merge requests
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
# Run if on a branch and not a merge request
- if: $CI_COMMIT_BRANCH
check:
stage: check
extends: .base-rules
image: alpine:latest
script:
- echo "This step always passes."
npm-test:
stage: test
image: node:23
before_script:
- cd projects/$PROJECT_NAME
script:
- npm install
- npm run coverage
- ls -la ./coverage
artifacts:
when: always
expire_in: 1 weeks
paths:
- $ROOTDIR/coverage
reports:
coverage_report:
coverage_format: cobertura
path: $ROOTDIR/coverage/cobertura-coverage.xml
rules:
- if: $CI_COMMIT_BRANCH == "sindit-frontend"
sonarqube:
stage: analysis
dependencies:
- npm-test
before_script:
- cd projects/$PROJECT_NAME
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: ['']
variables:
SONAR_USER_HOME: $ROOTDIR/.sonar
GIT_DEPTH: '0'
cache:
key: $CI_JOB_NAME
paths:
- $ROOTDIR/.sonar/cache
script:
- pwd
- ls -la
- sonar-scanner
allow_failure: true
rules:
- if: $CI_COMMIT_BRANCH == "sindit-frontend"
# Docker Build Instructions:
# This job only runs when a Git tag starting with "sindit-frontend-" is created.
# To trigger a Docker build:
# git tag sindit-frontend-1.0.0
# git push origin sindit-frontend-1.0.0
# The image will be tagged with: 1.0.0 (version without prefix) and latest
docker-build:
stage: build
extends: .base-rules
image: docker:latest
tags:
- dind
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
IMAGE_NAME: sindit-frontend
allow_failure: false
before_script:
- cd projects/$PROJECT_NAME
- |
echo "$CI_JOB_TOKEN" | docker login $CI_REGISTRY \
-u $CI_REGISTRY_USER --password-stdin
- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- docker buildx create --name mybuilder --use
# Extract version from tag (remove "sindit-frontend-" prefix)
- export IMAGE_VERSION=${CI_COMMIT_TAG#sindit-frontend-}
script: docker buildx build
--push
--platform linux/arm64/v8,linux/amd64
--provenance=false
--label "git-commit-sha=$CI_COMMIT_SHA"
--label "git-commit-branch=$CI_COMMIT_BRANCH"
--label "git-commit-timestamp=$CI_COMMIT_TIMESTAMP"
--label "git-commit-title=$CI_COMMIT_TITLE"
--label "git-tag=$CI_COMMIT_TAG"
-t $IMAGE_PATH/$IMAGE_NAME:$IMAGE_VERSION
-t $IMAGE_PATH/$IMAGE_NAME:latest .
rules:
- if: $CI_COMMIT_TAG =~ /^sindit-frontend-/
push-to-github:
stage: build
image: alpine:latest
before_script:
- apk add --no-cache git git-subtree openssh
- git config --global user.email "ci@sindit.com"
- git config --global user.name "SINDIT CI"
# Clone the current GitLab branch (either 'main' or 'sindit-frontend')
- git clone --branch $CI_COMMIT_BRANCH $CI_REPOSITORY_URL project
- cd project
# Set ROOTDIR relative to the Git repo root
- export ROOTDIR="projects/sindit-frontend"
# Set GitHub remote (will override if it already exists)
- |
if git remote | grep -q github; then
git remote set-url github https://$GITHUB_TOKEN@github.com/SINTEF-9012/SINDIT20-Frontend.git
else
git remote add github https://$GITHUB_TOKEN@github.com/SINTEF-9012/SINDIT20-Frontend.git
fi
script:
# Create a new branch from the subtree at $ROOTDIR
- git subtree split --prefix=$ROOTDIR -b subtree-sindit-frontend
# Push the subtree branch to GitHub's main branch
- git push github subtree-sindit-frontend:main --force
rules:
- if: $CI_COMMIT_BRANCH == "sindit-frontend"