-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Comment PRs with updated schedule information (#1576)
This adds a GH action to add a comment to every PR giving the updated course schedule with the PR merged. To accomplish this, I broke `mdbook-course` into a library and two binaries, allowing the mdbook content to be loaded dynamically outside of an `mdbook build` invocation. I think this is a net benefit, but possible improvements include: * diffing the "before" and "after" schedules and only making the comment when those are not the same (or replacing the comment with "no schedule changes") * including per-segment timing behind `<details>` (with a few minutes effort I couldn't get this to play nicely with the markdown lists) --------- Co-authored-by: Martin Geisler <[email protected]>
- Loading branch information
Showing
15 changed files
with
151 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: "Course Schedule Updates" | ||
on: | ||
pull_request: | ||
paths: | ||
- "src/**.md" | ||
|
||
jobs: | ||
course-schedule: | ||
runs-on: ubuntu-latest | ||
name: Make Course Schedule Comment | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Rust cache | ||
uses: ./.github/workflows/setup-rust-cache | ||
|
||
- name: Generate Schedule | ||
run: cargo run -p mdbook-course --bin course-schedule > course-schedule.md | ||
|
||
- name: Comment PR | ||
uses: thollander/actions-comment-pull-request@v2 | ||
with: | ||
filePath: course-schedule.md | ||
comment_tag: course-schedule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use mdbook::MDBook; | ||
use mdbook_course::course::{Course, Courses}; | ||
use mdbook_course::markdown::duration; | ||
|
||
fn main() { | ||
pretty_env_logger::init(); | ||
let root_dir = "."; | ||
let mdbook = MDBook::load(root_dir).expect("Unable to load the book"); | ||
let (courses, _) = Courses::extract_structure(mdbook.book) | ||
.expect("Unable to extract course structure"); | ||
|
||
println!("## Course Schedule"); | ||
println!("With this pull request applied, the course schedule is as follows:"); | ||
for course in &courses { | ||
print_summary(course); | ||
} | ||
} | ||
|
||
fn timediff(actual: u64, target: u64, slop: u64) -> String { | ||
if actual > target + slop { | ||
format!( | ||
"{} (\u{23f0} *{} too long*)", | ||
duration(actual), | ||
duration(actual - target), | ||
) | ||
} else if actual < target - slop { | ||
format!("{}: ({} short)", duration(actual), duration(target - actual),) | ||
} else { | ||
format!("{}", duration(actual)) | ||
} | ||
} | ||
|
||
fn print_summary(course: &Course) { | ||
if course.target_minutes() == 0 { | ||
return; | ||
} | ||
println!("### {}", course.name); | ||
println!("_{}_", timediff(course.minutes(), course.target_minutes(), 15)); | ||
|
||
for session in course { | ||
println!( | ||
"* {} - _{}_", | ||
session.name, | ||
timediff(session.minutes(), session.target_minutes(), 5) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
pub mod course; | ||
pub mod frontmatter; | ||
pub mod markdown; | ||
pub mod replacements; | ||
pub mod timing_info; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
--- | ||
session: Day 1 Afternoon | ||
target_minutes: 180 | ||
--- | ||
|
||
# Welcome Back | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
minutes: 5 | ||
course: Fundamentals | ||
session: Day 1 Morning | ||
target_minutes: 180 | ||
--- | ||
|
||
# Welcome to Day 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
--- | ||
session: Day 2 Afternoon | ||
target_minutes: 180 | ||
--- | ||
|
||
# Welcome Back | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
minutes: 3 | ||
course: Fundamentals | ||
session: Day 2 Morning | ||
target_minutes: 180 | ||
--- | ||
|
||
# Welcome to Day 2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
--- | ||
session: Day 3 Afternoon | ||
target_minutes: 180 | ||
--- | ||
|
||
# Welcome Back | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
minutes: 3 | ||
course: Fundamentals | ||
session: Day 3 Morning | ||
target_minutes: 180 | ||
--- | ||
|
||
# Welcome to Day 3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
--- | ||
session: Day 4 Afternoon | ||
target_minutes: 180 | ||
--- | ||
|
||
# Welcome Back | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
minutes: 3 | ||
course: Fundamentals | ||
session: Day 4 Morning | ||
target_minutes: 180 | ||
--- | ||
|
||
# Welcome to Day 4 | ||
|