From 2c1e173641d631bc0f188caf2d0d3e134b81a46e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 24 Mar 2023 08:17:22 +0000 Subject: [PATCH 01/13] Add woodpecker ci config --- .woodpecker.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .woodpecker.yml diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..2e41b51 --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,9 @@ +pipeline: + build: + image: rust + commands: + - cargo --version + - cargo fmt --check + - cargo build + - cargo test + - ./test.sh -- 2.45.2 From 3700c0ff498e2f922d59cca3c0529aaf87d91e0e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 24 Mar 2023 08:21:44 +0000 Subject: [PATCH 02/13] clean up just file --- justfile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/justfile b/justfile index 88e7fe6..478e8e6 100644 --- a/justfile +++ b/justfile @@ -1,15 +1,15 @@ -dist: target-release-skip +dist: target-release if test ! -d dist ; then mkdir dist ; fi cp target/release/skip dist/ -inttest: target-debug-skip - ./test.sh - -target-release-skip: unittest inttest +target-release: unittest inttest cargo build --release -target-debug-skip: - cargo build +inttest: target-debug + ./test.sh -unittest: target-debug-skip +unittest: target-debug cargo test + +target-debug: + cargo build -- 2.45.2 From 3b8876f39e720f5bb19bd0452af4032a4dac8df0 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 24 Mar 2023 08:35:52 +0000 Subject: [PATCH 03/13] woodpecker: install rustfmt --- .woodpecker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.woodpecker.yml b/.woodpecker.yml index 2e41b51..2c9bb67 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -2,6 +2,7 @@ pipeline: build: image: rust commands: + - rustup component add rustfmt - cargo --version - cargo fmt --check - cargo build -- 2.45.2 From f30f7c48aa7f966de660363ad933b40bf01f00bc Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 26 Feb 2024 08:30:01 +0000 Subject: [PATCH 04/13] rewrite .woodpecker.yml inspiration from lemmmy --- .woodpecker.yml | 102 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 95 insertions(+), 7 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 2c9bb67..bd8e535 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,10 +1,98 @@ -pipeline: - build: - image: rust +variables: + - &rust_image "docker.io/rust:1.76" + - &slow_check_paths + - path: + # rust source code + - "crates/**" + - "src/**" + - "tests/**" + - "**/Cargo.toml" + - "Cargo.lock" + # database migrations + - "migrations/**" + # config files and scripts used by ci + - ".woodpecker.yml" + +steps: + + toml_fmt: + image: docker.io/tamasfe/taplo:0.8.1 + commands: + - taplo format --check + + + cargo_fmt: + image: docker.io/rustlang/rust:nightly + environment: + # store cargo data in repo folder so that it gets cached between steps + CARGO_HOME: .cargo_home + commands: + # need make existing toolchain available + - cargo +nightly fmt -- --check + + cargo_machete: + image: docker.io/rustlang/rust:nightly + commands: + - wget https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz + - tar -xvf cargo-binstall-x86_64-unknown-linux-musl.tgz + - cp cargo-binstall /usr/local/cargo/bin + - cargo binstall -y cargo-machete + - cargo machete + + ignored_files: + image: docker.io/alpine:3 + commands: + - apk add git + - IGNORED=$(git ls-files --cached -i --exclude-standard) + - if [[ "$IGNORED" ]]; then echo "Ignored files present:\n$IGNORED\n"; exit 1; fi + + check: + image: *rust_image + environment: + CARGO_HOME: .cargo_home + commands: + - cargo check + when: *slow_check_paths + + cargo_clippy: + image: *rust_image + environment: + CARGO_HOME: .cargo_home + commands: + - rustup component add clippy + - cargo clippy --tests --all-targets -- -D warnings + when: *slow_check_paths + + cargo_build: + image: *rust_image + environment: + CARGO_HOME: .cargo_home commands: - - rustup component add rustfmt - - cargo --version - - cargo fmt --check - cargo build - - cargo test + - mv target/debug/lemmy_server target/lemmy_server + when: *slow_check_paths + + cargo_test: + image: *rust_image + environment: + LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy + RUST_BACKTRACE: "1" + CARGO_HOME: .cargo_home + commands: + - cargo test --no-fail-fast + when: *slow_check_paths + + integration_test: + image: docker.io/debian-slim:latest + commands: - ./test.sh + + publish_to_crates_io: + image: *rust_image + commands: + - cargo login "$CARGO_REGISTRY_TOKEN" + - cargo publish --registry crates-io --no-verify --allow-branch "${CI_COMMIT_TAG}" --yes + secrets: [cargo_api_token] + when: + event: tag + -- 2.45.2 From 3cc1b6743c956adc59a2f65f297268e16d7471d5 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 26 Feb 2024 08:34:08 +0000 Subject: [PATCH 05/13] install rustfmt --- .woodpecker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 73317e0..870d69d 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -27,8 +27,8 @@ steps: # store cargo data in repo folder so that it gets cached between steps CARGO_HOME: .cargo_home commands: - # need make existing toolchain available - - cargo +nightly fmt -- --check + - rustup component add rustfmt + - cargo fmt --check cargo_machete: image: docker.io/rustlang/rust:nightly -- 2.45.2 From 9c51c9c719c740fde00f2ce2c3b1698ffd12fb87 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 26 Feb 2024 08:47:01 +0000 Subject: [PATCH 06/13] cargo clippy --- src/lib.rs | 59 ++++++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 397c4b0..a61003a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ pub fn skip(cli: &Cli, writer: &mut impl Write) -> Result<()> { None => Box::new(BufReader::new(std::io::stdin())), }; if let Some(line) = &cli.line { - skip_lines_matching(&cli, reader, writer, line) + skip_lines_matching(cli, reader, writer, line) } else if let Some(ref token) = cli.token { skip_tokens(cli, reader, writer, token) } else { @@ -49,13 +49,9 @@ pub fn skip(cli: &Cli, writer: &mut impl Write) -> Result<()> { // skip a number of lines fn skip_lines(cli: &Cli, reader: Box, writer: &mut impl Write) -> Result<()> { - let mut counter = 0usize; - for current_line in reader.lines() { - if let Ok(current_line) = current_line { - if counter >= cli.lines { - writeln!(writer, "{}", current_line)?; - } - counter += 1; + for (counter, current_line) in reader.lines().map_while(Option::Some).flatten().enumerate() { + if counter >= cli.lines { + writeln!(writer, "{}", current_line)?; } } Ok(()) @@ -69,14 +65,12 @@ fn skip_lines_matching( line: &str, ) -> Result<()> { let mut counter = 0usize; - for current_line in reader.lines() { - if let Ok(current_line) = current_line { - if counter >= cli.lines { - writeln!(writer, "{}", current_line)?; - } - if line == current_line { - counter += 1; - } + for current_line in reader.lines().map_while(Option::Some).flatten() { + if counter >= cli.lines { + writeln!(writer, "{}", current_line)?; + } + if line == current_line { + counter += 1; } } Ok(()) @@ -92,18 +86,16 @@ fn skip_tokens( ) -> Result<()> { let mut counter = 0usize; - for current_line in reader.lines() { - if let Ok(current_line) = current_line { - if counter >= cli.lines { - writeln!(writer, "{}", current_line)?; - } - if current_line.contains(&token) { - if cli.ignore_extras { - counter += 1; - } else { - let occurances = current_line.matches(&token).count(); - counter += occurances; - } + for current_line in reader.lines().map_while(Option::Some).flatten() { + if counter >= cli.lines { + writeln!(writer, "{}", current_line)?; + } + if current_line.contains(token) { + if cli.ignore_extras { + counter += 1; + } else { + let occurances = current_line.matches(&token).count(); + counter += occurances; } } } @@ -151,10 +143,7 @@ mod tests { skip(&cli, &mut lines)?; //then - assert_eq!( - String::from_utf8(lines)?, - vec!["alpha", "gamma\n"].join("\n") - ); + assert_eq!(String::from_utf8(lines)?, ["alpha", "gamma\n"].join("\n")); Ok(()) } @@ -196,7 +185,7 @@ mod tests { //then assert_eq!( String::from_utf8(lines)?, - vec![ + [ "Or help one fainting robin", "Unto his nest again,", "I shall not live in vain.\n" @@ -224,7 +213,7 @@ mod tests { //then assert_eq!( String::from_utf8(lines)?, - vec![ + [ //Lorem ipsum dolor sit amet, -- +2 = 2 //consectetur adipiscing elit, //sed do eiusmod tempor incididunt -- +1 = 3 @@ -257,7 +246,7 @@ mod tests { //then assert_eq!( String::from_utf8(lines)?, - vec![ + [ //Lorem ipsum dolor sit amet, -- 1 //consectetur adipiscing elit, //sed do eiusmod tempor incididunt -- 2 -- 2.45.2 From f949fc5474ca3f72a1782bad49616c556fae327a Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 26 Feb 2024 08:47:12 +0000 Subject: [PATCH 07/13] update message to cargo --- test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.sh b/test.sh index e4c3aa8..8b4dc2c 100755 --- a/test.sh +++ b/test.sh @@ -6,7 +6,7 @@ SKIP="./target/debug/skip" DIFF="diff -u --color" if test ! -x $SKIP ; then - echo "File missing: $SKIP - try 'zig build'" + echo "File missing: $SKIP - try 'cargo build'" exit 1 fi -- 2.45.2 From 4fcbb1bf6b5c0a80f44c2417058faa2e0fde9014 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 26 Feb 2024 08:51:38 +0000 Subject: [PATCH 08/13] remove ro replace lemmy references --- .woodpecker.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 870d69d..bed4561 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -69,13 +69,12 @@ steps: CARGO_HOME: .cargo_home commands: - cargo build - - mv target/debug/lemmy_server target/lemmy_server + - mv target/debug/skip target/skip when: *slow_check_paths cargo_test: image: *rust_image environment: - LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy RUST_BACKTRACE: "1" CARGO_HOME: .cargo_home commands: -- 2.45.2 From 4a50b99b7b8e4314110d8b8a97172b91f6518f77 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 26 Feb 2024 09:04:35 +0000 Subject: [PATCH 09/13] update docker images --- .woodpecker.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index bed4561..efd7e0b 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -31,7 +31,7 @@ steps: - cargo fmt --check cargo_machete: - image: docker.io/rustlang/rust:nightly + image: *rust_image commands: - wget https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz - tar -xvf cargo-binstall-x86_64-unknown-linux-musl.tgz @@ -40,7 +40,7 @@ steps: - cargo machete ignored_files: - image: docker.io/alpine:3 + image: docker.io/alpine:latest commands: - apk add git - IGNORED=$(git ls-files --cached -i --exclude-standard) @@ -82,7 +82,7 @@ steps: when: *slow_check_paths integration_test: - image: docker.io/debian-slim:latest + image: docker.io/alpine:latest commands: - ./test.sh -- 2.45.2 From 3cb098191c44911f1a52f02f175a189dce94d517 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 26 Feb 2024 09:09:01 +0000 Subject: [PATCH 10/13] alpine needs to add bash --- .woodpecker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.woodpecker.yml b/.woodpecker.yml index efd7e0b..0bf6420 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -84,6 +84,7 @@ steps: integration_test: image: docker.io/alpine:latest commands: + - apk add bash - ./test.sh publish_to_crates_io: -- 2.45.2 From 05fdca152dc0f8fd0e6b3efccd9711e2c330699f Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 26 Feb 2024 09:16:04 +0000 Subject: [PATCH 11/13] test.sh: update path to skip for ci --- test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 8b4dc2c..5fc8e5e 100755 --- a/test.sh +++ b/test.sh @@ -2,7 +2,7 @@ set -e -SKIP="./target/debug/skip" +SKIP="./target/skip" DIFF="diff -u --color" if test ! -x $SKIP ; then -- 2.45.2 From dc4547e47c682da23379635279c89ab1bbdab7c9 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 26 Feb 2024 09:25:51 +0000 Subject: [PATCH 12/13] what dir am I in? --- test.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test.sh b/test.sh index 5fc8e5e..b78f511 100755 --- a/test.sh +++ b/test.sh @@ -2,6 +2,9 @@ set -e +echo "PWD: $PWD" +ls -l +ls -l target SKIP="./target/skip" DIFF="diff -u --color" -- 2.45.2 From a15c97a55f87bbe77f39c2aac46af4f115cac8c6 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 26 Feb 2024 09:30:29 +0000 Subject: [PATCH 13/13] use same image for int_test to preseve target? --- .woodpecker.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 0bf6420..ec38d74 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -82,9 +82,8 @@ steps: when: *slow_check_paths integration_test: - image: docker.io/alpine:latest + image: *rust_image commands: - - apk add bash - ./test.sh publish_to_crates_io: -- 2.45.2