-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.gitlab-ci.yml
98 lines (88 loc) · 3.48 KB
/
.gitlab-ci.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
# Entry point for GitLab CI for the Terminarium Project
# Variables are defined in the following order:
variables:
SRC_PATH: src/web/terminarium-web
# Define the docker image to use for the jobs - node:alpine
image: node:alpine
# Define the cache to use for the jobs
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .npm
# The stages are the following:
# 1. install-job: Install all the dependencies for the npm pr
# 2. lint-job: Lint the project - catch syntax errors and bad practices
# 3. test-job: Test the project - run the unit tests
# 4. build-job: Build the project
# 5. deploy-job: Deploy the project
stages:
- install
- lint
- test
- build
- deploy
# Define the image to use for the jobs
before_script:
- cd $SRC_PATH # Navigate to the source code (package-lock.json file is required)
- npm ci --cache .npm # Install the dependencies from the package-lock.json file
- apk add --no-cache bash git # Install bash and git
# Job 1. Install the dependencies
install-job:
stage: install
tags:
- docker
script:
- echo "Installing dependencies..." # Print a message
- npm install # Install the dependencies
- echo "Dependencies installed!" # Print a message
# Job 2. Lint the project
lint-job:
stage: lint
tags:
- docker
script:
- echo "Linting the project..." # Print a message
- npm run lint # Lint the project
- echo "Project linted!" # Print a message
# Job 3. Test the project
test-job:
stage: test
tags:
- docker
script:
- echo "Testing the project..." # Print a message
- npm run test:unit # Test the project (via unit tests)
- echo "Project tested!" # Print a message
# Job 4. Build the project
build-job:
stage: build
tags:
- docker
script:
- echo "Building the project..." # Print a message
- npm run build # Build the project
- echo "Project built!" # Print a message
artifacts:
paths:
- $SRC_PATH/dist # Save the build folder as an artifact
only:
- main # Only build the project when the main branch is updated
# Job 5. Deploy the project
deploy-job:
stage: deploy
tags:
- docker
script:
- echo "Deploying the project..." # Print a message
# Deploy the project with a log - use the environment variables to authenticate with Netlify and select the site to deploy
# Observe: this is different than the deploy script defined in the package.json file; the reason is, that the GitLab platform
# is given the environment variables via the CI/CD settings. On the other hand, on the local level, the environment variables
# are given within the shell instance, and hence `npm run deploy` is sufficient (the netlify-cli package is installed locally
# and has the access to the environment variables via an authentication process).
- ./node_modules/.bin/netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --dir dist | tee deploy.log
- echo "Project deployed!" # Print a message
artifacts:
paths:
- $SRC_PATH/deploy.log # Save the log of the deployment as an artifact
only:
- main # Only deploy the project when the main branch is updated