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