.woodpecker.yml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. # TODO: The when: platform conditionals aren't working currently
  2. # See https://github.com/woodpecker-ci/woodpecker/issues/1677
  3. variables:
  4. - &rust_image "rust:1.77"
  5. - &install_pnpm "corepack enable pnpm"
  6. - &slow_check_paths
  7. - event: pull_request
  8. path:
  9. include: [
  10. # rust source code
  11. "crates/**",
  12. "src/**",
  13. "**/Cargo.toml",
  14. "Cargo.lock",
  15. # database migrations
  16. "migrations/**",
  17. # typescript tests
  18. "api_tests/**",
  19. # config files and scripts used by ci
  20. ".woodpecker.yml",
  21. ".rustfmt.toml",
  22. "scripts/update_config_defaults.sh",
  23. "diesel.toml",
  24. ".gitmodules",
  25. ]
  26. # Broken for cron jobs currently, see
  27. # https://github.com/woodpecker-ci/woodpecker/issues/1716
  28. # clone:
  29. # git:
  30. # image: woodpeckerci/plugin-git
  31. # settings:
  32. # recursive: true
  33. # submodule_update_remote: true
  34. steps:
  35. prepare_repo:
  36. image: alpine:3
  37. commands:
  38. - apk add git
  39. - git submodule init
  40. - git submodule update
  41. when:
  42. - event: [pull_request, tag]
  43. prettier_check:
  44. image: tmknom/prettier:3.0.0
  45. commands:
  46. - prettier -c . '!**/volumes' '!**/dist' '!target' '!**/translations' '!api_tests/pnpm-lock.yaml'
  47. when:
  48. - event: pull_request
  49. toml_fmt:
  50. image: tamasfe/taplo:0.8.1
  51. commands:
  52. - taplo format --check
  53. when:
  54. - event: pull_request
  55. sql_fmt:
  56. image: backplane/pgformatter
  57. commands:
  58. - ./scripts/sql_format_check.sh
  59. when:
  60. - event: pull_request
  61. cargo_fmt:
  62. image: rustlang/rust:nightly
  63. environment:
  64. # store cargo data in repo folder so that it gets cached between steps
  65. CARGO_HOME: .cargo_home
  66. commands:
  67. - rustup component add rustfmt
  68. - cargo +nightly fmt -- --check
  69. when:
  70. - event: pull_request
  71. cargo_machete:
  72. image: rustlang/rust:nightly
  73. commands:
  74. - wget https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz
  75. - tar -xvf cargo-binstall-x86_64-unknown-linux-musl.tgz
  76. - cp cargo-binstall /usr/local/cargo/bin
  77. - cargo binstall -y cargo-machete
  78. - cargo machete
  79. when:
  80. - event: pull_request
  81. ignored_files:
  82. image: alpine:3
  83. commands:
  84. - apk add git
  85. - IGNORED=$(git ls-files --cached -i --exclude-standard)
  86. - if [[ "$IGNORED" ]]; then echo "Ignored files present:\n$IGNORED\n"; exit 1; fi
  87. when:
  88. - event: pull_request
  89. # make sure api builds with default features (used by other crates relying on lemmy api)
  90. check_api_common_default_features:
  91. image: *rust_image
  92. environment:
  93. CARGO_HOME: .cargo_home
  94. commands:
  95. - cargo check --package lemmy_api_common
  96. when: *slow_check_paths
  97. lemmy_api_common_doesnt_depend_on_diesel:
  98. image: *rust_image
  99. environment:
  100. CARGO_HOME: .cargo_home
  101. commands:
  102. - "! cargo tree -p lemmy_api_common --no-default-features -i diesel"
  103. when: *slow_check_paths
  104. lemmy_api_common_works_with_wasm:
  105. image: *rust_image
  106. environment:
  107. CARGO_HOME: .cargo_home
  108. commands:
  109. - "rustup target add wasm32-unknown-unknown"
  110. - "cargo check --target wasm32-unknown-unknown -p lemmy_api_common"
  111. when: *slow_check_paths
  112. check_defaults_hjson_updated:
  113. image: *rust_image
  114. environment:
  115. CARGO_HOME: .cargo_home
  116. commands:
  117. - export LEMMY_CONFIG_LOCATION=./config/config.hjson
  118. - ./scripts/update_config_defaults.sh config/defaults_current.hjson
  119. - diff config/defaults.hjson config/defaults_current.hjson
  120. when: *slow_check_paths
  121. check_diesel_schema:
  122. image: willsquire/diesel-cli
  123. environment:
  124. CARGO_HOME: .cargo_home
  125. DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
  126. commands:
  127. - diesel migration run
  128. - diesel print-schema --config-file=diesel.toml > tmp.schema
  129. - diff tmp.schema crates/db_schema/src/schema.rs
  130. when: *slow_check_paths
  131. check_db_perf_tool:
  132. image: *rust_image
  133. environment:
  134. LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
  135. RUST_BACKTRACE: "1"
  136. CARGO_HOME: .cargo_home
  137. commands:
  138. # same as scripts/db_perf.sh but without creating a new database server
  139. - export LEMMY_CONFIG_LOCATION=config/config.hjson
  140. - cargo run --package lemmy_db_perf -- --posts 10 --read-post-pages 1
  141. when: *slow_check_paths
  142. cargo_clippy:
  143. image: *rust_image
  144. environment:
  145. CARGO_HOME: .cargo_home
  146. commands:
  147. - rustup component add clippy
  148. - cargo clippy --workspace --tests --all-targets --features console -- -D warnings
  149. when: *slow_check_paths
  150. cargo_build:
  151. image: *rust_image
  152. environment:
  153. CARGO_HOME: .cargo_home
  154. commands:
  155. - cargo build
  156. - mv target/debug/lemmy_server target/lemmy_server
  157. when: *slow_check_paths
  158. cargo_test:
  159. image: *rust_image
  160. environment:
  161. LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
  162. RUST_BACKTRACE: "1"
  163. CARGO_HOME: .cargo_home
  164. commands:
  165. - export LEMMY_CONFIG_LOCATION=../../config/config.hjson
  166. - cargo test --workspace --no-fail-fast
  167. when: *slow_check_paths
  168. check_diesel_migration:
  169. # TODO: use willsquire/diesel-cli image when shared libraries become optional in lemmy_server
  170. image: *rust_image
  171. environment:
  172. LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
  173. RUST_BACKTRACE: "1"
  174. CARGO_HOME: .cargo_home
  175. DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
  176. PGUSER: lemmy
  177. PGPASSWORD: password
  178. PGHOST: database
  179. PGDATABASE: lemmy
  180. commands:
  181. - cargo install diesel_cli
  182. - export PATH="$CARGO_HOME/bin:$PATH"
  183. # Run all migrations
  184. - diesel migration run
  185. # Dump schema to before.sqldump (PostgreSQL apt repo is used to prevent pg_dump version mismatch error)
  186. - apt update && apt install -y lsb-release
  187. - sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
  188. - wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
  189. - apt update && apt install -y postgresql-client-16
  190. - psql -c "DROP SCHEMA IF EXISTS r CASCADE;"
  191. - pg_dump --no-owner --no-privileges --no-table-access-method --schema-only --no-sync -f before.sqldump
  192. # Make sure that the newest migration is revertable without the `r` schema
  193. - diesel migration redo
  194. # Run schema setup twice, which fails on the 2nd time if `DROP SCHEMA IF EXISTS r CASCADE` drops the wrong things
  195. - alias lemmy_schema_setup="target/lemmy_server --disable-scheduled-tasks --disable-http-server --disable-activity-sending"
  196. - lemmy_schema_setup
  197. - lemmy_schema_setup
  198. # Make sure that the newest migration is revertable with the `r` schema
  199. - diesel migration redo
  200. # Check for changes in the schema, which would be caused by an incorrect migration
  201. - psql -c "DROP SCHEMA IF EXISTS r CASCADE;"
  202. - pg_dump --no-owner --no-privileges --no-table-access-method --schema-only --no-sync -f after.sqldump
  203. - diff before.sqldump after.sqldump
  204. when: *slow_check_paths
  205. run_federation_tests:
  206. image: node:20-bookworm-slim
  207. environment:
  208. LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432
  209. DO_WRITE_HOSTS_FILE: "1"
  210. commands:
  211. - *install_pnpm
  212. - apt update && apt install -y bash curl postgresql-client
  213. - bash api_tests/prepare-drone-federation-test.sh
  214. - cd api_tests/
  215. - pnpm i
  216. - pnpm api-test
  217. when: *slow_check_paths
  218. federation_tests_server_output:
  219. image: alpine:3
  220. commands:
  221. # `|| true` prevents this step from appearing to fail if the server output files don't exist
  222. - cat target/log/lemmy_*.out || true
  223. - "# If you can't see all output, then use the download button"
  224. when:
  225. - event: pull_request
  226. status: failure
  227. publish_release_docker:
  228. image: woodpeckerci/plugin-docker-buildx
  229. secrets: [docker_username, docker_password]
  230. settings:
  231. repo: dessalines/lemmy
  232. dockerfile: docker/Dockerfile
  233. platforms: linux/amd64, linux/arm64
  234. build_args:
  235. - RUST_RELEASE_MODE=release
  236. tag: ${CI_COMMIT_TAG}
  237. when:
  238. - event: tag
  239. nightly_build:
  240. image: woodpeckerci/plugin-docker-buildx
  241. secrets: [docker_username, docker_password]
  242. settings:
  243. repo: dessalines/lemmy
  244. dockerfile: docker/Dockerfile
  245. platforms: linux/amd64,linux/arm64
  246. build_args:
  247. - RUST_RELEASE_MODE=release
  248. tag: dev
  249. when:
  250. - event: cron
  251. # using https://github.com/pksunkara/cargo-workspaces
  252. publish_to_crates_io:
  253. image: *rust_image
  254. commands:
  255. - cargo install cargo-workspaces
  256. - cp -r migrations crates/db_schema/
  257. - cargo workspaces publish --token "$CARGO_API_TOKEN" --from-git --allow-dirty --no-verify --allow-branch "${CI_COMMIT_TAG}" --yes custom "${CI_COMMIT_TAG}"
  258. secrets: [cargo_api_token]
  259. when:
  260. - event: tag
  261. notify_on_failure:
  262. image: alpine:3
  263. commands:
  264. - apk add curl
  265. - "curl -d'Lemmy CI build failed: ${CI_PIPELINE_URL}' ntfy.sh/lemmy_drone_ci"
  266. when:
  267. - event: [pull_request, tag]
  268. status: failure
  269. notify_on_tag_deploy:
  270. image: alpine:3
  271. commands:
  272. - apk add curl
  273. - "curl -d'lemmy:${CI_COMMIT_TAG} deployed' ntfy.sh/lemmy_drone_ci"
  274. when:
  275. - event: tag
  276. services:
  277. database:
  278. image: postgres:16-alpine
  279. environment:
  280. POSTGRES_USER: lemmy
  281. POSTGRES_PASSWORD: password