-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
186 lines (170 loc) · 4.28 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
175
176
177
178
179
180
181
182
183
184
185
186
# Ref: https://docs.gitlab.com/ee/ci/yaml
# Ref: Predefined variables can be found here https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
image:
name: bufbuild/buf:1.17.0
entrypoint: [""]
include:
- project: sanctumlabs/tools/ci-workflows
file: .gitlab/templates/slack-notification.yml
variables:
BUF_CACHE_DIR: ".cache"
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
PIPELINE_NAME: 'Message Schema pipeline'
workflow:
name: 'Pipeline $CI_COMMIT_TITLE with SHA $CI_COMMIT_SHORT_SHA'
cache:
key: "$CI_COMMIT_REF_SLUG"
untracked: false
paths:
- ".cache"
stages:
- lint
- build
- test
- package
- tag
- release
lint-format:
stage: lint
script:
- buf lint
- buf format -d --exit-code
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: "$CI_COMMIT_BRANCH"
- if: "$CI_COMMIT_TAG"
breaking:
stage: test
needs:
- lint-format
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
script:
- buf breaking --against "${CI_REPOSITORY_URL}#branch=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
generate:
stage: build
needs:
- lint-format
script:
- buf generate
artifacts:
paths:
- "lib"
when: always
expire_in: 1 week
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: "$CI_COMMIT_BRANCH"
- if: "$CI_COMMIT_TAG"
push-buf-registry:
stage: package
needs:
- generate
script:
- echo ${BUF_API_TOKEN} | buf registry login --username ${BUF_USER} --token-stdin
- cd shared
- buf mod update
- cd ..
- buf push shared -t "${CI_COMMIT_TAG}"
- cd events
- buf mod update
- cd ..
- buf push events -t "${CI_COMMIT_TAG}"
- cd messages
- buf mod update
- cd ..
- buf push messages -t "${CI_COMMIT_TAG}"
# Generate the libraries, these will be passed on to the next jobs in the pipeline
- buf generate
only:
- tags
publish-pypi:
stage: package
image: python:3.8
needs:
- generate
script:
- cd lib/python
- make publish-gitlab
only:
- tags
publish-npm:
stage: package
image: node:20.4.0
needs:
- generate
script:
- cd lib/js
- make build
- echo @sanctumlabs:registry=https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/packages/npm/ > .npmrc
- echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}" >> .npmrc
- npm version ${CI_COMMIT_TAG}
- NPM_TOKEN=${CI_JOB_TOKEN} npm publish
only:
- tags
publish-maven:
stage: package
image: gradle:7.4-jdk8
needs:
- generate
script:
- cd lib/kotlin
- echo signingKey=${SIGNING_KEY} > gradle.properties
- ./gradlew -Pversion="${CI_COMMIT_TAG}" build
- ./gradlew -PsigningKeyId=${SIGNING_KEY_ID} -PsigningPassword=${SIGNING_PASSWORD} -Pversion="${CI_COMMIT_TAG}" -PgitlabProjectID="${CI_PROJECT_ID}" -PgitLabPrivateToken=${CI_PROJECT_ID} -PgitLabTokenName=Job-Token publishLibraryPublicationToGitlabRepository
only:
- tags
# publish the next tag automatically and only on the main branch when manually triggered
publish-tag:
stage: tag
needs:
- generate
image: node:18
variables:
GITLAB_TOKEN: ${GITLAB_ACCESS_TOKEN}
before_script:
- apt-get update && apt-get install -y --no-install-recommends git-core ca-certificates
- npm install -g semantic-release @semantic-release/gitlab @semantic-release/changelog @semantic-release/git
script:
- semantic-release
only:
- main
when: manual
release_job:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: "$CI_COMMIT_TAG"
script:
- echo "running release_job"
release:
tag_name: '$CI_COMMIT_TAG'
description: '$CI_COMMIT_TAG'
slack-success:
needs:
- job: publish-tag
optional: true
- job: release_job
optional: true
- job: push-buf-registry
optional: true
- job: publish-pypi
optional: true
- job: publish-npm
optional: true
- job: publish-maven
optional: true
slack-failure:
needs:
- job: publish-tag
optional: true
- job: release_job
optional: true
- job: push-buf-registry
optional: true
- job: publish-pypi
optional: true
- job: publish-npm
optional: true
- job: publish-maven
optional: true