From a610211557a15c00f9591e0515c781d46c26890f Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 30 Jan 2023 14:17:24 -0500 Subject: [PATCH] Fixing `.drone.yml` (#2677) * Try to fix docker/drone plugin * Trying to use one rust image. * Fixing drone 1. * Fixing drone 2. * Add drone notify. * Fixing drone 3. * Fixing drone 4. * Fix clippy. * Remove uninlined format lint. * Combine all cargo tasks * Fixing drone 5. * Fixing drone 6. * Fixing drone 7. * Fixing drone 8. * Fixing drone 9. * Fixing drone 10. * Fixing drone 12. * Fixing drone 13. * Fixing drone 14. * Fixing drone 15. * Fixing drone 16. * Fixing drone 17. * Fixing drone 18. * Fixing drone 19. * Fixing drone 20. * Fixing drone 21. * Fixing drone 22. * Fixing drone 23. * Fixing drone 24. * Fixing drone 25. * Fixing drone 26. * Fixing drone 27. * Fixing drone 28. * Fixing drone 29. * Fixing drone 30. * Fixing drone 31. * Fixing drone 32. * Fixing drone 33. * Fixing drone 34. * Fixing drone 35. * Fixing drone 36. * Fixing drone 37. * Fixing drone 38. * Fixing drone 39. * Fixing drone 40. * Fixing drone 41. * Fixing drone 43. * Fixing drone 44. * Fixing drone 45. * Last cleanup. * Fixing drone 46. * Separate ci steps (#2679) * separate ci steps * fix 1 * add comments * dont add rustfmt explicitly * Revert "dont add rustfmt explicitly" This reverts commit 358ce3302a134b7ac88d90a854079356995e9725. * dont use all features for tests --------- Co-authored-by: Nutomic --- .drone.yml | 109 +++++++++++------- crates/api_common/src/utils.rs | 12 +- crates/apub/src/fetcher/webfinger.rs | 5 +- crates/db_schema/src/impls/comment.rs | 5 +- crates/db_schema/src/impls/community.rs | 2 +- .../src/impls/password_reset_request.rs | 2 +- crates/db_schema/src/impls/person.rs | 2 +- crates/db_schema/src/utils.rs | 11 +- crates/routes/src/feeds.rs | 11 +- crates/routes/src/images.rs | 2 +- crates/utils/src/apub.rs | 2 +- crates/utils/src/error.rs | 2 +- docker/dev/Dockerfile | 2 +- docker/prod/Dockerfile | 4 +- scripts/fix-clippy.sh | 5 +- scripts/test.sh | 2 +- src/code_migrations.rs | 2 +- src/root_span_builder.rs | 4 +- src/scheduled_tasks.rs | 4 +- 19 files changed, 104 insertions(+), 84 deletions(-) diff --git a/.drone.yml b/.drone.yml index 9df1405a5..559986e9f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,27 +10,33 @@ steps: # use minimum supported rust version for most steps - name: prepare repo - image: clux/muslrust:1.64.0 + image: alpine:3 commands: + - apk add git - git fetch --tags - git submodule init - git submodule update --recursive --remote - - chown 1000:1000 . -R - - name: check formatting - image: rustdocker/rust:nightly + - name: cargo fmt + image: clux/muslrust:1.67.0 + environment: + # store cargo data in repo folder so that it gets cached between steps + CARGO_HOME: .cargo commands: - - /root/.cargo/bin/cargo fmt -- --check + # need make existing toolchain available + - cp ~/.cargo . -r + - rustup toolchain install nightly + - rustup component add rustfmt --toolchain nightly + - cargo +nightly fmt -- --check + - # latest rust for clippy to get extra checks - # when adding new clippy lints, make sure to also add them in scripts/fix-clippy.sh - name: cargo clippy - image: rust:1.65-buster + image: clux/muslrust:1.67.0 environment: CARGO_HOME: .cargo commands: - - apt-get update - - apt-get install -y --no-install-recommends protobuf-compiler libprotobuf-dev + # latest rust for clippy to get extra checks + # when adding new clippy lints, make sure to also add them in scripts/fix-clippy.sh - rustup component add clippy - cargo clippy --workspace --tests --all-targets --all-features -- -D warnings -D deprecated -D clippy::perf -D clippy::complexity @@ -40,45 +46,56 @@ steps: -D clippy::wildcard_imports -D clippy::cast_lossless -D clippy::manual_string_new -D clippy::redundant_closure_for_method_calls -D clippy::unused_self + -A clippy::uninlined_format_args - cargo clippy --workspace --all-features -- -D clippy::unwrap_used + - name: cargo check + image: clux/muslrust:1.67.0 + environment: + CARGO_HOME: .cargo + commands: + - cargo check --package lemmy_utils + - cargo check --package lemmy_db_schema + - cargo check --package lemmy_db_views + - cargo check --package lemmy_db_views_actor + - cargo check --package lemmy_db_views_moderator + - cargo check --package lemmy_api_common + - cargo check --package lemmy_api + - cargo check --package lemmy_api_crud + - cargo check --package lemmy_apub + - cargo check --package lemmy_routes + - cargo check --workspace --no-default-features + - cargo check --workspace --all-features + + - name: lemmy_api_common doesnt depend on diesel + image: clux/muslrust:1.67.0 + environment: + CARGO_HOME: .cargo + commands: + - "! cargo tree -p lemmy_api_common --no-default-features -i diesel" + + - name: check defaults.hjson updated + image: clux/muslrust:1.67.0 + environment: + CARGO_HOME: .cargo + commands: + - export LEMMY_CONFIG_LOCATION=./config/config.hjson + - ./scripts/update_config_defaults.sh config/defaults_current.hjson + - diff config/defaults.hjson config/defaults_current.hjson + - name: cargo test - image: clux/muslrust:1.64.0 + image: clux/muslrust:1.67.0 environment: LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy - LEMMY_CONFIG_LOCATION: ../../config/config.hjson RUST_BACKTRACE: 1 RUST_TEST_THREADS: 1 CARGO_HOME: .cargo commands: - - apt-get update - - apt-get -y install --no-install-recommends postgresql-client protobuf-compiler libprotobuf-dev - - cargo test --workspace --no-fail-fast --all-features - - - name: check defaults.hjson updated - image: clux/muslrust:1.64.0 - environment: - CARGO_HOME: .cargo - commands: - - ./scripts/update_config_defaults.sh config/defaults_current.hjson - - diff config/defaults.hjson config/defaults_current.hjson - - - name: check with different features - image: clux/muslrust:1.64.0 - environment: - CARGO_HOME: .cargo - commands: - - cargo install cargo-workspaces - - cargo workspaces exec cargo check --no-default-features - - cargo workspaces exec cargo check --all-features - - - name: lemmy_api_common doesnt depend on diesel - image: rust:1.64-buster - commands: - - "! cargo tree -p lemmy_api_common --no-default-features -i diesel" + - export LEMMY_CONFIG_LOCATION=../../config/config.hjson + - cargo test --workspace --no-fail-fast - name: cargo build - image: clux/muslrust:1.64.0 + image: clux/muslrust:1.67.0 environment: CARGO_HOME: .cargo commands: @@ -106,6 +123,7 @@ steps: password: from_secret: docker_password repo: dessalines/lemmy + 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 tags: - dev when: @@ -121,6 +139,7 @@ steps: password: from_secret: docker_password repo: dessalines/lemmy + 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 auto_tag: true auto_tag_suffix: linux-amd64 when: @@ -163,7 +182,7 @@ steps: # using https://github.com/pksunkara/cargo-workspaces - name: publish to crates.io - image: rustlang/rust:nightly + image: clux/muslrust:1.67.0 environment: CARGO_TOKEN: from_secret: cargo_api_token @@ -176,9 +195,18 @@ steps: ref: - refs/tags/* + - name: Notify on failure + image: alpine:3 + commands: + - apk add curl + - "curl -d'Drone build failed: ${DRONE_BUILD_LINK}' ntfy.sh/lemmy_drone_ci" + when: + status: + - failure + services: - name: database - image: postgres:14-alpine + image: postgres:15-alpine environment: POSTGRES_USER: lemmy POSTGRES_PASSWORD: password @@ -197,7 +225,6 @@ steps: image: rust:1.57-slim user: root commands: - - chown 1000:1000 . -R - apt update - apt install --no-install-recommends --yes git - git fetch --tags diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index 22d8e6110..bf9bbf1b0 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -769,15 +769,15 @@ pub fn generate_local_apub_endpoint( EndpointType::PrivateMessage => "private_message", }; - Ok(Url::parse(&format!("{}/{}/{}", domain, point, name))?.into()) + Ok(Url::parse(&format!("{domain}/{point}/{name}"))?.into()) } pub fn generate_followers_url(actor_id: &DbUrl) -> Result { - Ok(Url::parse(&format!("{}/followers", actor_id))?.into()) + Ok(Url::parse(&format!("{actor_id}/followers"))?.into()) } pub fn generate_inbox_url(actor_id: &DbUrl) -> Result { - Ok(Url::parse(&format!("{}/inbox", actor_id))?.into()) + Ok(Url::parse(&format!("{actor_id}/inbox"))?.into()) } pub fn generate_site_inbox_url(actor_id: &DbUrl) -> Result { @@ -793,7 +793,7 @@ pub fn generate_shared_inbox_url(actor_id: &DbUrl) -> Result &actor_id.scheme(), &actor_id.host_str().context(location_info!())?, if let Some(port) = actor_id.port() { - format!(":{}", port) + format!(":{port}") } else { String::new() }, @@ -802,9 +802,9 @@ pub fn generate_shared_inbox_url(actor_id: &DbUrl) -> Result } pub fn generate_outbox_url(actor_id: &DbUrl) -> Result { - Ok(Url::parse(&format!("{}/outbox", actor_id))?.into()) + Ok(Url::parse(&format!("{actor_id}/outbox"))?.into()) } pub fn generate_moderators_url(community_id: &DbUrl) -> Result { - Ok(Url::parse(&format!("{}/moderators", community_id))?.into()) + Ok(Url::parse(&format!("{community_id}/moderators"))?.into()) } diff --git a/crates/apub/src/fetcher/webfinger.rs b/crates/apub/src/fetcher/webfinger.rs index 4746736eb..968a0d702 100644 --- a/crates/apub/src/fetcher/webfinger.rs +++ b/crates/apub/src/fetcher/webfinger.rs @@ -25,10 +25,7 @@ where .splitn(2, '@') .collect_tuple() .ok_or_else(|| LemmyError::from_message("Invalid webfinger query, missing domain"))?; - let fetch_url = format!( - "{}://{}/.well-known/webfinger?resource=acct:{}", - protocol, domain, identifier - ); + let fetch_url = format!("{protocol}://{domain}/.well-known/webfinger?resource=acct:{identifier}"); debug!("Fetching webfinger url: {}", &fetch_url); *request_counter += 1; diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index 688cff714..21dc6c26b 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -105,11 +105,10 @@ update comment_aggregates ca set child_count = c.child_count from ( select c.id, c.path, count(c2.id) as child_count from comment c join comment c2 on c2.path <@ c.path and c2.path != c.path - and c.path <@ '{}' + and c.path <@ '{top_parent}' group by c.id ) as c -where ca.comment_id = c.id", - top_parent +where ca.comment_id = c.id" ); sql_query(update_child_count_stmt).execute(conn).await?; diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index 5f29f1359..935bfa05e 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -357,7 +357,7 @@ impl ApubActor for Community { let conn = &mut get_conn(pool).await?; community .filter(lower(name).eq(lower(community_name))) - .filter(actor_id.like(format!("{}%", protocol_domain))) + .filter(actor_id.like(format!("{protocol_domain}%"))) .first::(conn) .await } diff --git a/crates/db_schema/src/impls/password_reset_request.rs b/crates/db_schema/src/impls/password_reset_request.rs index 6720df3f2..4aa5599a0 100644 --- a/crates/db_schema/src/impls/password_reset_request.rs +++ b/crates/db_schema/src/impls/password_reset_request.rs @@ -79,7 +79,7 @@ impl PasswordResetRequest { fn bytes_to_hex(bytes: Vec) -> String { let mut str = String::new(); for byte in bytes { - str = format!("{}{:02x}", str, byte); + str = format!("{str}{byte:02x}"); } str } diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index 1850c261d..fa7d2530f 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -219,7 +219,7 @@ impl ApubActor for Person { let conn = &mut get_conn(pool).await?; person .filter(lower(name).eq(lower(person_name))) - .filter(actor_id.like(format!("{}%", protocol_domain))) + .filter(actor_id.like(format!("{protocol_domain}%"))) .first::(conn) .await } diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index cf96b5e77..8441b6872 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -46,7 +46,7 @@ pub fn get_database_url_from_env() -> Result { pub fn fuzzy_search(q: &str) -> String { let replaced = q.replace('%', "\\%").replace('_', "\\_").replace(' ', "%"); - format!("%{}%", replaced) + format!("%{replaced}%") } pub fn limit_and_offset( @@ -67,7 +67,7 @@ pub fn limit_and_offset( Some(limit) => { if !(1..=FETCH_LIMIT_MAX).contains(&limit) { return Err(QueryBuilderError( - format!("Fetch limit is > {}", FETCH_LIMIT_MAX).into(), + format!("Fetch limit is > {FETCH_LIMIT_MAX}").into(), )); } else { limit @@ -154,7 +154,7 @@ pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!(); pub fn run_migrations(db_url: &str) { // Needs to be a sync connection let mut conn = - PgConnection::establish(db_url).unwrap_or_else(|_| panic!("Error connecting to {}", db_url)); + PgConnection::establish(db_url).unwrap_or_else(|_| panic!("Error connecting to {db_url}")); info!("Running Database migrations (This may take a long time)..."); let _ = &mut conn .run_pending_migrations(MIGRATIONS) @@ -178,10 +178,7 @@ pub fn get_database_url(settings: Option<&Settings>) -> String { Ok(url) => url, Err(e) => match settings { Some(settings) => settings.get_database_url(), - None => panic!( - "Failed to read database URL from env var LEMMY_DATABASE_URL: {}", - e - ), + None => panic!("Failed to read database URL from env var LEMMY_DATABASE_URL: {e}"), }, } } diff --git a/crates/routes/src/feeds.rs b/crates/routes/src/feeds.rs index 594bf1153..2e4f815db 100644 --- a/crates/routes/src/feeds.rs +++ b/crates/routes/src/feeds.rs @@ -329,7 +329,7 @@ async fn get_feed_inbox( channel_builder .namespaces(RSS_NAMESPACE.clone()) .title(&format!("{} - Inbox", site_view.site.name)) - .link(format!("{}/inbox", protocol_and_hostname,)) + .link(format!("{protocol_and_hostname}/inbox",)) .items(items); if let Some(site_desc) = site_view.site.description { @@ -392,11 +392,10 @@ fn build_item( protocol_and_hostname: &str, ) -> Result { let mut i = ItemBuilder::default(); - i.title(format!("Reply from {}", creator_name)); - let author_url = format!("{}/u/{}", protocol_and_hostname, creator_name); + i.title(format!("Reply from {creator_name}")); + let author_url = format!("{protocol_and_hostname}/u/{creator_name}"); i.author(format!( - "/u/{} (link)", - creator_name, author_url + "/u/{creator_name} (link)" )); let dt = DateTime::::from_utc(*published, Utc); i.pub_date(dt.to_rfc2822()); @@ -451,7 +450,7 @@ fn create_post_items( // If its a url post, add it to the description if let Some(url) = p.post.url { - let link_html = format!("
{url}", url = url); + let link_html = format!("
{url}"); description.push_str(&link_html); } diff --git a/crates/routes/src/images.rs b/crates/routes/src/images.rs index 0b1f6fbdd..cd6555d7d 100644 --- a/crates/routes/src/images.rs +++ b/crates/routes/src/images.rs @@ -158,7 +158,7 @@ async fn full_res( let mut url = format!("{}image/process.{}?src={}", pictrs_config.url, format, name,); if let Some(size) = params.thumbnail { - url = format!("{}&thumbnail={}", url, size,); + url = format!("{url}&thumbnail={size}",); } url }; diff --git a/crates/utils/src/apub.rs b/crates/utils/src/apub.rs index 130ee26ed..53e069d77 100644 --- a/crates/utils/src/apub.rs +++ b/crates/utils/src/apub.rs @@ -16,7 +16,7 @@ pub fn generate_actor_keypair() -> Result { Ok(s) => Ok(s), Err(e) => Err(Error::new( ErrorKind::Other, - format!("Failed converting key to string: {}", e), + format!("Failed converting key to string: {e}"), )), }; Ok(Keypair { diff --git a/crates/utils/src/error.rs b/crates/utils/src/error.rs index 441c0422e..41b437587 100644 --- a/crates/utils/src/error.rs +++ b/crates/utils/src/error.rs @@ -86,7 +86,7 @@ impl Debug for LemmyError { impl Display for LemmyError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(message) = &self.message { - write!(f, "{}: ", message)?; + write!(f, "{message}: ")?; } writeln!(f, "{}", self.inner)?; fmt::Display::fmt(&self.context, f) diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile index b004720ec..d52a52d3a 100644 --- a/docker/dev/Dockerfile +++ b/docker/dev/Dockerfile @@ -1,4 +1,4 @@ -ARG RUST_BUILDER_IMAGE=clux/muslrust:1.64.0 +ARG RUST_BUILDER_IMAGE=clux/muslrust:1.67.0 FROM $RUST_BUILDER_IMAGE as chef USER root diff --git a/docker/prod/Dockerfile b/docker/prod/Dockerfile index eb6bc215a..2ea67f819 100644 --- a/docker/prod/Dockerfile +++ b/docker/prod/Dockerfile @@ -1,5 +1,5 @@ # Build the project -FROM clux/muslrust:1.64.0 as builder +FROM clux/muslrust:1.67.0 as builder ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl ARG RUSTRELEASEDIR="release" @@ -17,7 +17,7 @@ RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server /app/lemmy_serv FROM alpine:3 as lemmy # Install libpq for postgres -RUN apk add libpq +RUN apk update && apk add libpq # Copy resources COPY --from=builder /app/lemmy_server /app/lemmy diff --git a/scripts/fix-clippy.sh b/scripts/fix-clippy.sh index 53b4c7562..8de660150 100755 --- a/scripts/fix-clippy.sh +++ b/scripts/fix-clippy.sh @@ -1,11 +1,12 @@ #!/bin/bash set -e -cargo clippy --workspace --fix --allow-staged --tests --all-targets --all-features -- \ +cargo clippy --workspace --fix --allow-staged --allow-dirty --tests --all-targets --all-features -- \ -D warnings -D deprecated -D clippy::perf -D clippy::complexity \ -D clippy::style -D clippy::correctness -D clippy::suspicious \ -D clippy::dbg_macro -D clippy::inefficient_to_string \ -D clippy::items-after-statements -D clippy::implicit_clone \ -D clippy::wildcard_imports -D clippy::cast_lossless \ -D clippy::manual_string_new -D clippy::redundant_closure_for_method_calls \ - -D clippy::unused_self + -D clippy::unused_self \ + -A clippy::uninlined_format_args diff --git a/scripts/test.sh b/scripts/test.sh index a64d99d42..e3239c7d3 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -17,7 +17,7 @@ if [ -n "$PACKAGE" ]; then cargo test -p $PACKAGE --all-features --no-fail-fast else - cargo test --workspace --all-features --no-fail-fast + cargo test --workspace --no-fail-fast fi # Add this to do printlns: -- --nocapture diff --git a/src/code_migrations.rs b/src/code_migrations.rs index 89933a15e..5151611bd 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -248,7 +248,7 @@ async fn post_thumbnail_url_updates_2020_07_27( info!("Running post_thumbnail_url_updates_2020_07_27"); - let domain_prefix = format!("{}/pictrs/image/", protocol_and_hostname,); + let domain_prefix = format!("{protocol_and_hostname}/pictrs/image/",); let incorrect_thumbnails = post.filter(thumbnail_url.not_like("http%")); diff --git a/src/root_span_builder.rs b/src/root_span_builder.rs index 477ac9edd..016074c7d 100644 --- a/src/root_span_builder.rs +++ b/src/root_span_builder.rs @@ -65,8 +65,8 @@ fn handle_error(span: Span, status_code: StatusCode, response_error: &dyn Respon } // pre-formatting errors is a workaround for https://github.com/tokio-rs/tracing/issues/1565 - let display_error = format!("{}", response_error); - let debug_error = format!("{:?}", response_error); + let display_error = format!("{response_error}"); + let debug_error = format!("{response_error:?}"); tracing::info_span!( parent: None, diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index 2c6648f2c..578549110 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -21,7 +21,7 @@ pub fn setup(db_url: String) -> Result<(), LemmyError> { reindex_aggregates_tables(&mut conn, true); scheduler.every(1.hour()).run(move || { let conn = &mut PgConnection::establish(&db_url) - .unwrap_or_else(|_| panic!("Error connecting to {}", db_url)); + .unwrap_or_else(|_| panic!("Error connecting to {db_url}")); active_counts(conn); update_banned_when_expired(conn); reindex_aggregates_tables(conn, true); @@ -56,7 +56,7 @@ fn reindex_aggregates_tables(conn: &mut PgConnection, concurrently: bool) { fn reindex_table(conn: &mut PgConnection, table_name: &str, concurrently: bool) { let concurrently_str = if concurrently { "concurrently" } else { "" }; info!("Reindexing table {} {} ...", concurrently_str, table_name); - let query = format!("reindex table {} {}", concurrently_str, table_name); + let query = format!("reindex table {concurrently_str} {table_name}"); sql_query(query).execute(conn).expect("reindex table"); info!("Done."); }