Newer
Older
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
# -*- coding: utf-8 -*-
# vim: ft=yaml
#
# Hidden template jobs to be used in `.gitlab-ci.yml`
#
# - `.git:commitlint`: verify formatting of commit messages
#
# - `.git:merge-to`: merge release tags to the `${GIT_MERGE_TARGET}` branch
#
---
#
# .git:commitlint
# ===============
#
# Verify formatting of all commit messages in the range
# `${BASE_BRANCH}..${CI_COMMIT_SHA}`.
#
# USAGE
# =====
#
# include:
# - project: baby-gnu/ci-tools
# ref: main
# file: /templates/Git.yaml
#
# stages:
# - lint
#
# commitlint: {extends: '.git:commitlint'}
#
# REQUIREMENTS
# ============
#
# - a `lint` stage must be present in your pipeline or it must be
# overriden by the extending job to feet your need
#
# - the `.not-on-stable` rules templates or it must be overriden by
# the extending job to feet your need
#
# - a `${CI_COMMIT_SHA}` pointing to the last commit to verify
#
# - a `commitlint` configuration file
#
# OPTIONAL VARIABLES
# ==================
#
# - `BASE_BRANCH`: name of the referrence branch, defaults to
# `${CI_DEFAULT_BRANCH}`
#
# - `GIT_COMMITLINT_IMAGE`: name of the `commitlint` docker image to use
#
# USED CI VARIABLES
# =================
#
# - `CI_COMMIT_SHA`
#
# - `CI_DEFAULT_BRANCH`
#
# SEE ALSO
# ========
#
# - Upstream: https://github.com/conventional-changelog/commitlint/
#
.git:commitlint:
stage: lint
extends: .not-on-stable
image: "${GIT_COMMITLINT_IMAGE}"
variables:
GIT_COMMITLINT_IMAGE: 'hub.eole.education/eole/commitlint:latest'
BASE_BRANCH: "${CI_DEFAULT_BRANCH}"
script:
- echo -e "\e[0Ksection_start:`date +%s`:git-fetch[collapsed=true]\r\e[0KFetch all remotes"
- 'git fetch --all'
- echo -e "\e[0Ksection_end:`date +%s`:git-fetch\r\e[0K"
# Set default commit hashes for `--from` and `--to`
- echo -e "\e[0Ksection_start:`date +%s`:commitlint-configure[collapsed=true]\r\e[0KCalculate 'COMMITLINT_FROM' and 'COMMITLINT_TO'"
- 'export COMMITLINT_FROM="$(git merge-base origin/${BASE_BRANCH} HEAD)"'
- 'export COMMITLINT_TO="${CI_COMMIT_SHA}"'
- echo -e "\e[0Ksection_end:`date +%s`:commitlint-configure\r\e[0K"
# Run `commitlint`
- echo -e "\e[0Ksection_start:`date +%s`:commitlint\r\e[0KVerify commit message between '${COMMITLINT_FROM}..${COMMITLINT_TO}'"
- 'commitlint --from "${COMMITLINT_FROM}"
--to "${COMMITLINT_TO}"
--verbose'
- echo -e "\e[0Ksection_end:`date +%s`:commitlint\r\e[0K"
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
#
# .git:merge-to
# =============
#
# Merge `${GIT_MERGE_SOURCE}` to a `${GIT_MERGE_TARGET}` branch.
#
# USAGE
# =====
#
# include:
# - project: baby-gnu/ci-tools
# ref: main
# file: /templates/Git.yaml
#
# stages:
# - release
#
# merge-to-dev: {extends: '.git:merge-to', variables: {GIT_MERGE_TARGET: $DEV_BRANCH}}
#
# REQUIREMENTS
# ============
#
# - a `release` stage must be present in your pipeline or it must be
# overriden by the extending job to feet your need
#
# - the `.on-release-tag` rules templates or it must be overriden by
# the extending job to feet your need
#
# - a `${GIT_MERGE_TARGET}` branch name
#
# - a `${GIT_MERGE_SOURCE}` reference, by default `${CI_COMMIT_TAG}`
#
# - a `${GITLAB_TOKEN}` to push the merged `${GIT_MERGE_TARGET}`
# branch
#
# OPTIONAL VARIABLES
# ==================
#
# - `GIT_AUTHOR_NAME`: name of the optional merge commit author,
# extracted from `CI_COMMIT_AUTHOR` by default
#
# - `GIT_AUTHOR_EMAIL`: email of the optional merge commit author,
# extracted from `CI_COMMIT_AUTHOR` by default
#
# - `GIT_COMMITTER_NAME`: name of the optional merge commit committer,
# default to `${GIT_AUTHOR_NAME}`
#
# - `GIT_COMMITTER_EMAIL`: email of the optional merge commit, default
# to `${GIT_AUTHOR_EMAIL}`
#
# - `GIT_MERGE_TO_IMAGE`: name of the docker image to execute `git`
# commands
#
# USED CI VARIABLES
# =================
#
# - `CI_COMMIT_TAG`
#
# - `CI_COMMIT_AUTHOR`
#
# - `CI_REPOSITORY_URL`
#
# - `CI_JOB_TOKEN`
#
.git:merge-to:
stage: release
extends: .on-release-tag
image: "${GIT_MERGE_TO_IMAGE}"
variables:
GIT_MERGE_TO_IMAGE: 'bitnami/git:latest'
GIT_MERGE_SOURCE: ${CI_COMMIT_TAG}
GIT_MERGE_TARGET: ''
script:
# Configure git to be able to create merge commit
# Extract author name and mail if not SET
- echo -e "\e[0Ksection_start:`date +%s`:git-configure[collapsed=true]\r\e[0KConfigure git variables from '${CI_COMMIT_AUTHOR}'"
- export GIT_AUTHOR_NAME="${GIT_AUTHOR_NAME:-${CI_COMMIT_AUTHOR% <*}}"
- export TEMP_MAIL_PREFIX="${CI_COMMIT_AUTHOR#*<}"
- export GIT_AUTHOR_EMAIL="${GIT_AUTHOR_EMAIL:-${TEMP_MAIL_PREFIX%>}}"
- export GIT_COMMITTER_NAME="${GIT_COMMITTER_NAME:-${GIT_AUTHOR_NAME}}"
- export GIT_COMMITTER_EMAIL="${GIT_COMMITTER_EMAIL:-${GIT_AUTHOR_EMAIL}}"
- echo -e "\e[0Ksection_end:`date +%s`:git-configure\r\e[0K"
# Add `upstream` remote to get access to `upstream/dev`
# Use `${GITLAB_TOKEN}` for write permission
- echo -e "\e[0Ksection_start:`date +%s`:git-remote-upstream-add[collapsed=true]\r\e[0KAdd upstream repository and checkout '${GIT_MERGE_TARGET}'"
- "git remote show upstream 2> /dev/null || git remote add upstream ${CI_REPOSITORY_URL/${CI_JOB_TOKEN}/${GITLAB_TOKEN}}"
- 'git fetch --all'
- 'git checkout -B ${GIT_MERGE_TARGET} upstream/${GIT_MERGE_TARGET}'
- echo -e "\e[0Ksection_end:`date +%s`:git-remote-upstream-add\r\e[0K"
# Merge the release tag
- echo -e "\e[0Ksection_start:`date +%s`:git-merge-release[collapsed=true]\r\e[0KMerge '${GIT_MERGE_SOURCE}' in '${GIT_MERGE_TARGET}'"
- 'git merge --no-edit ${GIT_MERGE_SOURCE}'
- 'git push upstream ${GIT_MERGE_TARGET}'
- echo -e "\e[0Ksection_end:`date +%s`:git-merge-release\r\e[0K"
# Remove `upstream` to avoid caching `${GITLAB_TOKEN}`
- echo -e "\e[0Ksection_start:`date +%s`:git-cleanup[collapsed=true]\r\e[0KCleanup git repository"
- "git remote remove upstream"
- echo -e "\e[0Ksection_end:`date +%s`:git-cleanup\r\e[0K"