-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
274 lines (254 loc) · 8.21 KB
/
.gitlab-ci.yml
File metadata and controls
274 lines (254 loc) · 8.21 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
stages:
- test
- publish
include:
- template: Code-Quality.gitlab-ci.yml
- template: Security/SAST.gitlab-ci.yml
- component: $CI_SERVER_FQDN/components/dependency-scanning/main@0.6.0
.test:
parallel:
matrix:
- PY_VERSION: [ "3.12", "3.13", "3.14" ]
stage: test
image: python:$PY_VERSION
rules:
- if: '$CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event"'
before_script:
- test $(echo $PY_VERSION | cut -d . -f 2) -gt 12 && (apt update && apt install -y gfortran libopenblas-dev)
- pip install --root-user-action ignore -q poetry
- poetry install
unit tests:
extends: .test
script:
- poetry run pytest --junitxml=pytest.xml tests/unit
artifacts:
reports:
junit:
- pytest.xml
integration tests:
extends: .test
script:
- poetry run pytest --junitxml=pytest.xml tests/integration
artifacts:
reports:
junit:
- pytest.xml
mypy:
extends: .test
script:
- poetry run mypy duplicate_images tests
flake8:
extends: .test
script:
- poetry run flake8 duplicate_images tests
pylint:
extends: .test
script:
- test $(echo $PY_VERSION | cut -d . -f 2) -ge 12 && PYLINT_EXTRA_ARGS="--disable=inconsistent-quotes"
- poetry run pylint $PYLINT_EXTRA_ARGS duplicate_images tests
bandit:
extends: .test
parallel:
matrix:
- PY_VERSION: [ "3.12" ]
script:
- poetry run bandit -r duplicate_images
ChangelogIsUpdated:
stage: test
image: alpine:latest
rules:
- if: "$CI_MERGE_REQUEST_ID"
- if: $CI_COMMIT_BRANCH == "master"
script:
- VERSION=$(egrep 'version = ".*"' pyproject.toml | cut -d \" -f 2)
- test -n "$VERSION"
- fgrep "## [$VERSION]" CHANGELOG.md
- fgrep "...$VERSION" CHANGELOG.md
- fgrep "## [$VERSION] - $(date +%Y-%m-%d)" CHANGELOG.md
RunAndCheckResults:
extends: .test
variables:
IMAGE_DIR: tests/integration/data/equal_but_binary_different
script:
- NUM_FILES=$(find $IMAGE_DIR -type f | wc -l)
- EXPECTED_PAIRS=$((NUM_FILES*(NUM_FILES-1)/2)) # should be if all files matched...
- EXPECTED_PAIRS=29 # ...turns out not all files match with each other though
- NUM_PAIRS=$(poetry run find-dups $IMAGE_DIR | wc -l)
- test $NUM_PAIRS -eq $EXPECTED_PAIRS
- NUM_PAIRS=$(poetry run find-dups $IMAGE_DIR --progress --quiet | wc -l)
- test $NUM_PAIRS -eq $EXPECTED_PAIRS
- NUM_PAIRS=$(poetry run find-dups $IMAGE_DIR --algorithm ahash --quiet | wc -l)
- test $NUM_PAIRS -eq $EXPECTED_PAIRS
- NUM_PAIRS=$(poetry run find-dups $IMAGE_DIR --max-distance 1 --quiet | wc -l)
- test $NUM_PAIRS -eq $EXPECTED_PAIRS
- NUM_PAIRS=$(poetry run find-dups $IMAGE_DIR --hash-size 8 --quiet | wc -l)
- test $NUM_PAIRS -eq $EXPECTED_PAIRS
RunWithArgs:
extends: .test
image: python:3.12
variables:
IMAGE_DIR: tests/integration/data
HASH_DB: test.pickle
parallel:
matrix:
- ON_EQUAL: [print, quote_inline, none, d<]
ALGORITHM: [ahash, colorhash]
MODE: ["", --slow, --parallel]
script:
# ensure the script runs without any error with the given options
- poetry run find-dups
${IMAGE_DIR} --hash-db ${HASH_DB} --progress
--algorithm ${ALGORITHM}
--on-equal ${ON_EQUAL}
$MODE
# ensure the hash cache file is written
- test -f ${HASH_DB}
- ls -l ${HASH_DB}
RunWithArgsExec:
extends: RunWithArgs
parallel:
matrix:
- ON_EQUAL: [exec]
ALGORITHM: [ahash]
MODE: ["", --slow, --parallel]
script:
# ensure the script runs without any error with the given options
- poetry run find-dups
${IMAGE_DIR} --hash-db ${HASH_DB} --progress --exec "ls -l {1} {2}"
--algorithm ${ALGORITHM}
--on-equal ${ON_EQUAL}
$MODE
# ensure the hash cache file is written
- test -f ${HASH_DB}
- ls -l ${HASH_DB}
RunWithArgsExecFailure:
extends: RunWithArgs
parallel:
matrix:
- ON_EQUAL: [ "" ]
ALGORITHM: [ "" ]
MODE: [ "" ]
script:
# ensure the script fails when given --exec without --on-equal exec
- poetry run find-dups
${IMAGE_DIR} --hash-db ${HASH_DB} --progress --exec "ls -l {1} {2}" && exit 1
# ensure the script fails when given --on-equal exec without --exec
- poetry run find-dups
${IMAGE_DIR} --hash-db ${HASH_DB} --progress --on-equal exec && exit 1
- exit 0
TagIsNew:
stage: test
image: alpine:latest
rules:
- if: "$CI_MERGE_REQUEST_ID"
- if: $CI_COMMIT_BRANCH == "master"
before_script:
- apk update
- apk add git
script:
- VERSION=$(egrep 'version = ".*"' pyproject.toml | cut -d \" -f 2)
- test -n "$VERSION"
- git tag | ( ! grep "^${VERSION}\$" )
CreateTag:
stage: publish
image: alpine:latest
rules:
- if: $CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE != "schedule"
when: on_success
before_script:
- apk update
- apk add git
- git config user.email "${GITLAB_USER_EMAIL}"
- git config user.name "${GITLAB_USER_NAME}"
script:
- VERSION=$(egrep 'version = ".*"' pyproject.toml | cut -d \" -f 2)
- echo "**** Tagging release as version $VERSION"
- git remote add tag-origin https://oauth2:${GITLAB_ACCESS_TOKEN}@gitlab.com/${CI_PROJECT_PATH}
- git tag -a "${VERSION}" -m "Released $(date +%Y-%m-%d)"
- git push tag-origin "${VERSION}"
PublishToPyPI:
stage: publish
image: python:3.12
rules:
- if: "$CI_COMMIT_TAG"
when: on_success
script:
- VERSION=$(egrep 'version = ".*"' pyproject.toml | cut -d \" -f 2)
- test "${CI_COMMIT_TAG}" == "${VERSION}" || exit 1
- echo "**** Upgrading to ${VERSION}"
- pip install -q poetry
- poetry build
- poetry config repositories.testpypi https://test.pypi.org/legacy/
- poetry publish --username __token__ --password ${TESTPYPI_TOKEN} --repository testpypi
- echo "**** Attempting pip install from test PyPI server"
- apt-get -y -qq update
- apt-get -y -q install libsndfile1 ffmpeg > /dev/null
- pip install -q --index-url https://test.pypi.org/simple --extra-index-url https://pypi.org/simple duplicate_images
- echo "**** Publishing on live PyPI server"
- poetry publish --username __token__ --password ${PYPI_TOKEN}
PushToGithub:
stage: publish
image: alpine:latest
rules:
- if: "$CI_COMMIT_TAG"
when: on_success
before_script:
- apk update
- apk add openssh-client git sshpass
- eval $(ssh-agent -s)
- echo "$GITHUB_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan github.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- ssh -T git@github.com 2>&1 || true
- git config user.email "${GITLAB_USER_EMAIL}"
- git config user.name "${GITLAB_USER_NAME}"
script:
- git remote add github git@github.com:lene/DuplicateImages.git
- git remote show github
- BRANCH=${CI_COMMIT_BRANCH:-master}
- git checkout $BRANCH
- git push github $BRANCH
- git push github $CI_COMMIT_TAG
CreateGithubRelease:
stage: publish
needs:
- PushToGithub
image: alpine:latest
rules:
- if: "$CI_COMMIT_TAG"
when: on_success
before_script:
- apk update
- apk add curl
variables:
RELEASE_API_URL: "https://api.github.com/repos/lene/DuplicateImages/releases"
DESCRIPTION: "Full Changelog: https://github.com/lene/DuplicateImages/blob/${CI_COMMIT_TAG}/CHANGELOG.md"
script:
- POST_DATA='{
"tag_name":"'${CI_COMMIT_TAG}'",
"target_commitish":"master",
"name":"'${CI_COMMIT_TAG}'",
"body":"'${FULL_DESCRIPTION}${DESCRIPTION}'",
"draft":false,
"prerelease":false,
"generate_release_notes":false
}'
- echo $API_URL
- echo $POST_DATA
- 'curl -L -X POST
-H "Accept: application/vnd.github+json"
-H "X-GitHub-Api-Version: 2022-11-28"
-H "Authorization: Bearer ${GITHUB_API_TOKEN}"
${RELEASE_API_URL} -d "${POST_DATA}"'
CreateGitlabRelease:
stage: publish
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: $CI_COMMIT_TAG
script:
- echo "running release_job" # dummy, see https://gitlab.com/gitlab-org/gitlab/-/issues/223856
release:
tag_name: '$CI_COMMIT_TAG'
description: './CHANGELOG.md'