-
Notifications
You must be signed in to change notification settings - Fork 20
/
.gitlab-ci.yml
118 lines (110 loc) · 3.04 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
include:
- template: Jobs/Dependency-Scanning.gitlab-ci.yml
- template: Jobs/SAST.gitlab-ci.yml
- template: Jobs/Secret-Detection.gitlab-ci.yml
# - template: Jobs/License-Scanning.gitlab-ci.yml
- project: 'dependabot-gitlab/dependabot-standalone'
file: '.gitlab-ci.yml'
variables:
SAST_EXCLUDED_PATHS: 'spec, test, tests, tmp, lib, node_modules'
.nodestuff: &nodestuff
image: ${CI_DEP_PREFIX}node:lts-alpine
cache:
key:
files:
- package-lock.json
paths:
- node_modules
install:
stage: build
script:
- npm install
- npm pack
artifacts:
paths:
- ./lib/*.js
- ./*.tgz
<<: *nodestuff
test:
stage: test
needs:
- install
script:
- npm run test -- --reporter mocha-junit-reporter
coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'
artifacts:
reports:
junit: test-results.xml
coverage_report:
coverage_format: cobertura
path: coverage/cobertura-coverage.xml
<<: *nodestuff
.pubCheck: &pubCheck
# Compare the versions in git and in node to verify that they are the same
- |
NODE_VERSION=$(node -e "r=require('./package.json');console.log(r.version);")
GIT_VERSION=$(echo $CI_COMMIT_TAG | sed 's/^v//')
if [ "$NODE_VERSION" == "$GIT_VERSION" ]; then
echo "Versions match. Continuing."
else
echo "Error, versions do not match."
exit 3
fi
- echo "CI_SHORT_VERSION=$NODE_VERSION" > dotenv
publish:
<<: *nodestuff
stage: deploy
needs:
- install
- test
rules:
- if: $CI_COMMIT_TAG
before_script: *pubCheck
script:
- echo "//registry.npmjs.org/:_authToken=$VAR_NPM_AUTHTOKEN" > ~/.npmrc
- npm publish || echo "This failed but thats okay."
environment:
name: npmjs
url: https://www.npmjs.com/package/$CI_PROJECT_NAME
artifacts:
reports:
dotenv: './dotenv'
publish_gitlab:
<<: *nodestuff
stage: deploy
needs:
- install
- test
rules:
- if: $CI_COMMIT_TAG
before_script: *pubCheck
script:
- |
echo "@${CI_PROJECT_ROOT_NAMESPACE}:registry=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/" > ~/.npmrc
echo "${CI_API_V4_URL#https?}/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=\${CI_JOB_TOKEN}" >> ~/.npmrc
- |
sed -i "s/\(^ \"name\": \)\"\($CI_PROJECT_NAME\)\"/\1\"@$CI_PROJECT_ROOT_NAMESPACE\/\2\"/" package.json
- npm publish
environment:
name: gitlab-npm
url: $CI_PROJECT_URL/-/packages?type=npm&orderBy=name&sort=desc&search[]=
release:
stage: deploy
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- publish
rules:
- if: $CI_COMMIT_TAG
script:
- echo "Creating the release at $CI_COMMIT_TAG"
release:
name: "mock-local-storage $CI_COMMIT_TAG"
tag_name: $CI_COMMIT_TAG
ref: $CI_COMMIT_TAG
description: "Automated release for mock-local-storage at $CI_COMMIT_TAG"
milestones:
- $CI_COMMIT_TAG
assets:
links:
- name: mock-local-storage@$CI_COMMIT_TAG
url: https://www.npmjs.com/package/$CI_PROJECT_NAME/v/$CI_SHORT_VERSION