]> Untitled Git - lemmy.git/blob - .woodpecker.yml
Revert "Attempt to fix CI building wrong commits (#3830)"
[lemmy.git] / .woodpecker.yml
1 # TODO: The when: platform conditionals aren't working currently
2 # See https://github.com/woodpecker-ci/woodpecker/issues/1677
3
4 variables:
5   - &muslrust_image "clux/muslrust:1.70.0"
6   - &slow_check_paths
7     - path:
8         # rust source code
9         - "**/*.rs"
10         - "**/Cargo.toml"
11         - "Cargo.lock"
12         # database migrations
13         - "migrations"
14         # typescript tests
15         - "api_tests"
16         # config files and scripts used by ci
17         - ".woodpecker.yml"
18         - ".rustfmt.toml"
19         - "scripts/update_config_defaults.sh"
20         - "diesel.toml"
21         - ".gitmodules"
22
23 # Broken for cron jobs currently, see
24 # https://github.com/woodpecker-ci/woodpecker/issues/1716
25 # clone:
26 #   git:
27 #     image: woodpeckerci/plugin-git
28 #     settings:
29 #       recursive: true
30 #       submodule_update_remote: true
31
32 pipeline:
33   prepare_repo:
34     image: alpine:3
35     commands:
36       - apk add git
37       - git submodule init
38       - git submodule update
39
40   prettier_check:
41     image: tmknom/prettier:3.0.0
42     commands:
43       - prettier -c . '!**/volumes' '!**/dist' '!target' '!**/translations'
44
45   restore-cache:
46     image: meltwater/drone-cache:v1
47     pull: true
48     settings:
49       restore: true
50       endpoint:
51         from_secret: MINIO_ENDPOINT
52       access-key:
53         from_secret: MINIO_WRITE_USER
54       secret-key:
55         from_secret: MINIO_WRITE_PASSWORD
56       bucket:
57         from_secret: MINIO_BUCKET
58       region: us-east-1
59       cache_key: "rust-cache"
60       path-style: true
61       mount:
62         - ".cargo"
63         - "target"
64         - "api_tests/node_modules"
65     secrets:
66       [MINIO_ENDPOINT, MINIO_WRITE_USER, MINIO_WRITE_PASSWORD, MINIO_BUCKET]
67     when: *slow_check_paths
68
69   toml_fmt:
70     image: tamasfe/taplo:0.8.1
71     commands:
72       - taplo format --check
73
74   cargo_fmt:
75     image: *muslrust_image
76     environment:
77       # store cargo data in repo folder so that it gets cached between steps
78       CARGO_HOME: .cargo
79     commands:
80       # need make existing toolchain available
81       - cp -n ~/.cargo . -r
82       - rustup toolchain install nightly-2023-07-10
83       - rustup component add rustfmt --toolchain nightly-2023-07-10
84       - cargo +nightly-2023-07-10 fmt -- --check
85
86   sql_fmt:
87     image: alpine:3
88     commands:
89       - apk add bash wget perl make git
90       - wget https://github.com/darold/pgFormatter/archive/refs/tags/v5.5.tar.gz
91       - tar xzf v5.5.tar.gz
92       - cd pgFormatter-5.5
93       - perl Makefile.PL
94       - make && make install
95       - cd ..
96       - ./scripts/./sql_format_check.sh
97
98   # make sure api builds with default features (used by other crates relying on lemmy api)
99   check_api_common_default_features:
100     image: *muslrust_image
101     environment:
102       CARGO_HOME: .cargo
103     commands:
104       - cargo check --package lemmy_api_common
105     when: *slow_check_paths
106
107   lemmy_api_common_doesnt_depend_on_diesel:
108     image: *muslrust_image
109     environment:
110       CARGO_HOME: .cargo
111     commands:
112       - "! cargo tree -p lemmy_api_common --no-default-features -i diesel"
113     when: *slow_check_paths
114
115   lemmy_api_common_works_with_wasm:
116     image: *muslrust_image
117     environment:
118       CARGO_HOME: .cargo
119     commands:
120       - "rustup target add wasm32-unknown-unknown"
121       - "cargo check --target wasm32-unknown-unknown -p lemmy_api_common"
122     when: *slow_check_paths
123
124   check_defaults_hjson_updated:
125     image: *muslrust_image
126     environment:
127       CARGO_HOME: .cargo
128     commands:
129       - export LEMMY_CONFIG_LOCATION=./config/config.hjson
130       - ./scripts/update_config_defaults.sh config/defaults_current.hjson
131       - diff config/defaults.hjson config/defaults_current.hjson
132     when: *slow_check_paths
133
134   check_diesel_schema:
135     image: willsquire/diesel-cli
136     environment:
137       CARGO_HOME: .cargo
138       DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
139     commands:
140       - diesel migration run
141       - diesel print-schema --config-file=diesel.toml > tmp.schema
142       - diff tmp.schema crates/db_schema/src/schema.rs
143     when: *slow_check_paths
144
145   check_diesel_migration_revertable:
146     image: willsquire/diesel-cli
147     environment:
148       CARGO_HOME: .cargo
149       DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
150     commands:
151       - diesel migration run
152       - diesel migration redo
153     when: *slow_check_paths
154
155   cargo_clippy:
156     image: *muslrust_image
157     environment:
158       CARGO_HOME: .cargo
159     commands:
160       # when adding new clippy lints, make sure to also add them in scripts/lint.sh
161       - rustup component add clippy
162       - cargo clippy --workspace --tests --all-targets --features console --
163         -D warnings -D deprecated -D clippy::perf -D clippy::complexity
164         -D clippy::style -D clippy::correctness -D clippy::suspicious
165         -D clippy::dbg_macro -D clippy::inefficient_to_string
166         -D clippy::items-after-statements -D clippy::implicit_clone
167         -D clippy::cast_lossless -D clippy::manual_string_new
168         -D clippy::redundant_closure_for_method_calls
169         -D clippy::unused_self
170         -A clippy::uninlined_format_args
171         -D clippy::get_first
172         -D clippy::explicit_into_iter_loop
173         -D clippy::explicit_iter_loop
174         -D clippy::needless_collect
175         -D clippy::unwrap_used
176         -D clippy::indexing_slicing
177     when: *slow_check_paths
178
179   cargo_test:
180     image: *muslrust_image
181     environment:
182       LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
183       RUST_BACKTRACE: "1"
184       CARGO_HOME: .cargo
185     commands:
186       - export LEMMY_CONFIG_LOCATION=../../config/config.hjson
187       - cargo test --workspace --no-fail-fast
188     when: *slow_check_paths
189
190   cargo_build:
191     image: *muslrust_image
192     environment:
193       CARGO_HOME: .cargo
194     commands:
195       - cargo build
196       - mv target/x86_64-unknown-linux-musl/debug/lemmy_server target/lemmy_server
197     when: *slow_check_paths
198
199   run_federation_tests:
200     image: node:alpine
201     environment:
202       LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432
203       DO_WRITE_HOSTS_FILE: "1"
204     commands:
205       - apk add bash curl postgresql-client
206       - bash api_tests/prepare-drone-federation-test.sh
207       - cd api_tests/
208       - yarn
209       - yarn api-test
210     when: *slow_check_paths
211
212   rebuild-cache:
213     image: meltwater/drone-cache:v1
214     pull: true
215     settings:
216       rebuild: true
217       endpoint:
218         from_secret: MINIO_ENDPOINT
219       access-key:
220         from_secret: MINIO_WRITE_USER
221       secret-key:
222         from_secret: MINIO_WRITE_PASSWORD
223       bucket:
224         from_secret: MINIO_BUCKET
225       cache_key: "rust-cache"
226       region: us-east-1
227       path-style: true
228       mount:
229         - ".cargo"
230         - "target"
231         - "api_tests/node_modules"
232     secrets:
233       [MINIO_ENDPOINT, MINIO_WRITE_USER, MINIO_WRITE_PASSWORD, MINIO_BUCKET]
234     when: *slow_check_paths
235
236   publish_release_docker:
237     image: woodpeckerci/plugin-docker-buildx
238     secrets: [docker_username, docker_password]
239     settings:
240       repo: dessalines/lemmy
241       dockerfile: docker/Dockerfile
242       platforms: linux/amd64
243       build_args:
244         - RUST_RELEASE_MODE=release
245       auto_tag: true
246     when:
247       event: tag
248
249   nightly_build:
250     image: woodpeckerci/plugin-docker-buildx
251     secrets: [docker_username, docker_password]
252     settings:
253       repo: dessalines/lemmy
254       dockerfile: docker/Dockerfile
255       platforms: linux/amd64
256       build_args:
257         - RUST_RELEASE_MODE=release
258       tag: dev
259     when:
260       event: cron
261
262   notify_on_failure:
263     image: alpine:3
264     commands:
265       - apk add curl
266       - "curl -d'Lemmy CI build failed: ${CI_BUILD_LINK}' ntfy.sh/lemmy_drone_ci"
267     when:
268       status: [failure]
269
270   notify_on_tag_deploy:
271     image: alpine:3
272     commands:
273       - apk add curl
274       - "curl -d'lemmy:${CI_COMMIT_TAG} deployed' ntfy.sh/lemmy_drone_ci"
275     when:
276       event: tag
277
278 services:
279   database:
280     image: postgres:15.2-alpine
281     environment:
282       POSTGRES_USER: lemmy
283       POSTGRES_PASSWORD: password