-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
.gitlab-ci.yml
412 lines (372 loc) · 14.3 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
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
image: "rust:slim"
stages:
- check
- build
- test
- package
- pre-release
- release
# Variable defaults
variables:
RUST_VERSION: stable
TARGET: x86_64-unknown-linux-gnu
APT_GTK_LIBS: libgtk-3-dev
FEATURES_CLI_UNIX: backend-gpgme,alias,clipboard,notify,select-skim,tomb,totp
FEATURES_GTK3_UNIX: backend-gpgme
FEATURES_CLI_WINDOWS: backend-gnupg-bin,clipboard,notify,select-fzf-bin,totp
# Install compiler and OpenSSL dependencies
before_script:
- apt-get update
- apt-get install -y --no-install-recommends libgpgme-dev build-essential pkg-config xorg-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev python3 libx11-xcb-dev libdbus-1-dev libgl1-mesa-dev $APT_GTK_LIBS $APT_PACKAGES
- apt-get install -y $APT_PACKAGES_RECOMMENDS
- |
rustup install $RUST_VERSION
rustup default $RUST_VERSION
- |
rustc --version
cargo --version
# Windows before script
.before_script-windows: &before_script-windows
before_script:
# Install scoop
- iex "& {$(irm get.scoop.sh)} -RunAsAdmin"
# Install Rust
- scoop install rustup
- rustup install $RUST_VERSION
- rustup default $RUST_VERSION
- rustc --version
- cargo --version
# Install missing Rust target
- rustup target add x86_64-pc-windows-msvc
# Install GPGME
- scoop install gpg
# Check on stable, beta and nightly
.check-base: &check-base
stage: check
script:
- cargo check --verbose
- cd cli; cargo check --no-default-features --features $FEATURES_CLI_UNIX --locked --verbose; cd ..
- cd gtk3; cargo check --no-default-features --features $FEATURES_GTK3_UNIX --locked --verbose; cd ..
- cd lib; cargo check --no-default-features --features backend-gpgme --locked --verbose; cd ..
- cd lib; cargo check --no-default-features --features backend-gnupg-bin --locked --verbose; cd ..
- cd cli; cargo check --no-default-features --features backend-gpgme --locked --verbose; cd ..
- cd cli; cargo check --no-default-features --features backend-gnupg-bin --locked --verbose; cd ..
- cd gtk3; cargo check --no-default-features --features backend-gpgme --locked --verbose; cd ..
- cd gtk3; cargo check --no-default-features --features backend-gnupg-bin --locked --verbose; cd ..
# check-stable:
# <<: *check-base
check-beta:
<<: *check-base
variables:
RUST_VERSION: beta
only:
- master
check-nightly:
<<: *check-base
variables:
RUST_VERSION: nightly
only:
- master
check-msrv:
<<: *check-base
variables:
RUST_VERSION: "1.81.0"
only:
- master
# Build using Rust stable on Linux
build-x86_64-linux-gnu:
stage: build
needs: []
script:
- cd cli; cargo build --target=$TARGET --release --no-default-features --features $FEATURES_CLI_UNIX --locked --verbose; cd ..
- cd gtk3; cargo build --target=$TARGET --release --no-default-features --features $FEATURES_GTK3_UNIX --locked --verbose; cd ..
- mv target/$TARGET/release/prs ./prs-$TARGET
- mv target/$TARGET/release/prs-gtk3-copy ./prs-gtk3-copy-$TARGET
- strip -g ./prs-$TARGET
- strip -g ./prs-gtk3-copy-$TARGET
artifacts:
name: prs-x86_64-linux-gnu
paths:
- prs-$TARGET
- prs-gtk3-copy-$TARGET
expire_in: 1 month
# Build a static version
build-x86_64-linux-musl:
image: alpine
stage: build
needs: []
variables:
TARGET: x86_64-unknown-linux-musl
FEATURES_CLI_UNIX: backend-gnupg-bin,alias,clipboard,notify,select-skim,tomb,totp
before_script: []
script:
- apk add rustup alpine-sdk libxcb-dev gtk+3.0-dev
- rustup-init -y --target=$TARGET
- source $HOME/.cargo/env
- cd cli; cargo build --target=$TARGET --release --no-default-features --features $FEATURES_CLI_UNIX --locked --verbose; cd ..
# Prepare the release artifact, strip it
- find . -name prs -exec ls -lah {} \;
- mv target/$TARGET/release/prs ./prs-$TARGET
- strip -g ./prs-$TARGET
artifacts:
name: prs-x86_64-linux-musl
paths:
- prs-$TARGET
expire_in: 1 month
# # Build using Rust stable on Windows
# build-x86_64-windows:
# stage: build
# tags:
# - windows
# only:
# - master
# - /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
# needs: []
# variables:
# TARGET: x86_64-pc-windows-msvc
# <<: *before_script-windows
# script:
# - cd cli; cargo build --target=$TARGET --release --no-default-features --features $FEATURES_CLI_WINDOWS --locked --verbose; cd ..
# - mv target\$env:TARGET\release\prs.exe .\prs-$env:TARGET.exe
# artifacts:
# name: prs-x86_64-windows
# paths:
# - prs-$TARGET.exe
# expire_in: 1 month
# Run the unit tests through Cargo on Linux
test-cargo-x86_64-linux-gnu:
stage: test
needs: []
dependencies: []
script:
- cargo test --locked --verbose
# # Run the unit tests through Cargo on Windows
# test-cargo-x86_64-windows:
# stage: test
# tags:
# - windows
# only:
# - master
# needs: []
# dependencies: []
# cache: {}
# <<: *before_script-windows
# script:
# - cd lib; cargo test --locked --verbose; cd ..
# - cd cli; cargo test --locked --verbose; cd ..
# Run basic integration test with prs
test-integration:
image: alpine
stage: test
needs:
- build-x86_64-linux-musl
dependencies:
- build-x86_64-linux-musl
variables:
TARGET: x86_64-unknown-linux-musl
before_script: []
script:
- apk add git gnupg gpgme
- mv ./prs-$TARGET ./prs
- git config --global user.email [email protected]
- git config --global user.name "Example User"
# TODO: add/edit/remove secrets
- ./prs help
- ./prs init
- ./prs sync init
- ./prs list
- ./prs sync
# Package a Docker image
package-docker:
image: docker:latest
stage: package
needs:
- build-x86_64-linux-musl
dependencies:
- build-x86_64-linux-musl
services:
- docker:dind
only:
- master
- /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
variables:
TARGET: x86_64-unknown-linux-musl
IMAGE_NAME: prs:$CI_COMMIT_SHA
DOCKER_HOST: tcp://docker:2375
# DOCKER_DRIVER: overlay2
before_script: []
script:
- ls -al
# Place binary in Docker directory
- mv ./prs-$TARGET ./pkg/docker/prs
# Build the Docker image, run it once to test
- cd ./pkg/docker
- docker build -t $IMAGE_NAME ./
- docker run --rm $IMAGE_NAME -V
- cd ../..
# Export image as artifact
- docker image save -o ./prs-docker-$TARGET.tar $IMAGE_NAME
artifacts:
name: prs-docker-x86_64-linux-musl
paths:
- prs-docker-$TARGET.tar
expire_in: 1 month
# Release binaries on GitLab as generic package
release-gitlab-generic-package:
image: curlimages/curl
stage: pre-release
dependencies:
- build-x86_64-linux-gnu
- build-x86_64-linux-musl
# - build-x86_64-windows
only:
- /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
variables:
LINUX_GNU_BIN: "prs-x86_64-unknown-linux-gnu"
LINUX_GNU_BIN_GTK_COPY: "prs-gtk3-copy-x86_64-unknown-linux-gnu"
LINUX_MUSL_BIN: "prs-x86_64-unknown-linux-musl"
# WINDOWS_BIN: "prs-x86_64-pc-windows-msvc.exe"
before_script: []
script:
# Get version based on tag, determine registry URL
- VERSION=$(echo $CI_COMMIT_REF_NAME | cut -c 2-)
- PACKAGE_REGISTRY_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/prs/${VERSION}"
# Publish packages
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${LINUX_GNU_BIN} ${PACKAGE_REGISTRY_URL}/${LINUX_GNU_BIN}
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${LINUX_GNU_BIN_GTK_COPY} ${PACKAGE_REGISTRY_URL}/${LINUX_GNU_BIN_GTK_COPY}
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${LINUX_MUSL_BIN} ${PACKAGE_REGISTRY_URL}/${LINUX_MUSL_BIN}
# - |
# curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${WINDOWS_BIN} ${PACKAGE_REGISTRY_URL}/${WINDOWS_BIN}
# Publish GitLab release
release-gitlab-release:
image: registry.gitlab.com/gitlab-org/release-cli
stage: release
only:
- /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
variables:
LINUX_GNU_BIN: "prs-x86_64-unknown-linux-gnu"
LINUX_GNU_BIN_GTK_COPY: "prs-gtk3-copy-x86_64-unknown-linux-gnu"
LINUX_MUSL_BIN: "prs-x86_64-unknown-linux-musl"
# WINDOWS_BIN: "prs-x86_64-pc-windows-msvc.exe"
before_script: []
script:
# Get version based on tag, determine registry URL
- VERSION=$(echo $CI_COMMIT_REF_NAME | cut -c 2-)
- PACKAGE_REGISTRY_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/prs/${VERSION}"
# Publish release
- |
release-cli create --name "prs $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG \
--assets-link "{\"name\":\"${LINUX_GNU_BIN}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${LINUX_GNU_BIN}\"}" \
--assets-link "{\"name\":\"${LINUX_GNU_BIN_GTK_COPY}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${LINUX_GNU_BIN_GTK_COPY}\"}" \
--assets-link "{\"name\":\"${LINUX_MUSL_BIN}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${LINUX_MUSL_BIN}\"}"
# --assets-link "{\"name\":\"${WINDOWS_BIN}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${WINDOWS_BIN}\"}"
# Publish GitHub release
release-github:
stage: release
only:
- /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
dependencies:
- build-x86_64-linux-gnu
- build-x86_64-linux-musl
# - build-x86_64-windows
before_script: []
script:
# Install dependencies
- apt-get update
- apt-get install -y curl wget gzip netbase
# Download github-release binary
- wget https://github.com/tfausak/github-release/releases/download/1.2.5/github-release-linux.gz -O github-release.gz
- gunzip github-release.gz
- chmod a+x ./github-release
# Create the release, upload binaries
- ./github-release release --token "$GITHUB_TOKEN" --owner timvisee --repo prs --tag "$CI_COMMIT_REF_NAME" --title "prs $CI_COMMIT_REF_NAME"
- ./github-release upload --token "$GITHUB_TOKEN" --owner timvisee --repo prs --tag "$CI_COMMIT_REF_NAME" --file ./prs-x86_64-unknown-linux-gnu --name prs-$CI_COMMIT_REF_NAME-linux-x64
- ./github-release upload --token "$GITHUB_TOKEN" --owner timvisee --repo prs --tag "$CI_COMMIT_REF_NAME" --file ./prs-gtk3-copy-x86_64-unknown-linux-gnu --name prs-gtk3-copy-$CI_COMMIT_REF_NAME-linux-x64
- ./github-release upload --token "$GITHUB_TOKEN" --owner timvisee --repo prs --tag "$CI_COMMIT_REF_NAME" --file ./prs-x86_64-unknown-linux-musl --name prs-$CI_COMMIT_REF_NAME-linux-x64-static
# - ./github-release upload --token "$GITHUB_TOKEN" --owner timvisee --repo prs --tag "$CI_COMMIT_REF_NAME" --file ./prs-x86_64-pc-windows-msvc.exe --name prs-$CI_COMMIT_REF_NAME-windows.exe
# Cargo crate release
release-crate:
stage: release
dependencies: []
only:
- /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
before_script: []
script:
- echo "Creating release crate to publish on crates.io..."
- echo $CARGO_TOKEN | cargo login
- echo "Publishing crates to crates.io..."
- cd lib; cargo publish --allow-dirty --no-verify --locked --verbose ; cd ..
# Give package index some time to sync
- sleep 60
- cd cli; cargo publish --allow-dirty --no-verify --locked --verbose; cd ..
- cd gtk3; cargo publish --allow-dirty --no-verify --locked --verbose; cd ..
# Publish Docker image on repository registry
release-docker:
image: docker:latest
stage: release
only:
- /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
dependencies:
- package-docker
services:
- docker:dind
variables:
TARGET: x86_64-unknown-linux-musl
DOCKER_HOST: tcp://docker:2375
IMAGE_NAME: prs:$CI_COMMIT_SHA
# DOCKER_DRIVER: overlay2
before_script: []
script:
# Import Docker image
- docker image load -i ./prs-docker-$TARGET.tar
# Retag version
- VERSION=$(echo $CI_COMMIT_REF_NAME | cut -c 2-)
- echo "Determined Docker image version number 'v$VERSION', retagging image..."
- docker tag $IMAGE_NAME registry.gitlab.com/timvisee/prs:$VERSION
- docker tag $IMAGE_NAME registry.gitlab.com/timvisee/prs:latest
# Authenticate and push the Docker images
- 'docker login registry.gitlab.com -u $DOCKER_USER -p $DOCKER_PASS'
- docker push registry.gitlab.com/timvisee/prs:$VERSION
- docker push registry.gitlab.com/timvisee/prs:latest
# Publish Docker image on Docker hub
release-docker-hub:
image: docker:latest
stage: release
only:
- /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
dependencies:
- package-docker
services:
- docker:dind
variables:
TARGET: x86_64-unknown-linux-musl
DOCKER_HOST: tcp://docker:2375
IMAGE_NAME: prs:$CI_COMMIT_SHA
# DOCKER_DRIVER: overlay2
before_script: []
script:
# Import Docker image
- docker image load -i ./prs-docker-$TARGET.tar
# Retag version
- VERSION=$(echo $CI_COMMIT_REF_NAME | cut -c 2-)
- echo "Determined Docker image version number 'v$VERSION', retagging image..."
- docker tag $IMAGE_NAME timvisee/prs:$VERSION
- docker tag $IMAGE_NAME timvisee/prs:latest
# Authenticate and push the Docker images
- echo "$DOCKER_HUB_PASS" | docker login -u "$DOCKER_HUB_USER" --password-stdin
- docker push timvisee/prs:$VERSION
- docker push timvisee/prs:latest
# AUR packages release
release-aur:
image: archlinux
stage: release
only:
- /^v(\d+\.)*\d+$/
timeout: 1h 30m
before_script: []
script:
- cd ./pkg/aur
- ./publish