-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
174 lines (166 loc) · 4.32 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
stages:
- dependencies
- lint
- update
- build
- publish
build dependencies:
stage: dependencies
image: alpine/helm:3.10.1
script:
- helm dependencies build
artifacts:
name: dependencies
paths:
- charts/*
- Chart.lock
rules:
- when: on_success
lint:
stage: lint
image: alpine/helm:3.10.1
script:
- helm lint
needs:
- build dependencies
rules:
- when: on_success
verify values.yaml annotations:
stage: lint
image: alpine/helm:3.10.1
before_script:
- apk update
- apk add npm
- npm install -g @bitnami/readme-generator-for-helm
script:
- readme-generator --values values.yaml --readme README.md --schema "/tmp/schema.json"
needs: []
rules:
- if: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
when: on_success
- if: '$CI_COMMIT_TAG'
when: on_success
- changes:
- values.yaml # If it has changed, we will push the updated Readme instead
when: never
update readme:
stage: update
image: alpine
before_script:
- apk update
- apk add git npm openssh-client curl
- npm install -g @bitnami/readme-generator-for-helm
- git config --global user.name "HackademINT CI"
- git config --global user.email "ci@hackademint.org"
- mkdir -p ~/.ssh
- mv ${CI_PUSH_KEY} ~/.ssh/id_ecdsa
- chmod 600 ~/.ssh/id_ecdsa
- ssh-keyscan -p ${CI_SERVER_SHELL_SSH_PORT} ${CI_SERVER_SHELL_SSH_HOST} >> ~/.ssh/known_hosts
- git clone "ssh://git@${CI_SERVER_SHELL_SSH_HOST}:${CI_SERVER_SHELL_SSH_PORT}/${CI_PROJECT_PATH}.git" "${CI_COMMIT_SHA}"
script:
- cd ${CI_COMMIT_SHA}
- git switch ${CI_COMMIT_BRANCH}
- readme-generator --values values.yaml --readme README.md --schema "/tmp/schema.json"
- |-
CHANGES=$(git status --porcelain | wc -l)
if [ "$CHANGES" -gt "0" ]
then
git add README.md
git status
git commit -m "CI bot: Update README.md from values.yaml"
git push
else
echo "No changes to commit, triggering another job"
curl --request POST \
--fail \
--form token=${FAILED_PUSH_PIPELINE_TRIGGER} \
--form ref=${CI_COMMIT_REF_NAME} \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/trigger/pipeline"
fi
needs:
- lint
rules:
- if: '$CI_COMMIT_TAG'
when: never
- if: $CI_PIPELINE_SOURCE == "trigger"
when: never
- if: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
when: never # We let the commit job deal with it
- changes:
- values.yaml
when: on_success
- when: never
package chart:
stage: build
image: alpine/helm:3.10.1
script:
- helm package .
needs:
- build dependencies
- lint
artifacts:
name: Helm package
paths:
- "*.tgz"
rules:
- when: on_success
publish to gitlab packages:
stage: publish
image: curlimages/curl:latest
script:
- |
if [[ "${CI_COMMIT_BRANCH}" != "${CI_DEFAULT_BRANCH}" ]];
then
CHANNEL="unstable"
else
CHANNEL="stable"
fi
- PACKAGE=$(ls *.tgz);
- >-
curl --request POST
--user gitlab-ci-token:$CI_JOB_TOKEN
--form "chart=@${PACKAGE}"
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/helm/api/${CHANNEL}/charts"
needs:
- package chart
rules:
- if: '$CI_COMMIT_TAG'
when: on_success
- if: $CI_PIPELINE_SOURCE == "trigger"
when: on_success
- changes:
- values.yaml
when: never
- when: on_success
publish to gitlab registry:
stage: publish
image: alpine/helm:3.10.1
script:
- PACKAGE=$(ls *.tgz);
- helm registry login ${CI_REGISTRY} -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD}
- helm push ${PACKAGE} oci://${CI_REGISTRY_IMAGE}
needs:
- package chart
rules:
- if: '$CI_COMMIT_TAG'
when: on_success
- changes:
- values.yaml
when: never
- when: never
publish to docker hub:
stage: publish
image: alpine/helm:3.10.1
script:
- PACKAGE=$(ls *.tgz);
- echo ${DOCKER_HUB_TOKEN} | helm registry login registry-1.docker.io -u hackademint --password-stdin
- helm push ${PACKAGE} oci://registry-1.docker.io/hackademint
needs:
- package chart
rules:
- if: '$CI_COMMIT_TAG'
when: on_success
- changes:
- values.yaml
when: never
- when: never