-
-
Notifications
You must be signed in to change notification settings - Fork 947
Expand file tree
/
Copy path.woodpecker.yml
More file actions
379 lines (347 loc) · 11.6 KB
/
.woodpecker.yml
File metadata and controls
379 lines (347 loc) · 11.6 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
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
# TODO: The when: platform conditionals aren't working currently
# See https://github.com/woodpecker-ci/woodpecker/issues/1677
variables:
# When updating the rust version here, be sure to update versions in `docker/Dockerfile`
# as well. Otherwise release builds can fail if Lemmy or dependencies rely on new Rust
# features. In particular the ARM builder image needs to be updated manually in the repo below:
# https://github.com/raskyld/lemmy-cross-toolchains
# Also be sure to change the version in `rust-toolchain.toml`
- &rust_image "rust:1.95"
- &rust_nightly_image "rustlang/rust:nightly"
- &install_pnpm "npm install -g corepack@latest && corepack enable pnpm"
- &install_binstall "wget -q -O- https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz | tar -xvz -C /usr/local/cargo/bin"
- &slow_check_paths
- event: pull_request
path:
include: [
# rust source code
"crates/**",
"**/Cargo.toml",
"Cargo.lock",
# database migrations
"migrations/**",
# typescript tests
"api_tests/**",
# config files and scripts used by ci
".woodpecker.yml",
".rustfmt.toml",
"scripts/update_config_defaults.sh",
"diesel.toml",
".gitmodules",
]
steps:
prepare_repo:
image: alpine:3
commands:
- apk add git
- git submodule init
- git submodule update
when:
- event: [pull_request, tag]
prettier_check:
image: jauderho/prettier:3.7.4-alpine
commands:
- prettier -c . '!**/volumes' '!**/dist' '!target' '!**/translations' '!api_tests/pnpm-lock.yaml'
when:
- event: pull_request
bash_fmt:
image: alpine:3
commands:
- apk add shfmt
- shfmt -i 2 -d */**.bash
- shfmt -i 2 -d */**.sh
when:
- event: pull_request
toml_fmt:
image: ghcr.io/shaddydc/taplo
commands:
- taplo format --check
when:
- event: pull_request
sql_fmt:
image: *rust_image
commands:
- apt-get install perl make bash
- ./scripts/alpine_install_pg_formatter.sh
- ./scripts/sql_format_check.sh
when:
- event: pull_request
cargo_fmt:
image: *rust_nightly_image
environment:
# store cargo data in repo folder so that it gets cached between steps
CARGO_HOME: .cargo_home
RUSTUP_HOME: .rustup_home
commands:
- rustup component add rustfmt --toolchain nightly
- cargo +nightly fmt -- --check
when:
- event: pull_request
cargo_shear:
image: *rust_nightly_image
commands:
- *install_binstall
- cargo binstall -y cargo-shear --disable-strategies compile
- cargo shear --deny-warnings
when:
- event: pull_request
api_tests_lint:
image: node:24-trixie-slim
commands:
- *install_pnpm
- cd api_tests/
- pnpm i
- pnpm lint
when: *slow_check_paths
ignored_files:
image: alpine:3
commands:
- apk add git
- IGNORED=$(git ls-files --cached -i --exclude-standard)
- if [[ "$IGNORED" ]]; then echo "Ignored files present:\n$IGNORED\n"; exit 1; fi
when:
- event: pull_request
no_empty_files:
image: alpine:3
commands:
# Makes sure there are no files smaller than 2 bytes
# Don't use completely empty, as some editors use newlines
- EMPTY_FILES=$(find crates migrations api_tests/src config -type f -size -2c)
- if [[ "$EMPTY_FILES" ]]; then echo "Empty files present:\n$EMPTY_FILES\n"; exit 1; fi
when:
- event: pull_request
cargo_build:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
RUSTUP_HOME: .rustup_home
commands:
- cargo build
- mv target/debug/lemmy_server target/lemmy_server
when: *slow_check_paths
# `DROP OWNED` doesn't work for default user
create_database_user:
image: pgautoupgrade/pgautoupgrade:18-alpine
environment:
PGUSER: postgres
PGPASSWORD: password
PGHOST: database
PGDATABASE: lemmy
commands:
- psql -c "CREATE USER lemmy WITH PASSWORD 'password' SUPERUSER;"
when: *slow_check_paths
cargo_clippy:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
RUSTUP_HOME: .rustup_home
commands:
- rustup component add clippy
- cargo clippy --workspace --tests --all-targets --all-features -- -D warnings
when: *slow_check_paths
cargo_test:
image: *rust_image
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: "1"
CARGO_HOME: .cargo_home
RUSTUP_HOME: .rustup_home
LEMMY_TEST_FAST_FEDERATION: "1"
LEMMY_CONFIG_LOCATION: /woodpecker/src/github.com/LemmyNet/lemmy/config/config.hjson
commands:
# Install pg_dump for the schema setup test (must match server version)
- apt update && apt install -y lsb-release
- sh -c 'echo "deb [signed-by=/usr/share/keyrings/postgres-keyring.gpg] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgres-keyring.gpg
- apt update && apt install -y postgresql-client-18
# Run tests (if they fail, try again)
- cargo test --workspace || cargo test --workspace
when: *slow_check_paths
# make sure api builds with default features (used by other crates relying on lemmy api)
check_api_common_default_features:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
RUSTUP_HOME: .rustup_home
commands:
- cargo check --package lemmy_api_common
when: *slow_check_paths
check_disallowed_dependencies:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
RUSTUP_HOME: .rustup_home
commands:
- "! cargo tree -p lemmy_api_common --no-default-features -i diesel"
- "! cargo tree -i aws-lc-sys"
when: *slow_check_paths
lemmy_api_common_works_with_wasm:
image: *rust_image
environment:
CARGO_HOME: .cargo_home
RUSTUP_HOME: .rustup_home
commands:
- "rustup target add wasm32-unknown-unknown"
- "cargo check --target wasm32-unknown-unknown -p lemmy_api_common"
when: *slow_check_paths
check_diesel_schema:
image: *rust_image
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: "1"
CARGO_HOME: .cargo_home
RUSTUP_HOME: .rustup_home
commands:
- *install_binstall
- cp crates/db_schema_file/src/schema.rs tmp.schema
- target/lemmy_server migration --all run
- apt-get update && apt-get install -y postgresql-client
- cargo binstall diesel_cli@2.3.2 -y --disable-strategies compile
- export PATH="$CARGO_HOME/bin:$PATH"
- diesel print-schema
- diff tmp.schema crates/db_schema_file/src/schema.rs
when: *slow_check_paths
run_federation_tests:
image: node:24-trixie-slim
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432
DO_WRITE_HOSTS_FILE: "1"
commands:
- *install_pnpm
- apt-get update && apt-get install -y bash curl postgresql-client
- bash api_tests/prepare-drone-federation-test.sh
- cd api_tests/
- pnpm i
# Unfortunately these tests are unstable on slower CI machines, so try it a few times.
- pnpm api-test-multiple
when: *slow_check_paths
federation_tests_server_output:
image: alpine:3
commands:
# `|| true` prevents this step from appearing to fail if the server output files don't exist
- cat target/log/lemmy_*.out || true
- "# If you can't see all output, then use the download button"
when:
- event: pull_request
status: [failure]
# Only publish arm builds on non-pre-release builds
publish_release_docker_arm64:
image: woodpeckerci/plugin-docker-buildx
settings:
repo: dessalines/lemmy
dockerfile: docker/Dockerfile
username:
from_secret: docker_username
password:
from_secret: docker_password
platforms: linux/arm64
build_args:
RUST_RELEASE_MODE: release
build_args_from_env:
- CI_PIPELINE_EVENT
tag: ${CI_COMMIT_TAG=nightly}
when:
- event: [tag, cron]
# Ensures that its a full semver release, and not a pre-release one like 1.0.0-alpha.1
evaluate: '"${CI_COMMIT_TAG}" matches ''^([0-9]\\\d*).([0-9]\\\d*).([0-9]\\\d*)$'''
# Only publish arm builds on non-pre-release builds
publish_release_docker_amd64:
image: woodpeckerci/plugin-docker-buildx
settings:
repo: dessalines/lemmy
dockerfile: docker/Dockerfile
username:
from_secret: docker_username
password:
from_secret: docker_password
platforms: linux/amd64
build_args:
RUST_RELEASE_MODE: release
build_args_from_env:
- CI_PIPELINE_EVENT
tag: ${CI_COMMIT_TAG=nightly}
when:
- event: [tag, cron]
# lemmy container doesnt run as root so we need to change permissions to let it copy the binary
chmod_for_native_binary:
image: alpine:3
commands:
- chmod 777 .
when:
- event: tag
# extract lemmy binary from newly built docker image into workspace folder
extract_native_binary:
image: dessalines/lemmy:${CI_COMMIT_TAG=default}
commands:
- cp /usr/local/bin/lemmy_server .
when:
- event: tag
prepare_native_binary:
image: alpine:3
commands:
- sha256sum lemmy_server > sha256sum.txt
- gzip lemmy_server
when:
- event: tag
# https://woodpecker-ci.org/plugins/Release
publish_native_binary:
image: woodpeckerci/plugin-release
settings:
files:
- lemmy_server.gz
- sha256sum.txt
title: ${CI_COMMIT_TAG}
prerelease: true
api-key:
from_secret: github_token
when:
- event: tag
# using https://github.com/pksunkara/cargo-workspaces
publish_to_crates_io:
image: *rust_image
environment:
CARGO_API_TOKEN:
from_secret: cargo_api_token
commands:
- *install_binstall
- cargo binstall -y cargo-workspaces@0.4.1 --disable-strategies compile
- cp -r migrations crates/db_schema/
- cargo workspaces publish --token "$CARGO_API_TOKEN" --from-git --allow-dirty --no-verify --allow-branch "${CI_COMMIT_TAG}" --yes custom "${CI_COMMIT_TAG}"
when:
- event: tag
notify_success:
image: alpine:3
commands:
- apk add curl
- "curl -H'Title: ✔️ ${CI_REPO_NAME}/${CI_COMMIT_SOURCE_BRANCH}' -d'${CI_PIPELINE_URL}' ntfy.sh/lemmy_drone_ci"
when:
- event: pull_request
status: [success]
notify_failure:
image: alpine:3
commands:
- apk add curl
- "curl -H'Title: ❌ ${CI_REPO_NAME}/${CI_COMMIT_SOURCE_BRANCH}' -d'${CI_PIPELINE_URL}' ntfy.sh/lemmy_drone_ci"
when:
- event: pull_request
status: [failure]
notify_on_tag_deploy:
image: alpine:3
commands:
- apk add curl
- "curl -H'Title: ${CI_REPO_NAME}:${CI_COMMIT_TAG} deployed' -d'${CI_PIPELINE_URL}' ntfy.sh/lemmy_drone_ci"
when:
event: tag
services:
database:
image: pgautoupgrade/pgautoupgrade:18-alpine
environment:
POSTGRES_DB: lemmy
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
when:
- event: pull_request
# Woodpecker's services ending is now causing pipeline failures:
# https://github.com/woodpecker-ci/woodpecker/issues/6372
failure: ignore