Skip to content

Commit

Permalink
Fixing .drone.yml (#2677)
Browse files Browse the repository at this point in the history
* 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 358ce33.

* dont use all features for tests

---------

Co-authored-by: Nutomic <[email protected]>
  • Loading branch information
dessalines and Nutomic authored Jan 30, 2023
1 parent a8232fe commit a610211
Show file tree
Hide file tree
Showing 19 changed files with 97 additions and 77 deletions.
95 changes: 61 additions & 34 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 test
image: clux/muslrust:1.64.0
- 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:
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
- "! cargo tree -p lemmy_api_common --no-default-features -i diesel"

- name: check defaults.hjson updated
image: clux/muslrust:1.64.0
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: check with different features
image: clux/muslrust:1.64.0
- name: cargo test
image: clux/muslrust:1.67.0
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
RUST_BACKTRACE: 1
RUST_TEST_THREADS: 1
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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions crates/api_common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DbUrl, ParseError> {
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<DbUrl, ParseError> {
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<DbUrl, ParseError> {
Expand All @@ -793,7 +793,7 @@ pub fn generate_shared_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, LemmyError>
&actor_id.scheme(),
&actor_id.host_str().context(location_info!())?,
if let Some(port) = actor_id.port() {
format!(":{}", port)
format!(":{port}")
} else {
String::new()
},
Expand All @@ -802,9 +802,9 @@ pub fn generate_shared_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, LemmyError>
}

pub fn generate_outbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
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<DbUrl, LemmyError> {
Ok(Url::parse(&format!("{}/moderators", community_id))?.into())
Ok(Url::parse(&format!("{community_id}/moderators"))?.into())
}
5 changes: 1 addition & 4 deletions crates/apub/src/fetcher/webfinger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions crates/db_schema/src/impls/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
2 changes: 1 addition & 1 deletion crates/db_schema/src/impls/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Self>(conn)
.await
}
Expand Down
2 changes: 1 addition & 1 deletion crates/db_schema/src/impls/password_reset_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl PasswordResetRequest {
fn bytes_to_hex(bytes: Vec<u8>) -> String {
let mut str = String::new();
for byte in bytes {
str = format!("{}{:02x}", str, byte);
str = format!("{str}{byte:02x}");
}
str
}
Expand Down
2 changes: 1 addition & 1 deletion crates/db_schema/src/impls/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Self>(conn)
.await
}
Expand Down
11 changes: 4 additions & 7 deletions crates/db_schema/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn get_database_url_from_env() -> Result<String, VarError> {

pub fn fuzzy_search(q: &str) -> String {
let replaced = q.replace('%', "\\%").replace('_', "\\_").replace(' ', "%");
format!("%{}%", replaced)
format!("%{replaced}%")
}

pub fn limit_and_offset(
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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}"),
},
}
}
Expand Down
11 changes: 5 additions & 6 deletions crates/routes/src/feeds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -392,11 +392,10 @@ fn build_item(
protocol_and_hostname: &str,
) -> Result<Item, LemmyError> {
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/{} <a href=\"{}\">(link)</a>",
creator_name, author_url
"/u/{creator_name} <a href=\"{author_url}\">(link)</a>"
));
let dt = DateTime::<Utc>::from_utc(*published, Utc);
i.pub_date(dt.to_rfc2822());
Expand Down Expand Up @@ -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!("<br><a href=\"{url}\">{url}</a>", url = url);
let link_html = format!("<br><a href=\"{url}\">{url}</a>");
description.push_str(&link_html);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/routes/src/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
2 changes: 1 addition & 1 deletion crates/utils/src/apub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn generate_actor_keypair() -> Result<Keypair, Error> {
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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/utils/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docker/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions docker/prod/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
Loading

0 comments on commit a610211

Please sign in to comment.