rust-training icon indicating copy to clipboard operation
rust-training copied to clipboard

setup xtask infra for cheatsheets

Open miguelraz opened this issue 1 year ago • 6 comments

Problem:

Making cheatsheets like "From Python to Rust" and friends is going to be a maintainability nightmare as training-materials grows, changes ownership, etc., over time. This was raised as a concern in #148 and this PR seeks to fix that.

Proposed solution:

Setup a xtask style workflow where we

  • call cargo xtask make-cheatsheet python at the root folder
  • scrape Markdown headers in SUMMARY..md and segment topics by Rust Fundamentals, Applied Rust and Advanced Rust
  • write out to src/python-cheatsheet.md if it doesn't exist
  • if it does exist, check that it in sync: all headers in python-cheatsheet.md are in the appropriate sections, in order, and none are missing.

The code is (I think) defensive to spare future pain for someone else looking at this code ~~(myself in a few months)~~.

This PR only sets up the infrastructure but doesn't add any cheatsheets themselves - I'll file a separate PR with a basic Julia cheatsheet once this lands to separate concerns.


Current functionality:
❯ cargo xtask make-cheatsheet python
   Compiling xtask v0.1.0 (C:\Users\mrg\work\rust-training\xtask)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.10s
     Running `target\debug\xtask.exe make-cheatsheet python`
Cheatsheat for python written at ./training-slides/src/python-cheatsheet.md

❯ cat .\training-slides\src\python-cheatsheet.md
# Rust Fundamentals
## Overview
## Installation
## Basic Types
## Control Flow
## Compound Types
## Ownership and Borrowing
## Error Handling
## Collections
## Iterators
## Imports and Modules
## Good Design Practices

# Applied Rust
## Methods and Traits
## Rust I/O Traits
## Generics
## Lifetimes
## Cargo Workspaces
## Heap Allocation (Box and Rc)
## Shared Mutability (Cell, RefCell)
## Thread Safety (Send/Sync, Arc, Mutex)
## Closures and the Fn/FnOnce/FnMut traits
## Spawning Threads and Scoped Threads

# Advanced Rust
## Advanced Strings
## Debugging Rust
## Dependency Management with Cargo
## Deref Coercions
## Design Patterns
## Documentation
## Drop, Panic and Abort
## Dynamic Dispatch
## Macros
## Property Testing
## Rust Projects Build Time
## Send and Sync
## Serde
## Testing
## The stdlib
## Using Cargo
## Using Types to encode State
## WASM

❯ cargo xtask make-cheatsheet python
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
     Running `target\debug\xtask.exe make-cheatsheet python`
File python-cheatsheet.md already exists - checking it's in sync
Neat! python-cheatsheet.md is in sync

rust-training on  xtask-cheatsheet [$?] via 🦀 v1.78.0
❯ cargo xtask test-cheatsheet python
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
     Running `target\debug\xtask.exe test-cheatsheet python`
Neat! python-cheatsheet.md is in sync

miguelraz avatar Jun 10 '24 22:06 miguelraz

Deploying ferrous-systems-rust-training with  Cloudflare Pages  Cloudflare Pages

Latest commit: cb162be
Status: ✅  Deploy successful!
Preview URL: https://73191fdd.ferrous-systems-rust-training.pages.dev
Branch Preview URL: https://xtask-cheatsheet.ferrous-systems-rust-training.pages.dev

View logs

Could we add a few words (here, or in a README) about how the cheatsheets work - to save having to read and understand the source code?

jonathanpallant avatar Jun 13 '24 08:06 jonathanpallant

Also, it needs a rebase on main to fix the CloudFlare CI failure, and some thought about the workspaces to fix the GHA CI failure.

jonathanpallant avatar Jun 13 '24 08:06 jonathanpallant

@jonathanpallant

  • added a README.md
  • rebased to main to have Cloudflare deploy passing
  • fixed workspace issue by adding a exclude = ["examples/"] array to the Cargo.toml and CI is happy

miguelraz avatar Jun 13 '24 14:06 miguelraz

OK, I think this tool makes sense. I had some minor points about the program itself, but I also think we should be running the unit tests in CI, and testing our cheat-sheets in CI.

jonathanpallant avatar Jul 01 '24 09:07 jonathanpallant

re-assign to me when you're ready, thanks!

jonathanpallant avatar Jul 03 '24 08:07 jonathanpallant

Force pushed to get rid of a pesky rebase muddying the history horribly.

miguelraz avatar Dec 24 '24 06:12 miguelraz

Should be ready for review again.

miguelraz avatar Dec 24 '24 06:12 miguelraz

There's quite a lot of code here, and coming to it fresh after vacation I lacked any real context. Some file-level comments explaining the purpose of the file and some function-level comments explaining the purpose of each function would be a useful addition.

jonathanpallant avatar Jan 06 '25 15:01 jonathanpallant

I'll write those in later today, good point.

miguelraz avatar Jan 06 '25 16:01 miguelraz

@jonathanpallant this feels ready for review again.

miguelraz avatar Jan 07 '25 02:01 miguelraz

I elected to push some changes rather than leave a bunch of review comments. Please do review the diff and let me know if you have any questions.

The final matter is deciding how we want CI to run this, to automatically check out cheatsheets. Ideally we'd have a cargo xtask test-cheatsheets which automatically tested all of them.

jonathanpallant avatar Jan 07 '25 09:01 jonathanpallant

All the comments being hoisted to a README make sense to me and the added level of doc comments is welcome, thanks!

I'm in favor of writing a cargo xtask test-all-cheatsheets.

miguelraz avatar Jan 07 '25 14:01 miguelraz

Resolved a small merge conflict by accepting the xtask target folder as part of .gitignore

miguelraz avatar Jan 07 '25 21:01 miguelraz

Ah, I noticed there's a corner case I haven't handled, I'm going to work on it for a bit.

Removing the review request for now.

miguelraz avatar Jan 08 '25 04:01 miguelraz