-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
179 lines (149 loc) · 4.95 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
image: python:3.8-buster
variables:
GIT_SUBMODULE_STRATEGY: recursive
GIT_DEPTH: 1
BRANCH_NAME: "${CI_COMMIT_REF_NAME}_temp" # Name of the branch to modify
BOT_NAME: "GitLab Runner Bot" # Bot's name that appears in the commit log
BOT_EMAIL: "[email protected]" # Bot's email, not important
COMMIT_MESSAGE: "Commit from runner " # Part of the commit message
.push_convert: &push_convert |
lines=$(git diff --cached | wc -l)
if [ $lines -gt 0 ]; then
echo "commiting"
git commit -m 'convert whitelists'
echo "git push $BRANCH_NAME"
git push -o ci.skip "https://whatever:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@}" $BRANCH_NAME
else
echo "nothing to commit"
fi
.delete_private_files: &delete_private_files |
lines=$(git for-each-ref refs/heads/ --format='%(refname:short)')
if [ $(echo $lines | grep -w $BRANCH_NAME | wc -l) -gt 0 ]; then
git checkout $BRANCH_NAME
else
git checkout -b $BRANCH_NAME
fi
for FILENAME in $(cat private_files)
do
for DELETE_FILE in $(find -print | grep $(echo $FILENAME | tr -d '\r')$)
do
git rm $DELETE_FILE
done
done
git commit -m 'delete private files'
echo "git push $BRANCH_NAME"
git push -o ci.skip "https://whatever:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@}" $BRANCH_NAME
.push_merge_public: &push_merge_public |
git checkout public
git pull --allow-unrelated-histories --strategy-option theirs
git merge --allow-unrelated-histories origin/$BRANCH_NAME --strategy-option theirs
echo "merge branches"
git push -o ci.skip "https://whatever:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@}" public
.push_merge: &push_merge |
lines=$(git ls-remote --heads "https://whatever:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@}" $BRANCH_NAME | wc -l)
if [ $lines -gt 0 ]; then
git checkout $CI_COMMIT_REF_NAME
git pull
git merge --allow-unrelated-histories origin/$BRANCH_NAME --strategy-option theirs
echo "merge branches"
git push -o ci.skip "https://whatever:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@}" $CI_COMMIT_REF_NAME
else
echo "nothing to commit"
fi
.remove_local: &remove_local |
git fetch --all --prune
lines=$(git for-each-ref refs/heads/ --format='%(refname:short)')
echo $lines
if [ $(echo $lines | grep -w $BRANCH_NAME | wc -l) -gt 0 ]; then
git branch -D $BRANCH_NAME
echo "delete local branch"
else
echo "No local branch to delete"
fi
git fetch --all --prune
lines=$(git for-each-ref refs/heads/ --format='%(refname:short)')
echo $lines
if [ $(echo $lines | grep -w main_temp | wc -l) -gt 0 ]; then
git branch -D main_temp
echo "delete local branch"
else
echo "No local main_temp branch to delete"
fi
.remove_remote: &remove_remote |
git fetch --all --prune
lines=$(git for-each-ref refs/remotes/ --format='%(refname:short)')
echo $lines
if [ $(echo $lines | grep -w "origin/$BRANCH_NAME" | wc -l) -gt 0 ]; then
git push "https://whatever:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@}" --delete $BRANCH_NAME
echo "delete remote branch"
else
echo "No remote branch to delete"
fi
git fetch --all --prune
lines=$(git for-each-ref refs/remotes/ --format='%(refname:short)')
echo $lines
if [ $(echo $lines | grep -w "origin/main_temp" | wc -l) -gt 0 ]; then
git push "https://whatever:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@}" --delete main_temp
echo "delete remote branch"
else
echo "No remote main_temp branch to delete"
fi
before_script:
- pip install -r requirements.txt
stages:
- pre_remove
- test
- convert
- merge
- merge_public
- post_remove
test_whitelists:
stage: test
script:
- test/test_whitelists.py
convert_whitelists:
stage: convert
except:
- public
script:
- test/update_department.py -d "${MANAGEMENT_API_DOMAIN}" -id "${MANAGEMENT_API_CLIENTID}" -s "${MANAGEMENT_API_SECRET}"
- misc/convert.py
- git config --global user.name "${BOT_NAME}"
- git config --global user.email "${BOT_EMAIL}"
- git fetch --all --prune
- git checkout -b $BRANCH_NAME
- git add whitelists/department
- git add misc/json
- *push_convert
merge_branch:
stage: merge
except:
- public
script:
- git fetch
- git config --global user.name "${BOT_NAME}"
- git config --global user.email "${BOT_EMAIL}"
- *push_merge
remove_branch_pre:
stage: pre_remove
script:
- git config --global user.name "${BOT_NAME}"
- git config --global user.email "${BOT_EMAIL}"
- *remove_local
- *remove_remote
remove_branch_post:
stage: post_remove
script:
- git config --global user.name "${BOT_NAME}"
- git config --global user.email "${BOT_EMAIL}"
- *remove_local
- *remove_remote
merge_public_branch:
stage: merge_public
only:
- main
script:
- git config --global user.name "${BOT_NAME}"
- git config --global user.email "${BOT_EMAIL}"
- *delete_private_files
- *push_merge_public