-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
239 lines (228 loc) · 7.14 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
239 lines (228 loc) · 7.14 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
---
stages:
- molecule
- changes
- push
variables:
GITHUB_USER: lotusnoir
ANSIBLE_REMOTE_TMP: /tmp
PY_COLORS: 1
######################################################
# DEFINE CHANGES RULES
######################################################
.molecule_job_template: &molecule_job_template
stage: molecule
rules:
# Exécuter uniquement si un fichier pertinent change
- changes:
- ".gitlab-ci.yml"
- "defaults/**"
- "files/**"
- "handlers/**"
- "meta/**"
- "tasks/**"
- "templates/**"
- "vars/**"
- "molecule/*/**" # Inclut tous les fichiers dans chaque scenario
- "molecule/*" # Inclut le scenario lui-même (utile pour playbook.yml)
- when: never # Sinon, ne pas exécuter
######################################################
# RUN MOLECULE FOR EACH DISTRIB
######################################################
molecule_debian12:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.18.11
script:
- MOLECULE_DISTRIB=debian12 molecule test
molecule_debian11:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.18.11
script:
- MOLECULE_DISTRIB=debian11 molecule test
molecule_debian10:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.15.13
script:
- MOLECULE_DISTRIB=debian10 molecule test
molecule_debian13:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.18.11
script:
- MOLECULE_DISTRIB=debian13 molecule test
molecule_oraclelinux10:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.18.11
tags:
- avx2
script:
- MOLECULE_DISTRIB=oraclelinux10 molecule test
molecule_oraclelinux9:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.18.11
script:
- MOLECULE_DISTRIB=oraclelinux9 molecule test
molecule_redhat10:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.18.11
tags:
- avx2
script:
- MOLECULE_DISTRIB=redhat10 molecule test
molecule_redhat8:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.15.13
script:
- MOLECULE_DISTRIB=redhat8 molecule test
molecule_redhat9:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.18.11
script:
- MOLECULE_DISTRIB=redhat9 molecule test
molecule_rocky10:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.18.11
tags:
- avx2
script:
- MOLECULE_DISTRIB=rocky10 molecule test
molecule_rocky8:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.15.13
script:
- MOLECULE_DISTRIB=rocky8 molecule test
molecule_rocky9:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.18.11
script:
- MOLECULE_DISTRIB=rocky9 molecule test
molecule_ubuntu20:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.18.11
variables:
MOLECULE_DOCKER_COMMAND: "--cap-add NET_ADMIN"
script:
- MOLECULE_DISTRIB=ubuntu20 molecule test
molecule_ubuntu22:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.18.11
script:
- MOLECULE_DISTRIB=ubuntu22 molecule test
molecule_ubuntu24:
<<: *molecule_job_template
image: lotusnoir/molecule_play:2.18.11
script:
- MOLECULE_DISTRIB=ubuntu24 molecule test
######################################################
# GENERATE CHANGELOG FILE
######################################################
changelog:
stage: changes
image: node:19
needs:
- job: molecule_debian12
optional: true
- job: molecule_debian11
optional: true
- job: molecule_debian10
optional: true
- job: molecule_debian13
optional: true
- job: molecule_oraclelinux10
optional: true
- job: molecule_oraclelinux9
optional: true
- job: molecule_redhat10
optional: true
- job: molecule_redhat8
optional: true
- job: molecule_redhat9
optional: true
- job: molecule_rocky10
optional: true
- job: molecule_rocky8
optional: true
- job: molecule_rocky9
optional: true
- job: molecule_ubuntu20
optional: true
- job: molecule_ubuntu22
optional: true
- job: molecule_ubuntu24
optional: true
artifacts:
paths:
- CHANGELOG.md
expire_in: 1 day
before_script:
- apt-get update -qq && apt-get install -y git rsync
- npm install -g auto-changelog
- git config --global user.name "CI Bot"
- git config --global user.email "ci@${CI_SERVER_HOST}"
script:
# 1️⃣ Clone GitHub repository (source of truth)
- mkdir -p ~/.ssh
- echo "$GITHUB_USER_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_ed25519
- chmod 600 ~/.ssh/id_ed25519
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
- eval $(ssh-agent -s)
- ssh-add ~/.ssh/id_ed25519
- git clone git@github.com:${GITHUB_USER}/ansible-apps_akhq.git tmp_repo
- cd tmp_repo
- git fetch --tags
# 2️⃣ Merge local GitLab changes as working tree diff (no commits)
- rsync -av --exclude .git "${CI_PROJECT_DIR}/" ./
# 3️⃣ Skip changelog if last commit is already a changelog
- LAST_MSG="$(git log -1 --pretty=%B || echo '')"
- |
if echo "$LAST_MSG" | grep -qiE "changelog|update changelog|maj changelog"; then
echo "⚠️ Last commit is a changelog, skipping."
echo "skip" > CHANGELOG.md
exit 0
fi
# 4️⃣ Debug: show last tags
- echo "🔖 Tags present on GitHub branch:"
- git tag --sort=creatordate | tail -n 10
# 5️⃣ Generate changelog based only on GitHub history
- auto-changelog \
-t keepachangelog \
--commit-url "https://github.com/${GITHUB_USER}/ansible-apps_akhq/commit/{{hash}}" \
--issue-url "" \
--sort-commits date-desc \
--hide-empty-releases \
--hide-credit \
-b 50
# 6️⃣ Copy changelog to CI project root
- cp CHANGELOG.md ${CI_PROJECT_DIR}/
##################################################
# PUSH CODE WHEN ALL TEST OK
##################################################
push_src_on_github:
stage: push
image: alpine:latest
needs:
- changelog
before_script:
- apk add git openssh-client
- eval $(ssh-agent -s)
- echo "${GITHUB_USER_PRIVATE_KEY}" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo -e "Host *\n\tUser ansible\n\tStrictHostKeyChecking no\n\tForwardAgent yes\n\n" > ~/.ssh/config
- git config --global user.email "${GITHUB_USER_EMAIL}"
- git config --global user.name "${GITHUB_USER}"
- git config --global init.defaultBranch main
- COMMENT=$(git log -1 --pretty=%B | head -1)
script:
- if grep -q "^skip" CHANGELOG.md 2>/dev/null; then
echo "⚠️ Changelog marqué 'skip' — aucun push GitHub effectué.";
exit 0;
fi
- git clone git@github.com:${GITHUB_USER}/ansible-apps_akhq.git /tmp/ansible-apps_akhq
- find /tmp/ansible-apps_akhq -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf "{}" +;
- rm -rf .git
- cp -r . /tmp/ansible-apps_akhq/
- cd /tmp/ansible-apps_akhq
- git add -A
# - git diff --quiet && echo "✅ Aucun changement à pousser." && exit 0
- git commit -m "${COMMENT}" || echo "No changes, nothing to commit!"
- git push --follow-tags