Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yamgent authored Dec 1, 2024
0 parents commit e1b981a
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/.idea
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "actual_inputs"]
path = actual_inputs
url = [email protected]:yamgent/advent-of-code-inputs.git
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "aoc_xxxx"
version = "0.1.0"
edition = "2021"

[dependencies]
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions actual_inputs
Submodule actual_inputs added at 70438f
45 changes: 45 additions & 0 deletions src/bin/empty/main.rs
Original file line number Diff line number Diff line change
@@ -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), "");
}
}
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

0 comments on commit e1b981a

Please sign in to comment.