108 lines
2.8 KiB
YAML
108 lines
2.8 KiB
YAML
name: test
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
paths:
|
|
- '2022/**'
|
|
- '2023/**'
|
|
- '2024/**'
|
|
- '2025/**'
|
|
- '2026/**'
|
|
- '.github/workflows/test.yaml'
|
|
- 'rustfmt.toml'
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
CARGO_AOC_VERSION: 0.3.8
|
|
|
|
jobs:
|
|
tests:
|
|
name: AoC ${{ matrix.year }}
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
year: [2022, 2023, 2024, 2025, 2026]
|
|
include:
|
|
- year: 2024
|
|
clippy_args: -D warnings
|
|
defaults:
|
|
run:
|
|
working-directory: ${{ matrix.year }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: get date
|
|
id: date
|
|
# AoC unlocks puzzles at 00:00 EST (05:00 UTC), so shift the date back 5 hours
|
|
run: |
|
|
echo "date=$(date -u -d '-5 hours' +%Y%m%d)" >> "$GITHUB_OUTPUT"
|
|
echo "week=$(date -u +%G-W%V)" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: cache rustup toolchains
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.rustup
|
|
key: rustup-${{ runner.os }}-${{ runner.arch }}-${{ steps.date.outputs.week }}
|
|
|
|
- name: setup toolchain
|
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
|
with:
|
|
# caches the cargo registry and the year's target dir
|
|
cache: true
|
|
cache-workspaces: ${{ matrix.year }}
|
|
components: clippy, rustfmt
|
|
toolchain: stable
|
|
rustflags: ""
|
|
|
|
- name: cache cargo-aoc
|
|
id: cargo-aoc
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.cargo/bin/cargo-aoc
|
|
key: cargo-aoc-${{ runner.os }}-${{ runner.arch }}-${{ env.CARGO_AOC_VERSION }}
|
|
|
|
- name: install cargo-aoc
|
|
if: steps.cargo-aoc.outputs.cache-hit != 'true'
|
|
run: cargo install --locked cargo-aoc --version "$CARGO_AOC_VERSION"
|
|
|
|
- name: Get cached inputs
|
|
id: inputs
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ${{ matrix.year }}/input
|
|
key: inputs-${{ matrix.year }}-${{ steps.date.outputs.date }}
|
|
restore-keys: inputs-${{ matrix.year }}-
|
|
|
|
- name: Get inputs from source
|
|
if: steps.inputs.outputs.cache-hit != 'true'
|
|
env:
|
|
AOC_SESSION: ${{ secrets.AOC_SESSION }}
|
|
AOC_DATE: ${{ steps.date.outputs.date }}
|
|
run: |
|
|
year=${{ matrix.year }}
|
|
max_day=25
|
|
if [ "$year" -ge 2025 ]; then max_day=12; fi
|
|
cargo aoc credentials "$AOC_SESSION"
|
|
for i in $(seq 1 "$max_day"); do
|
|
if [ "$AOC_DATE" -ge "$(printf '%s12%02d' "$year" "$i")" ]; then
|
|
cargo aoc input --year "$year" --day "$i"
|
|
fi
|
|
done
|
|
|
|
- name: cargo test
|
|
run: cargo test --lib
|
|
|
|
- name: rustfmt
|
|
run: cargo fmt --all -- --check
|
|
|
|
- name: clippy
|
|
run: cargo clippy --lib --tests -- ${{ matrix.clippy_args }}
|
|
if: always()
|
|
|
|
- name: full run
|
|
run: cargo run --release
|
|
if: always()
|