-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
138 lines (119 loc) · 3.72 KB
/
.gitlab-ci.yml
File metadata and controls
138 lines (119 loc) · 3.72 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
image: node:12
#===========================================================
# global variables
#===========================================================
variables:
CACHE_DIR: .npm
npm_config_cache: $CI_PROJECT_DIR/$CACHE_DIR
INFINITY_VERSION_PRERELEASE_SEPARATOR: "-"
stages:
- build
- test
- publish
- tag
#===========================================================
# global job configuration and templates
#===========================================================
# output build info in each job
before_script:
- infinity config build-info
# for the cache we can rely on the package-lock.json file hash - if it changed, we use a new cache
# a cache template to use push strategy for updating the cache
.setup_cache: &setup_cache
cache:
key:
files:
- package-lock.json
paths:
- $CACHE_DIR
policy: push
# a cache template to use pull strategy to just use the cache
.use_cache: &use_cache
cache:
key:
files:
- package-lock.json
paths:
- $CACHE_DIR
policy: pull
# a template for installing dependencies faster
.install_deps: &install_deps
- npm ci --cache $CACHE_DIR --prefer-offline --no-audit --verbose
# a template for ssh setup
.setup_ssh: &setup_ssh
before_script:
# export the SSH_AUTH_SOCK and SSH_AGENT_PID variables
- eval "$(infinity ssh agent)"
# Use infinity to add gitlab runner to known host for git clone (using ssh)
- infinity ssh set-knownhosts
# We add a custom user for git operations during CI
- git config --global user.email $INFINITY_USER_EMAIL
- git config --global user.name $INFINITY_USER_NAME
build:
stage: build
<<: *setup_cache
script:
- *install_deps
- npm run publish:prepare
- cd dist && npm version --no-git-tag-version --allow-same-version $(infinity version get)
artifacts:
paths:
- dist
test:
stage: test
<<: *setup_cache
dependencies:
- build
needs:
- build
script:
- *install_deps
- npm run test
- npm run coverage
coverage: '/Statements\s+:\s(\d+.?\d+)%/'
artifacts:
paths:
- coverage
internal-publish:
stage: publish
rules:
# trigger only for branches, skip tags
- if: '$CI_COMMIT_BRANCH == $CI_COMMIT_REF_NAME'
dependencies:
- build
needs:
- build
script:
- echo $CI_COMMIT_TAG
- echo $CI_COMMIT_BRANCH
- npm config set registry $NEXUS3_NPM_REGISTRY
- infinity npm publish dist/
release-tag:
stage: tag
<<: *setup_ssh
<<: *use_cache
rules:
- if: '$CI_COMMIT_BRANCH == "master" && $CI_COMMIT_MESSAGE =~ /^release: auto/'
dependencies:
- build
- test
needs:
- build
- test
script:
# we create temporary folder to hold newly cloned project
- PROJECT_CLONE=$(mktemp -d)
# we clone git project into temporary folder
- infinity git clone --destination $PROJECT_CLONE --branch $CI_COMMIT_REF_NAME
# we copy cache directory to cloned project
- if [ -d $CACHE_DIR ]; then cp -r $CACHE_DIR $PROJECT_CLONE/$CACHE_DIR; fi
# we enter the repository root
- cd $PROJECT_CLONE
# now that our repository is up-to-date we need to install dependencies
- *install_deps
# now we can run standard-version
- npm run release:tag
# we push the changes to the triggering branch, including the tag created by standard-version
- infinity git push --include-tags
# remove cloned repository
- rm -rf $PROJECT_CLONE