rewrite woodpecker-ci to publish to crates.io #8
3 changed files with 120 additions and 42 deletions
|
@ -1,10 +1,96 @@
|
||||||
pipeline:
|
variables:
|
||||||
build:
|
- &rust_image "docker.io/rust:1.76"
|
||||||
image: rust
|
- &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:
|
commands:
|
||||||
- rustup component add rustfmt
|
- rustup component add rustfmt
|
||||||
- cargo --version
|
|
||||||
- cargo fmt --check
|
- cargo fmt --check
|
||||||
|
|
||||||
|
cargo_machete:
|
||||||
|
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
|
||||||
|
- cp cargo-binstall /usr/local/cargo/bin
|
||||||
|
- cargo binstall -y cargo-machete
|
||||||
|
- cargo machete
|
||||||
|
|
||||||
|
ignored_files:
|
||||||
|
image: docker.io/alpine:latest
|
||||||
|
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:
|
||||||
- cargo build
|
- cargo build
|
||||||
- cargo test
|
- mv target/debug/skip target/skip
|
||||||
|
when: *slow_check_paths
|
||||||
|
|
||||||
|
cargo_test:
|
||||||
|
image: *rust_image
|
||||||
|
environment:
|
||||||
|
RUST_BACKTRACE: "1"
|
||||||
|
CARGO_HOME: .cargo_home
|
||||||
|
commands:
|
||||||
|
- cargo test --no-fail-fast
|
||||||
|
when: *slow_check_paths
|
||||||
|
|
||||||
|
integration_test:
|
||||||
|
image: *rust_image
|
||||||
|
commands:
|
||||||
- ./test.sh
|
- ./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
|
||||||
|
|
29
src/lib.rs
29
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())),
|
None => Box::new(BufReader::new(std::io::stdin())),
|
||||||
};
|
};
|
||||||
if let Some(line) = &cli.line {
|
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 {
|
} else if let Some(ref token) = cli.token {
|
||||||
skip_tokens(cli, reader, writer, token)
|
skip_tokens(cli, reader, writer, token)
|
||||||
} else {
|
} else {
|
||||||
|
@ -49,14 +49,10 @@ pub fn skip(cli: &Cli, writer: &mut impl Write) -> Result<()> {
|
||||||
|
|
||||||
// skip a number of lines
|
// skip a number of lines
|
||||||
fn skip_lines(cli: &Cli, reader: Box<dyn BufRead>, writer: &mut impl Write) -> Result<()> {
|
fn skip_lines(cli: &Cli, reader: Box<dyn BufRead>, writer: &mut impl Write) -> Result<()> {
|
||||||
let mut counter = 0usize;
|
for (counter, current_line) in reader.lines().map_while(Option::Some).flatten().enumerate() {
|
||||||
for current_line in reader.lines() {
|
|
||||||
if let Ok(current_line) = current_line {
|
|
||||||
if counter >= cli.lines {
|
if counter >= cli.lines {
|
||||||
writeln!(writer, "{}", current_line)?;
|
writeln!(writer, "{}", current_line)?;
|
||||||
}
|
}
|
||||||
counter += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -69,8 +65,7 @@ fn skip_lines_matching(
|
||||||
line: &str,
|
line: &str,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut counter = 0usize;
|
let mut counter = 0usize;
|
||||||
for current_line in reader.lines() {
|
for current_line in reader.lines().map_while(Option::Some).flatten() {
|
||||||
if let Ok(current_line) = current_line {
|
|
||||||
if counter >= cli.lines {
|
if counter >= cli.lines {
|
||||||
writeln!(writer, "{}", current_line)?;
|
writeln!(writer, "{}", current_line)?;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +73,6 @@ fn skip_lines_matching(
|
||||||
counter += 1;
|
counter += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,12 +86,11 @@ fn skip_tokens(
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut counter = 0usize;
|
let mut counter = 0usize;
|
||||||
|
|
||||||
for current_line in reader.lines() {
|
for current_line in reader.lines().map_while(Option::Some).flatten() {
|
||||||
if let Ok(current_line) = current_line {
|
|
||||||
if counter >= cli.lines {
|
if counter >= cli.lines {
|
||||||
writeln!(writer, "{}", current_line)?;
|
writeln!(writer, "{}", current_line)?;
|
||||||
}
|
}
|
||||||
if current_line.contains(&token) {
|
if current_line.contains(token) {
|
||||||
if cli.ignore_extras {
|
if cli.ignore_extras {
|
||||||
counter += 1;
|
counter += 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -106,7 +99,6 @@ fn skip_tokens(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,10 +143,7 @@ mod tests {
|
||||||
skip(&cli, &mut lines)?;
|
skip(&cli, &mut lines)?;
|
||||||
|
|
||||||
//then
|
//then
|
||||||
assert_eq!(
|
assert_eq!(String::from_utf8(lines)?, ["alpha", "gamma\n"].join("\n"));
|
||||||
String::from_utf8(lines)?,
|
|
||||||
vec!["alpha", "gamma\n"].join("\n")
|
|
||||||
);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +185,7 @@ mod tests {
|
||||||
//then
|
//then
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
String::from_utf8(lines)?,
|
String::from_utf8(lines)?,
|
||||||
vec![
|
[
|
||||||
"Or help one fainting robin",
|
"Or help one fainting robin",
|
||||||
"Unto his nest again,",
|
"Unto his nest again,",
|
||||||
"I shall not live in vain.\n"
|
"I shall not live in vain.\n"
|
||||||
|
@ -224,7 +213,7 @@ mod tests {
|
||||||
//then
|
//then
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
String::from_utf8(lines)?,
|
String::from_utf8(lines)?,
|
||||||
vec![
|
[
|
||||||
//Lorem ipsum dolor sit amet, -- +2 = 2
|
//Lorem ipsum dolor sit amet, -- +2 = 2
|
||||||
//consectetur adipiscing elit,
|
//consectetur adipiscing elit,
|
||||||
//sed do eiusmod tempor incididunt -- +1 = 3
|
//sed do eiusmod tempor incididunt -- +1 = 3
|
||||||
|
@ -257,7 +246,7 @@ mod tests {
|
||||||
//then
|
//then
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
String::from_utf8(lines)?,
|
String::from_utf8(lines)?,
|
||||||
vec![
|
[
|
||||||
//Lorem ipsum dolor sit amet, -- 1
|
//Lorem ipsum dolor sit amet, -- 1
|
||||||
//consectetur adipiscing elit,
|
//consectetur adipiscing elit,
|
||||||
//sed do eiusmod tempor incididunt -- 2
|
//sed do eiusmod tempor incididunt -- 2
|
||||||
|
|
7
test.sh
7
test.sh
|
@ -2,11 +2,14 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
SKIP="./target/debug/skip"
|
echo "PWD: $PWD"
|
||||||
|
ls -l
|
||||||
|
ls -l target
|
||||||
|
SKIP="./target/skip"
|
||||||
DIFF="diff -u --color"
|
DIFF="diff -u --color"
|
||||||
|
|
||||||
if test ! -x $SKIP ; then
|
if test ! -x $SKIP ; then
|
||||||
echo "File missing: $SKIP - try 'zig build'"
|
echo "File missing: $SKIP - try 'cargo build'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue