]> Untitled Git - lemmy.git/blob - .drone.yml
559986e9fdf59313ed2f391791fbf0cdb93eb572
[lemmy.git] / .drone.yml
1 ---
2 kind: pipeline
3 name: amd64
4
5 platform:
6   os: linux
7   arch: amd64
8
9 steps:
10
11   # use minimum supported rust version for most steps
12   - name: prepare repo
13     image: alpine:3
14     commands:
15       - apk add git
16       - git fetch --tags
17       - git submodule init
18       - git submodule update --recursive --remote
19
20   - name: cargo fmt
21     image: clux/muslrust:1.67.0
22     environment:
23       # store cargo data in repo folder so that it gets cached between steps
24       CARGO_HOME: .cargo
25     commands:
26       # need make existing toolchain available
27       - cp ~/.cargo . -r
28       - rustup toolchain install nightly
29       - rustup component add rustfmt --toolchain nightly
30       - cargo +nightly fmt -- --check
31
32
33   - name: cargo clippy
34     image: clux/muslrust:1.67.0
35     environment:
36       CARGO_HOME: .cargo
37     commands:
38         # latest rust for clippy to get extra checks
39         # when adding new clippy lints, make sure to also add them in scripts/fix-clippy.sh
40       - rustup component add clippy
41       - cargo clippy --workspace --tests --all-targets --all-features -- 
42           -D warnings -D deprecated -D clippy::perf -D clippy::complexity 
43           -D clippy::style -D clippy::correctness -D clippy::suspicious
44           -D clippy::dbg_macro -D clippy::inefficient_to_string 
45           -D clippy::items-after-statements -D clippy::implicit_clone 
46           -D clippy::wildcard_imports -D clippy::cast_lossless 
47           -D clippy::manual_string_new -D clippy::redundant_closure_for_method_calls 
48           -D clippy::unused_self
49           -A clippy::uninlined_format_args
50       - cargo clippy --workspace --all-features -- -D clippy::unwrap_used
51
52   - name: cargo check
53     image: clux/muslrust:1.67.0
54     environment:
55       CARGO_HOME: .cargo
56     commands:
57       - cargo check --package lemmy_utils
58       - cargo check --package lemmy_db_schema
59       - cargo check --package lemmy_db_views
60       - cargo check --package lemmy_db_views_actor
61       - cargo check --package lemmy_db_views_moderator
62       - cargo check --package lemmy_api_common
63       - cargo check --package lemmy_api
64       - cargo check --package lemmy_api_crud
65       - cargo check --package lemmy_apub
66       - cargo check --package lemmy_routes
67       - cargo check --workspace --no-default-features
68       - cargo check --workspace --all-features
69
70   - name: lemmy_api_common doesnt depend on diesel
71     image: clux/muslrust:1.67.0
72     environment:
73       CARGO_HOME: .cargo
74     commands:
75       - "! cargo tree -p lemmy_api_common --no-default-features -i diesel"
76
77   - name: check defaults.hjson updated
78     image: clux/muslrust:1.67.0
79     environment:
80       CARGO_HOME: .cargo
81     commands:
82       - export LEMMY_CONFIG_LOCATION=./config/config.hjson
83       - ./scripts/update_config_defaults.sh config/defaults_current.hjson
84       - diff config/defaults.hjson config/defaults_current.hjson
85
86   - name: cargo test
87     image: clux/muslrust:1.67.0
88     environment:
89       LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
90       RUST_BACKTRACE: 1
91       RUST_TEST_THREADS: 1
92       CARGO_HOME: .cargo
93     commands:
94       - export LEMMY_CONFIG_LOCATION=../../config/config.hjson
95       - cargo test --workspace --no-fail-fast
96
97   - name: cargo build
98     image: clux/muslrust:1.67.0
99     environment:
100       CARGO_HOME: .cargo
101     commands:
102       - cargo build
103       - mv target/x86_64-unknown-linux-musl/debug/lemmy_server target/lemmy_server
104
105   - name: run federation tests
106     image: node:alpine
107     environment:
108       LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432
109       DO_WRITE_HOSTS_FILE: 1
110     commands:
111       - apk add bash curl postgresql-client
112       - bash api_tests/prepare-drone-federation-test.sh
113       - cd api_tests/
114       - yarn
115       - yarn api-test
116
117   - name: nightly build
118     image: plugins/docker
119     settings:
120       dockerfile: docker/prod/Dockerfile
121       username:
122         from_secret: docker_username
123       password:
124         from_secret: docker_password
125       repo: dessalines/lemmy
126       add_host: github.com:140.82.112.3,static.crates.io:18.154.227.73,crates.io:108.138.64.68,dl-cdn.alpinelinux.org:146.75.30.133
127       tags:
128         - dev
129     when:
130       event:
131         - cron
132
133   - name: publish release docker image
134     image: plugins/docker
135     settings:
136       dockerfile: docker/prod/Dockerfile
137       username:
138         from_secret: docker_username
139       password:
140         from_secret: docker_password
141       repo: dessalines/lemmy
142       add_host: github.com:140.82.112.3,static.crates.io:18.154.227.73,crates.io:108.138.64.68,dl-cdn.alpinelinux.org:146.75.30.133
143       auto_tag: true
144       auto_tag_suffix: linux-amd64
145     when:
146       ref:
147         - refs/tags/*
148
149   - name: publish release docker manifest
150     image: plugins/manifest
151     settings:
152       username:
153         from_secret: docker_username
154       password:
155         from_secret: docker_password
156       target: "dessalines/lemmy:${DRONE_TAG}"
157       template: "dessalines/lemmy:${DRONE_TAG}-OS-ARCH"
158       platforms:
159         - linux/amd64
160         - linux/arm64
161       ignore_missing: true
162     when:
163       ref:
164         - refs/tags/*
165
166   - name: publish latest release docker manifest
167     image: plugins/manifest
168     settings:
169       username:
170         from_secret: docker_username
171       password:
172         from_secret: docker_password
173       target: "dessalines/lemmy:latest"
174       template: "dessalines/lemmy:${DRONE_TAG}-OS-ARCH"
175       platforms:
176         - linux/amd64
177         - linux/arm64
178       ignore_missing: true
179     when:
180       ref:
181         - refs/tags/*
182
183   # using https://github.com/pksunkara/cargo-workspaces
184   - name: publish to crates.io
185     image: clux/muslrust:1.67.0
186     environment:
187       CARGO_TOKEN:
188         from_secret: cargo_api_token
189     commands:
190       - cargo install cargo-workspaces
191       - cp -r migrations crates/db_schema/
192       - cargo login "$CARGO_TOKEN"
193       - cargo workspaces publish --from-git --allow-dirty --allow-branch "${DRONE_TAG}" --yes custom "${DRONE_TAG}"
194     when:
195       ref:
196         - refs/tags/*
197
198   - name: Notify on failure
199     image: alpine:3
200     commands: 
201       - apk add curl
202       - "curl -d'Drone build failed: ${DRONE_BUILD_LINK}' ntfy.sh/lemmy_drone_ci"
203     when:
204       status:
205         - failure
206
207 services:
208   - name: database
209     image: postgres:15-alpine
210     environment:
211       POSTGRES_USER: lemmy
212       POSTGRES_PASSWORD: password
213
214 ---
215 kind: pipeline
216 name: arm64
217
218 platform:
219   os: linux
220   arch: arm64
221
222 steps:
223
224   - name: prepare repo
225     image: rust:1.57-slim
226     user: root
227     commands:
228       - apt update
229       - apt install --no-install-recommends --yes git
230       - git fetch --tags
231       - git submodule init
232       - git submodule update --recursive --remote
233
234   # TODO temporarily disable arm tests
235   # - name: cargo test
236   #   image: rust:1.57-slim
237   #   environment:
238   #     LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
239   #     LEMMY_CONFIG_LOCATION: ../../config/config.hjson
240   #     RUST_BACKTRACE: 1
241   #     RUST_TEST_THREADS: 1
242   #   commands:
243   #     - apt-get update
244   #     - apt-get -y install --no-install-recommends postgresql-client libssl-dev pkg-config libpq-dev
245   #     - cargo test --workspace --no-fail-fast
246   #     - cargo build
247
248   # TODO temporarily disable arm tests
249   # Using Debian here because there seems to be no official Alpine-based Rust docker image for ARM.
250   # - name: cargo build
251   #   image: rust:1.57-slim
252   #   commands:
253   #     - apt-get update
254   #     - apt-get -y install --no-install-recommends libssl-dev pkg-config libpq-dev
255   #     - cargo build
256   #     - mv target/debug/lemmy_server target/lemmy_server
257
258   # TODO temporarily disable arm tests
259   # - name: run federation tests
260   #   image: node:16-slim
261   #   environment:
262   #     LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432
263   #     DO_WRITE_HOSTS_FILE: 1
264   #   commands:
265   #     - mkdir -p /usr/share/man/man1 /usr/share/man/man7
266   #     - apt-get update
267   #     - apt-get -y install --no-install-recommends bash curl libssl-dev pkg-config libpq-dev postgresql-client libc6-dev
268   #     - bash api_tests/prepare-drone-federation-test.sh
269   #     - cd api_tests/
270   #     - yarn
271   #     - yarn api-test
272
273   - name: publish release docker image
274     image: plugins/docker
275     settings:
276       dockerfile: docker/prod/Dockerfile.arm
277       username:
278         from_secret: docker_username
279       password:
280         from_secret: docker_password
281       repo: dessalines/lemmy
282       auto_tag: true
283       auto_tag_suffix: linux-arm64
284     when:
285       ref:
286         - refs/tags/*
287
288   - name: publish release docker manifest
289     image: plugins/manifest
290     settings:
291       username:
292         from_secret: docker_username
293       password:
294         from_secret: docker_password
295       target: "dessalines/lemmy:${DRONE_TAG}"
296       template: "dessalines/lemmy:${DRONE_TAG}-OS-ARCH"
297       platforms:
298         - linux/amd64
299         - linux/arm64
300       ignore_missing: true
301     when:
302       ref:
303         - refs/tags/*
304
305   - name: publish latest release docker manifest
306     image: plugins/manifest
307     settings:
308       username:
309         from_secret: docker_username
310       password:
311         from_secret: docker_password
312       target: "dessalines/lemmy:latest"
313       template: "dessalines/lemmy:${DRONE_TAG}-OS-ARCH"
314       platforms:
315         - linux/amd64
316         - linux/arm64
317       ignore_missing: true
318     when:
319       ref:
320         - refs/tags/*
321
322 # TODO temporarily disable arm tests
323 # services:
324 #   - name: database
325 #     image: postgres:12-alpine
326 #     environment:
327 #       POSTGRES_USER: lemmy
328 #       POSTGRES_PASSWORD: password