From e1b981a1e40f23c764eebcaa1f817ce3cb27f1b6 Mon Sep 17 00:00:00 2001 From: Maurice Wangleng Tan Date: Sun, 1 Dec 2024 11:43:32 +0800 Subject: [PATCH] Initial commit --- .github/workflows/ci.yml | 78 ++++++++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ .gitmodules | 3 ++ Cargo.lock | 7 ++++ Cargo.toml | 6 ++++ README.md | 7 ++++ actual_inputs | 1 + src/bin/empty/main.rs | 45 +++++++++++++++++++++++ src/lib.rs | 14 ++++++++ src/main.rs | 3 ++ 10 files changed, 166 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 README.md create mode 160000 actual_inputs create mode 100644 src/bin/empty/main.rs create mode 100644 src/lib.rs create mode 100644 src/main.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6992d8c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,78 @@ +name: Tests and Lints + +on: + pull_request: + push: + branches: + - main + +jobs: + test: + strategy: + matrix: + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + token: ${{ secrets.INPUT_REPO_TOKEN }} + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.toml') }} + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + - name: Build & run tests + run: cargo test + all-doc-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + token: ${{ secrets.INPUT_REPO_TOKEN }} + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ubuntu-latest-cargo-all-doc-tests-${{ hashFiles('**/Cargo.toml') }} + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + - name: Run doc tests with all features (this also compiles README examples) + run: cargo test --doc --all-features + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + token: ${{ secrets.INPUT_REPO_TOKEN }} + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ubuntu-latest-cargo-lint-${{ hashFiles('**/Cargo.toml') }} + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: rustfmt, clippy + - name: Run clippy + run: cargo clippy --workspace --all-targets --all-features -- -Dwarnings + - name: Check format + run: cargo fmt --all -- --check diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d81f12e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +/.idea diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9ebf5ca --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "actual_inputs"] + path = actual_inputs + url = git@github.com:yamgent/advent-of-code-inputs.git diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..8999826 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aoc_xxxx" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..c583f96 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "aoc_xxxx" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/README.md b/README.md new file mode 100644 index 0000000..423cfb4 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# advent-of-code-xxxx-rust + +1. Clone template +2. Replace all `xxxx` with current year (do not accidentally replace content inside `actual_inputs` folder!) +3. Update the `src/bin/empty/main.rs` `include_str!()` macro to use the correct year. +4. Add `INPUT_REPO_TOKEN` secret with access to `actual_inputs` folder so that CI can access the inputs + * Just "Contents - Read-only" access for the input repo is sufficient diff --git a/actual_inputs b/actual_inputs new file mode 160000 index 0000000..70438fb --- /dev/null +++ b/actual_inputs @@ -0,0 +1 @@ +Subproject commit 70438fb7648dd89795028dece525cd33cec46a0d diff --git a/src/bin/empty/main.rs b/src/bin/empty/main.rs new file mode 100644 index 0000000..50c8edd --- /dev/null +++ b/src/bin/empty/main.rs @@ -0,0 +1,45 @@ +const ACTUAL_INPUT: &str = include_str!("../../../actual_inputs/2015/01/input.txt"); + +fn p1(input: &str) -> String { + let _input = input.trim(); + "".to_string() +} + +fn p2(input: &str) -> String { + let _input = input.trim(); + "".to_string() +} + +fn main() { + println!("{}", p1(ACTUAL_INPUT)); + println!("{}", p2(ACTUAL_INPUT)); +} + +#[cfg(test)] +mod tests { + use super::*; + + const SAMPLE_INPUT: &str = r""; + + #[test] + fn test_p1_sample() { + assert_eq!(p1(SAMPLE_INPUT), ""); + } + + #[test] + #[ignore = "not yet implemented"] + fn test_p1_actual() { + assert_eq!(p1(ACTUAL_INPUT), ""); + } + + #[test] + fn test_p2_sample() { + assert_eq!(p2(SAMPLE_INPUT), ""); + } + + #[test] + #[ignore = "not yet implemented"] + fn test_p2_actual() { + assert_eq!(p2(ACTUAL_INPUT), ""); + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..b93cf3f --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}