]> Untitled Git - lemmy.git/blob - .drone.yml
Merge pull request #2263 from LemmyNet/fix-ci-unsafe-repo
[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   - name: prepare repo
12     image: clux/muslrust:1.59.0
13     user: root
14     commands:
15       - git fetch --tags
16       - git submodule init
17       - git submodule update --recursive --remote
18       - chown 1000:1000 . -R
19
20   - name: check formatting
21     image: rustdocker/rust:nightly
22     commands:
23       - /root/.cargo/bin/cargo fmt -- --check
24
25   - name: check with different features
26     image: clux/muslrust:1.59.0
27     commands:
28       # api with minimal deps
29       - cargo check -p lemmy_api_common
30       # opentelemetry console
31       - cargo check --features console
32       # default features
33       - cargo check
34
35   - name: cargo clippy
36     image: clux/muslrust:1.59.0
37     commands:
38       - rustup component add clippy
39       - cargo clippy --workspace --tests --all-targets --all-features -- -D warnings -D deprecated -D clippy::perf -D clippy::complexity -D clippy::dbg_macro
40       - cargo clippy --workspace -- -D clippy::unwrap_used
41
42   - name: cargo test
43     image: clux/muslrust:1.59.0
44     environment:
45       LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
46       LEMMY_CONFIG_LOCATION: ../../config/config.hjson
47       RUST_BACKTRACE: 1
48       RUST_TEST_THREADS: 1
49     commands:
50       - apt-get update
51       - apt-get -y install --no-install-recommends postgresql-client
52       - cargo test --workspace --no-fail-fast
53
54   - name: check defaults.hjson updated
55     image: clux/muslrust:1.59.0
56     commands:
57       - ./scripts/update_config_defaults.sh config/defaults_current.hjson
58       - diff config/defaults.hjson config/defaults_current.hjson
59
60   - name: cargo build
61     image: clux/muslrust:1.59.0
62     commands:
63       - cargo build
64       - mv target/x86_64-unknown-linux-musl/debug/lemmy_server target/lemmy_server
65
66   - name: run federation tests
67     image: node:alpine
68     environment:
69       LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432
70       DO_WRITE_HOSTS_FILE: 1
71     commands:
72       - apk add bash curl postgresql-client
73       - bash api_tests/prepare-drone-federation-test.sh
74       - cd api_tests/
75       - yarn
76       - yarn api-test
77
78   - name: publish release docker image
79     image: plugins/docker
80     settings:
81       dockerfile: docker/prod/Dockerfile
82       username:
83         from_secret: docker_username
84       password:
85         from_secret: docker_password
86       repo: dessalines/lemmy
87       auto_tag: true
88       auto_tag_suffix: linux-amd64
89     when:
90       ref:
91         - refs/tags/*
92
93   - name: publish release docker manifest
94     image: plugins/manifest
95     settings:
96       username:
97         from_secret: docker_username
98       password:
99         from_secret: docker_password
100       target: "dessalines/lemmy:${DRONE_TAG}"
101       template: "dessalines/lemmy:${DRONE_TAG}-OS-ARCH"
102       platforms:
103         - linux/amd64
104         - linux/arm64
105       ignore_missing: true
106     when:
107       ref:
108         - refs/tags/*
109
110   - name: publish latest release docker manifest
111     image: plugins/manifest
112     settings:
113       username:
114         from_secret: docker_username
115       password:
116         from_secret: docker_password
117       target: "dessalines/lemmy:latest"
118       template: "dessalines/lemmy:${DRONE_TAG}-OS-ARCH"
119       platforms:
120         - linux/amd64
121         - linux/arm64
122       ignore_missing: true
123     when:
124       ref:
125         - refs/tags/*
126
127   # using https://github.com/pksunkara/cargo-workspaces
128   - name: publish to crates.io
129     image: rustlang/rust:nightly
130     environment:
131       CARGO_TOKEN:
132         from_secret: cargo_api_token
133     commands:
134       - cargo install cargo-workspaces
135       - cp -r migrations crates/db_schema/
136       - cargo login "$CARGO_TOKEN"
137       - cargo workspaces publish --from-git --allow-dirty --allow-branch "${DRONE_TAG}" --yes custom "${DRONE_TAG}"
138     when:
139       ref:
140         - refs/tags/*
141
142 services:
143   - name: database
144     image: postgres:12-alpine
145     environment:
146       POSTGRES_USER: lemmy
147       POSTGRES_PASSWORD: password
148
149 ---
150 kind: pipeline
151 name: arm64
152
153 platform:
154   os: linux
155   arch: arm64
156
157 steps:
158
159   - name: prepare repo
160     image: rust:1.60-slim
161     user: root
162     commands:
163       - chown 1000:1000 . -R
164       - apt update
165       - apt install --no-install-recommends --yes git
166       - git fetch --tags
167       - git submodule init
168       - git submodule update --recursive --remote
169
170   # TODO temporarily disable arm tests
171   # - name: cargo test
172   #   image: rust:1.60-slim
173   #   environment:
174   #     LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
175   #     LEMMY_CONFIG_LOCATION: ../../config/config.hjson
176   #     RUST_BACKTRACE: 1
177   #     RUST_TEST_THREADS: 1
178   #   commands:
179   #     - apt-get update
180   #     - apt-get -y install --no-install-recommends postgresql-client libssl-dev pkg-config libpq-dev
181   #     - cargo test --workspace --no-fail-fast
182   #     - cargo build
183
184   # TODO temporarily disable arm tests
185   # Using Debian here because there seems to be no official Alpine-based Rust docker image for ARM.
186   # - name: cargo build
187   #   image: rust:1.60-slim
188   #   commands:
189   #     - apt-get update
190   #     - apt-get -y install --no-install-recommends libssl-dev pkg-config libpq-dev
191   #     - cargo build
192   #     - mv target/debug/lemmy_server target/lemmy_server
193
194   # TODO temporarily disable arm tests
195   # - name: run federation tests
196   #   image: node:16-slim
197   #   environment:
198   #     LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432
199   #     DO_WRITE_HOSTS_FILE: 1
200   #   commands:
201   #     - mkdir -p /usr/share/man/man1 /usr/share/man/man7
202   #     - apt-get update
203   #     - apt-get -y install --no-install-recommends bash curl libssl-dev pkg-config libpq-dev postgresql-client libc6-dev
204   #     - bash api_tests/prepare-drone-federation-test.sh
205   #     - cd api_tests/
206   #     - yarn
207   #     - yarn api-test
208
209   - name: publish release docker image
210     image: plugins/docker
211     settings:
212       dockerfile: docker/prod/Dockerfile.arm
213       username:
214         from_secret: docker_username
215       password:
216         from_secret: docker_password
217       repo: dessalines/lemmy
218       auto_tag: true
219       auto_tag_suffix: linux-arm64
220     when:
221       ref:
222         - refs/tags/*
223
224   - name: publish release docker manifest
225     image: plugins/manifest
226     settings:
227       username:
228         from_secret: docker_username
229       password:
230         from_secret: docker_password
231       target: "dessalines/lemmy:${DRONE_TAG}"
232       template: "dessalines/lemmy:${DRONE_TAG}-OS-ARCH"
233       platforms:
234         - linux/amd64
235         - linux/arm64
236       ignore_missing: true
237     when:
238       ref:
239         - refs/tags/*
240
241   - name: publish latest release docker manifest
242     image: plugins/manifest
243     settings:
244       username:
245         from_secret: docker_username
246       password:
247         from_secret: docker_password
248       target: "dessalines/lemmy:latest"
249       template: "dessalines/lemmy:${DRONE_TAG}-OS-ARCH"
250       platforms:
251         - linux/amd64
252         - linux/arm64
253       ignore_missing: true
254     when:
255       ref:
256         - refs/tags/*
257
258 # TODO temporarily disable arm tests
259 # services:
260 #   - name: database
261 #     image: postgres:12-alpine
262 #     environment:
263 #       POSTGRES_USER: lemmy
264 #       POSTGRES_PASSWORD: password