-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
137 lines (127 loc) · 3.88 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# .gitlab-ci.yml file to be placed in the root of your repository
variables:
MAINT_BRANCH_PATTERN: /^(([0-9]+)\.)?([0-9]+)\.x/
PREREL_BRANCH_PATTERN: /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
CYPRESS_INSTALL_BINARY: "0"
LIB_NAME: "crossref-ui"
DEPLOY_EXCLUDE_GLOB: "demo.html"
DEPLOY_INCLUDE_GLOB: "*"
DEPLOY_PATH_PREFIX: "${CI_PROJECT_NAME}/${LIB_NAME}"
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ''
NODE_DOCKER_IMAGE: "node:16.6.2-alpine3.13"
CI_BUILD_IMAGE: "${CI_REGISTRY_IMAGE}/ci-build:${CI_COMMIT_REF_SLUG}"
VUE_APP_BASE_ROUTE: "/${CI_PROJECT_NAME}/"
stages:
- build-ci-docker-image
- get-version
- unit-test
- build
- semantic-release
- pages
# - integration-test
# - deploy-stg
# - deploy-sandbox
# - deploy-production
# - deploy-pages
build-ci-docker-image:
image: docker:19.03.12
stage: build-ci-docker-image
services:
- docker:19.03.12-dind
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -f Dockerfile.ci -t $CI_BUILD_IMAGE .
- docker push $CI_BUILD_IMAGE
unit test:
image: "$CI_BUILD_IMAGE"
stage: unit-test
script:
- export APP_VERSION="$(cat VERSION.txt)"
- echo "APP_VERSION is ${APP_VERSION}"
- npm ci
- npm run test:unit
build:
image: "$CI_BUILD_IMAGE"
stage: build
script:
- export APP_VERSION="$(cat VERSION.txt)"
- echo "APP_VERSION is ${APP_VERSION}"
- npm ci
- npm run build
artifacts:
paths:
- dist # artifact path must be /public for GitLab Pages to pick it up
semantic-release:
image: registry.gitlab.com/crossref/infrastructure/aws-ecr-ecs-cicd-docker:latest
stage: semantic-release
variables:
AWS_DEFAULT_PROFILE: staging
tags:
- aws
- crossref-portal
# services:
# - docker:dind
before_script:
- export APP_VERSION="$(cat VERSION.txt)"
- "[[ -z ${CI_PIPELINE_ID+x} ]] && export APP_VERSION=$CI_COMMIT_SHA"
- echo "APP_VERSION is ${APP_VERSION}"
- if [ -z "$APP_VERSION" ]; then echo "APP_VERSION is not defined, exiting."; exit 0; fi
script:
- "[[ ! -z ${CI_PIPELINE_ID+x} ]] && npx semantic-release"
artifacts:
paths:
- dist # artifact path must be /public for GitLab Pages to pick it up
only:
- main
# Get current semantic version for release branches
get-semantic-version:
image: registry.gitlab.com/crossref/infrastructure/aws-ecr-ecs-cicd-docker:latest
stage: get-version
only:
refs:
- main
- $MAINT_BRANCH_PATTERN
- $PREREL_BRANCH_PATTERN
script:
- echo "Using semantic version"
# - npm install @semantic-release/gitlab @semantic-release/exec @semantic-release/changelog
- npx semantic-release --dry-run
artifacts:
paths:
- VERSION.txt
# Get generic version for non-release branches
get-generic-version:
image: node:lts-alpine
stage: get-version
except:
refs:
- main
- $MAINT_BRANCH_PATTERN
- $PREREL_BRANCH_PATTERN
script:
- echo "Using generic version"
- export APP_VERSION="build-${CI_PIPELINE_ID}"
- echo "Version is ${APP_VERSION}"
- echo $APP_VERSION > VERSION.txt
artifacts:
paths:
- VERSION.txt
pages: # the job must be named pages
image: node:lts-alpine
stage: pages
before_script:
- export APP_VERSION="$(cat VERSION.txt)"
- echo "APP_VERSION is ${APP_VERSION}"
script:
- mv public public-vue # GitLab Pages hooks on the public folder
- mv dist public # rename the dist folder (result of npm run build)
- echo "APP_VERSION is ${APP_VERSION}" > public/version.txt
# optionally, you can activate gzip support wih the following line:
- find public -type f -regex '.*\.\(htm\|html\|txt\|text\|js\|css\)$' -exec gzip -f -k {} \;
artifacts:
paths:
- public # artifact path must be /public for GitLab Pages to pick it up
only:
- main