Skip to content

Commit

Permalink
ci: add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
m4tx committed Dec 25, 2024
1 parent 365be0f commit 79862fe
Show file tree
Hide file tree
Showing 29 changed files with 745 additions and 442 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Rust CI

on:
push:
pull_request:

env:
CARGO_TERM_COLOR: always

# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#concurrency.
# This will ensure that only one commit will be running tests at a time on each PR.
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
build:
strategy:
matrix:
rust: [ stable ]
os: [ ubuntu-latest ]

runs-on: ${{ matrix.os }}
steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-debug-${{ hashFiles('**/Cargo.toml') }}

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}

- name: Build
run: cargo +${{ matrix.rust }} build --features=${{ matrix.features }}

- name: Test
run: cargo +${{ matrix.rust }} test --features=${{ matrix.features }}

clippy:
runs-on: ubuntu-latest
needs: [ "build" ]
steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-debug-${{ hashFiles('**/Cargo.toml') }}

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: clippy

- name: Run clippy
run: cargo clippy -- -Dclippy::all

rustfmt:
runs-on: ubuntu-latest
needs: [ "build" ]
steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-debug-${{ hashFiles('**/Cargo.toml') }}

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: rustfmt

- name: Run fmt
run: cargo fmt --all -- --check
38 changes: 23 additions & 15 deletions 2024/01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ fn parse_input(input: &str) -> Input {
}

fn default_input() -> Input {
parse_input(include_input!(2024 / 01))
#[cfg(feature = "default-inputs")]
return parse_input(include_input!(2024 / 01));
#[cfg(not(feature = "default-inputs"))]
panic!("default-inputs feature not enabled");
}

fn part1((mut l, mut r): Input) -> i32 {
Expand Down Expand Up @@ -45,24 +48,29 @@ fn main() {
solution.cli()
}

#[ignore]
#[test]
fn default() {
let input = default_input();
assert_eq!(part1(input.clone()), 3246517);
assert_eq!(part2(input), 29379307);
}
#[cfg(test)]
mod tests {
use super::*;

#[ignore]
#[test]
fn default() {
let input = default_input();
assert_eq!(part1(input.clone()), 3246517);
assert_eq!(part2(input), 29379307);
}

#[test]
fn examples() {
let input = parse_input(
"3 4
#[test]
fn examples() {
let input = parse_input(
"3 4
4 3
2 5
1 3
3 9
3 3",
);
assert_eq!(part1(input.clone()), 11);
assert_eq!(part2(input.clone()), 31);
);
assert_eq!(part1(input.clone()), 11);
assert_eq!(part2(input.clone()), 31);
}
}
38 changes: 23 additions & 15 deletions 2024/02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ fn parse_input(input: &str) -> Input {
}

fn default_input() -> Input {
parse_input(include_input!(2024 / 02))
#[cfg(feature = "default-inputs")]
return parse_input(include_input!(2024 / 02));
#[cfg(not(feature = "default-inputs"))]
panic!("default-inputs feature not enabled");
}

fn part1(input: Input) -> i64 {
Expand Down Expand Up @@ -68,24 +71,29 @@ fn main() {
solution.cli()
}

#[ignore]
#[test]
fn default() {
let input = default_input();
assert_eq!(part1(input.clone()), 639);
assert_eq!(part2(input), 674);
}
#[cfg(test)]
mod tests {
use super::*;

#[ignore]
#[test]
fn default() {
let input = default_input();
assert_eq!(part1(input.clone()), 639);
assert_eq!(part2(input), 674);
}

#[test]
fn examples() {
let input = parse_input(
"7 6 4 2 1
#[test]
fn examples() {
let input = parse_input(
"7 6 4 2 1
1 2 7 8 9
9 7 6 2 1
1 3 2 4 5
8 6 4 4 1
1 3 6 7 9",
);
assert_eq!(part1(input.clone()), 2);
assert_eq!(part2(input), 4);
);
assert_eq!(part1(input.clone()), 2);
assert_eq!(part2(input), 4);
}
}
41 changes: 25 additions & 16 deletions 2024/03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ fn parse_input(input: &str) -> Input {
}

fn default_input() -> Input {
parse_input(include_input!(2024 / 03))
#[cfg(feature = "default-inputs")]
return parse_input(include_input!(2024 / 03));
#[cfg(not(feature = "default-inputs"))]
panic!("default-inputs feature not enabled");
}

fn part1(input: Input) -> i64 {
Expand All @@ -43,20 +46,26 @@ fn main() {
solution.cli()
}

#[ignore]
#[test]
fn default() {
let input = default_input();
assert_eq!(part1(input.clone()), 183669043);
assert_eq!(part2(input), 59097164);
}
#[cfg(test)]
mod tests {
use super::*;

#[ignore]
#[test]
fn default() {
let input = default_input();
assert_eq!(part1(input.clone()), 183669043);
assert_eq!(part2(input), 59097164);
}

#[test]
fn examples() {
let input =
parse_input("xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))");
assert_eq!(part1(input.clone()), 161);
let input =
parse_input("xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))");
assert_eq!(part2(input), 48);
#[test]
fn examples() {
let input =
parse_input("xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))");
assert_eq!(part1(input.clone()), 161);
let input = parse_input(
"xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))",
);
assert_eq!(part2(input), 48);
}
}
38 changes: 23 additions & 15 deletions 2024/04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ fn parse_input(input: &str) -> Input {
}

fn default_input() -> Input {
parse_input(include_input!(2024 / 04))
#[cfg(feature = "default-inputs")]
return parse_input(include_input!(2024 / 04));
#[cfg(not(feature = "default-inputs"))]
panic!("default-inputs feature not enabled");
}

fn part1(input: Input) -> i64 {
Expand Down Expand Up @@ -106,18 +109,22 @@ fn main() {
solution.cli()
}

#[ignore]
#[test]
fn default() {
let input = default_input();
assert_eq!(part1(input.clone()), 2569);
assert_eq!(part2(input), 1998);
}
#[cfg(test)]
mod tests {
use super::*;

#[ignore]
#[test]
fn default() {
let input = default_input();
assert_eq!(part1(input.clone()), 2569);
assert_eq!(part2(input), 1998);
}

#[test]
fn examples() {
let input = parse_input(
"MMMSXXMASM
#[test]
fn examples() {
let input = parse_input(
"MMMSXXMASM
MSAMXMSMSA
AMXSXMAAMM
MSAMASMSMX
Expand All @@ -127,7 +134,8 @@ SMSMSASXSS
SAXAMASAAA
MAMMMXMMMM
MXMXAXMASX",
);
assert_eq!(part1(input.clone()), 18);
assert_eq!(part2(input), 9);
);
assert_eq!(part1(input.clone()), 18);
assert_eq!(part2(input), 9);
}
}
38 changes: 23 additions & 15 deletions 2024/05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ fn parse_input(input: &str) -> Input {
}

fn default_input() -> Input {
parse_input(include_input!(2024 / 05))
#[cfg(feature = "default-inputs")]
return parse_input(include_input!(2024 / 05));
#[cfg(not(feature = "default-inputs"))]
panic!("default-inputs feature not enabled");
}

fn part1(input: Input) -> i32 {
Expand Down Expand Up @@ -83,18 +86,22 @@ fn main() {
solution.cli()
}

#[ignore]
#[test]
fn default() {
let input = default_input();
assert_eq!(part1(input.clone()), 4905);
assert_eq!(part2(input), 6204);
}
#[cfg(test)]
mod tests {
use super::*;

#[ignore]
#[test]
fn default() {
let input = default_input();
assert_eq!(part1(input.clone()), 4905);
assert_eq!(part2(input), 6204);
}

#[test]
fn examples() {
let input = parse_input(
"47|53
#[test]
fn examples() {
let input = parse_input(
"47|53
97|13
97|61
97|47
Expand Down Expand Up @@ -122,7 +129,8 @@ fn examples() {
75,97,47,61,53
61,13,29
97,13,75,29,47",
);
assert_eq!(part1(input.clone()), 143);
assert_eq!(part2(input), 123);
);
assert_eq!(part1(input.clone()), 143);
assert_eq!(part2(input), 123);
}
}
Loading

0 comments on commit 79862fe

Please sign in to comment.