From 0af1acd6e28eb88ccf1c3134b34befd57a190e26 Mon Sep 17 00:00:00 2001 From: makspll Date: Tue, 25 Mar 2025 22:22:54 +0000 Subject: [PATCH 1/4] fix: mdbook preprocessor links not taking into account root url --- .../mdbook_lad_preprocessor/src/lib.rs | 28 ++++++++++++++++++- .../tests/books/example_ladfile/book.toml | 2 +- docs/book.toml | 1 + 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/lad_backends/mdbook_lad_preprocessor/src/lib.rs b/crates/lad_backends/mdbook_lad_preprocessor/src/lib.rs index 4304945d20..bacb7a2bdb 100644 --- a/crates/lad_backends/mdbook_lad_preprocessor/src/lib.rs +++ b/crates/lad_backends/mdbook_lad_preprocessor/src/lib.rs @@ -10,6 +10,24 @@ mod argument_visitor; mod markdown; mod sections; +#[derive(Debug)] +struct Options { + pub root: String, +} + +impl From<&PreprocessorContext> for Options { + fn from(context: &PreprocessorContext) -> Self { + let root = context + .config + .get_preprocessor("lad-preprocessor") + .and_then(|t| t.get("root")) + .and_then(|v| v.as_str()) + .map(|s| s.to_owned()) + .unwrap_or_default(); + Options { root } + } +} + const LAD_EXTENSION: &str = "lad.json"; pub struct LADPreprocessor; @@ -31,6 +49,7 @@ impl LADPreprocessor { /// and `chapter_index` is the index of the chapter among its siblings. fn process_lad_chapter( _context: &PreprocessorContext, + options: &Options, chapter: &mdbook::book::Chapter, parent: Option<&mdbook::book::Chapter>, chapter_index: usize, @@ -45,9 +64,11 @@ impl LADPreprocessor { let parent_path = parent .and_then(|p| p.path.clone()) - .unwrap_or_default() + .unwrap_or_else(|| options.root.clone().into()) .with_extension(""); + log::debug!("Parent path: {:?}", parent_path); + let new_chapter = Section::new( parent_path, &ladfile, @@ -75,6 +96,9 @@ impl Preprocessor for LADPreprocessor { mut book: mdbook::book::Book, ) -> mdbook::errors::Result { let mut errors = Vec::new(); + let options = Options::from(context); + + log::debug!("Options: {:?}", options); // first replace children in parents book.for_each_mut(|item| { @@ -89,6 +113,7 @@ impl Preprocessor for LADPreprocessor { if LADPreprocessor::is_lad_file(chapter) { match LADPreprocessor::process_lad_chapter( context, + &options, chapter, Some(parent), idx, @@ -122,6 +147,7 @@ impl Preprocessor for LADPreprocessor { } let new_chapter = match LADPreprocessor::process_lad_chapter( context, + &options, chapter, None, chapter diff --git a/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/book.toml b/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/book.toml index 0620453489..8c84c8e7f9 100644 --- a/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/book.toml +++ b/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/book.toml @@ -8,6 +8,6 @@ description = "Documentation for the Bevy Scripting library" [preprocessor.lad-preprocessor] - +root = "root" [output.markdown] diff --git a/docs/book.toml b/docs/book.toml index b347b4786a..6728e0f0ee 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -16,3 +16,4 @@ enable = true level = 1 [preprocessor.lad-preprocessor] +root = "bevy_mod_scripting" From ad717967bc588a1e157729206a54360f8bee2c8c Mon Sep 17 00:00:00 2001 From: Maksymilian Mozolewski Date: Wed, 26 Mar 2025 00:57:41 +0000 Subject: [PATCH 2/4] Update bencher_on_pr_or_fork_upload.yml --- .github/workflows/bencher_on_pr_or_fork_upload.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/bencher_on_pr_or_fork_upload.yml b/.github/workflows/bencher_on_pr_or_fork_upload.yml index 38442c96ec..3c3204d701 100644 --- a/.github/workflows/bencher_on_pr_or_fork_upload.yml +++ b/.github/workflows/bencher_on_pr_or_fork_upload.yml @@ -5,6 +5,8 @@ on: workflows: [Run benchmarks on PR] types: [completed] +permissions: write-all + jobs: track_fork_pr_branch: if: github.event.workflow_run.conclusion == 'success' From 746e299f74ffacedb0133715d99af9c458637b28 Mon Sep 17 00:00:00 2001 From: makspll Date: Wed, 26 Mar 2025 09:06:28 +0000 Subject: [PATCH 3/4] add write perms to bencher token --- .github/workflows/bencher_on_pr_or_fork_upload.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bencher_on_pr_or_fork_upload.yml b/.github/workflows/bencher_on_pr_or_fork_upload.yml index 3c3204d701..c9c07e7ce7 100644 --- a/.github/workflows/bencher_on_pr_or_fork_upload.yml +++ b/.github/workflows/bencher_on_pr_or_fork_upload.yml @@ -49,6 +49,6 @@ jobs: --testbed linux-gha \ --err \ --adapter rust_criterion \ - --github-actions '${{ secrets.GITHUB_TOKEN }}' \ + --github-actions '${{ secrets.BENCHER_GITHUB_TOKEN }}' \ --ci-number "$PR_NUMBER" \ --file "$BENCHMARK_RESULTS" \ No newline at end of file From 6eefb7f04a119272bd98bf28c74bb84bb451ca3a Mon Sep 17 00:00:00 2001 From: makspll Date: Wed, 26 Mar 2025 09:20:27 +0000 Subject: [PATCH 4/4] revert to standard workflow token --- .github/workflows/bencher_on_pr_or_fork_upload.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bencher_on_pr_or_fork_upload.yml b/.github/workflows/bencher_on_pr_or_fork_upload.yml index c9c07e7ce7..3c3204d701 100644 --- a/.github/workflows/bencher_on_pr_or_fork_upload.yml +++ b/.github/workflows/bencher_on_pr_or_fork_upload.yml @@ -49,6 +49,6 @@ jobs: --testbed linux-gha \ --err \ --adapter rust_criterion \ - --github-actions '${{ secrets.BENCHER_GITHUB_TOKEN }}' \ + --github-actions '${{ secrets.GITHUB_TOKEN }}' \ --ci-number "$PR_NUMBER" \ --file "$BENCHMARK_RESULTS" \ No newline at end of file