-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
115 lines (104 loc) · 2.63 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
image: node:16.13.1-alpine
stages:
- build
- test
- deploy review
- deploy staging
- deploy production
- production tests
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
variables:
STAGING_DOMAIN: carrotcabbage-staging.surge.sh
PRODUCTION_DOMAIN: carrotcabbage.surge.sh
build website:
stage: build
#only:
# - main
# - merge_requests
script:
- echo $CI_COMMIT_SHORT_SHA
- npm install --silent
- npm install -g gatsby-cli
- gatsby build
- sed -i "s/%%VERSION%%/$CI_COMMIT_SHORT_SHA/" ./public/index.html
artifacts:
paths:
- ./public
test artifact:
stage: test
image: alpine
script:
- grep -q "Gatsby" ./public/index.html
test website:
stage: test
script:
- npm install --silent
- npm install -g gatsby-cli
- gatsby serve &
- sleep 3
- apk --no-cache add curl
- curl "http://localhost:9000" | tac | tac | grep -q "Gatsby"
deploy review:
stage: deploy review
only:
- merge_requests
script:
- npm install --silent
- npm install -g gatsby-cli
- gatsby build
- npm install --global surge
- surge --project ./public --domain carrotcabbage-$CI_ENVIRONMENT_SLUG.surge.sh
environment:
name: review/$CI_COMMIT_REF_NAME
url: https://carrotcabbage-$CI_ENVIRONMENT_SLUG.surge.sh
on_stop: destroy review
artifacts:
paths:
- ./public
destroy review:
stage: deploy review
only:
- merge_requests
variables:
GIT_STRATEGY: none
script:
- npm install --global surge
- surge teardown carrotcabbage-$CI_ENVIRONMENT_SLUG.surge.sh
when: manual
environment:
name: review/$CI_COMMIT_REF_NAME
action: stop
deploy staging:
stage: deploy staging
environment:
name: staging
url: https://$STAGING_DOMAIN
only:
- main #(only main branch since it's deployment)
script:
- npm install --global surge
- surge --project ./public --domain $STAGING_DOMAIN
deploy production:
stage: deploy production
environment:
name: production
url: https://$PRODUCTION_DOMAIN
# when: manual # the stage would be waiting for a manual execution
# allow_failure: false # the option would postpone the rest stages
only:
- main #(only main branch since it's deployment)
script:
- npm install --global surge
- surge --project ./public --domain $PRODUCTION_DOMAIN
production tests:
image: alpine
stage: production tests
only:
- main #(only main branch since it's deployment)
script:
- apk add --no-cache curl
- curl -s "https://carrotcabbage.surge.sh" | grep -q "Hi people"
- curl -s "https://carrotcabbage.surge.sh" | grep -q "$CI_COMMIT_SHORT_SHA"