Skip to content

Commit a43e047

Browse files
committed
Copy book directory in xtask release step
1 parent 19d2ea0 commit a43e047

File tree

4 files changed

+38
-29
lines changed

4 files changed

+38
-29
lines changed

docs/book/src/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ The LSP allows various code editors, like VS Code, Emacs or Vim, to
99
implement semantic features like completion or goto definition by
1010
talking to an external language server process.
1111

12-
To improve this document, send a pull request:
13-
[https://github.com/rust-analyzer/…​/manual.adoc](https://github.com/rust-lang/rust-analyzer/blob/master/docs/user/manual.adoc)
12+
To improve this document, send a pull request:
13+
[https://github.com/rust-lang/rust-analyzer](https://github.com/rust-lang/rust-analyzer/blob/docs/book/README.md)
1414

15-
The manual is written in [AsciiDoc](https://asciidoc.org) and includes
15+
The manual is written in markdown and includes
1616
some extra files which are generated from the source code. Run
17-
`cargo test` and `cargo test -p xtask` to create these and then
18-
`asciidoctor manual.adoc` to create an HTML copy.
17+
`cargo test` and `cargo test -p xtask` to create these.
1918

2019
If you have questions about using rust-analyzer, please ask them in the
2120
[“IDEs and Editors”](https://users.rust-lang.org/c/ide/14) topic of Rust

docs/dev/style.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ Use `anyhow::format_err!` rather than `anyhow::anyhow`.
873873
**Rationale:** consistent, boring, avoids stuttering.
874874

875875
There's no specific guidance on the formatting of error messages, see [anyhow/#209](https://github.com/dtolnay/anyhow/issues/209).
876-
Do not end error and context messages with `.` though.
876+
Do not end error and context messages with `.` though.
877877

878878
## Early Returns
879879

@@ -1172,7 +1172,7 @@ MergeBehavior::Last => {
11721172
**Rationale:** writing a sentence (or maybe even a paragraph) rather just "a comment" creates a more appropriate frame of mind.
11731173
It tricks you into writing down more of the context you keep in your head while coding.
11741174

1175-
For `.md` and `.adoc` files, prefer a sentence-per-line format, don't wrap lines.
1175+
For `.md` files prefer a sentence-per-line format, don't wrap lines.
11761176
If the line is too long, you want to split the sentence in two :-)
11771177

11781178
**Rationale:** much easier to edit the text and read the diff, see [this link](https://asciidoctor.org/docs/asciidoc-recommended-practices/#one-sentence-per-line).

xtask/src/release.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod changelog;
22

3+
use std::path::Path;
34
use std::process::{Command, Stdio};
45
use std::thread;
56
use std::time::Duration;
@@ -29,7 +30,7 @@ impl flags::Release {
2930
cmd!(sh, "git push --force").run()?;
3031
}
3132

32-
// Generates bits of manual.adoc.
33+
// Generates bits of the book.
3334
codegen::diagnostics_docs::generate(false);
3435
codegen::assists_doc_tests::generate(false);
3536

@@ -53,31 +54,38 @@ impl flags::Release {
5354
.max()
5455
.unwrap_or_default();
5556

56-
for adoc in [
57-
"manual.adoc",
58-
"generated_assists.adoc",
59-
"generated_config.adoc",
60-
"generated_diagnostic.adoc",
61-
"generated_features.adoc",
62-
] {
63-
let src = project_root().join("./docs/user/").join(adoc);
64-
let dst = website_root.join(adoc);
65-
66-
let contents = sh.read_file(src)?;
67-
sh.write_file(dst, contents)?;
68-
}
57+
let book = project_root().join("./docs/book/");
58+
let dst = website_root.join("manual");
59+
copy_dir_all(sh, &book, &dst)?;
6960

7061
let tags = cmd!(sh, "git tag --list").read()?;
7162
let prev_tag = tags.lines().filter(|line| is_release_tag(line)).last().unwrap();
7263

73-
let contents = changelog::get_changelog(sh, changelog_n, &commit, prev_tag, &today)?;
74-
let path = changelog_dir.join(format!("{today}-changelog-{changelog_n}.adoc"));
75-
sh.write_file(path, contents)?;
76-
64+
if let Some(contents) =
65+
changelog::get_changelog(sh, changelog_n, &commit, prev_tag, &today)?
66+
{
67+
let path = changelog_dir.join(format!("{today}-changelog-{changelog_n}.adoc"));
68+
sh.write_file(path, contents)?;
69+
}
7770
Ok(())
7871
}
7972
}
8073

74+
fn copy_dir_all(sh: &Shell, src: &Path, dst: &Path) -> xshell::Result<()> {
75+
sh.create_dir(dst)?;
76+
for path in sh.read_dir(src)? {
77+
let ty = std::fs::metadata(&path).unwrap().file_type();
78+
let Some(name) = path.file_name() else { continue };
79+
let dst = &dst.join(name);
80+
if ty.is_dir() {
81+
copy_dir_all(sh, &path, dst)?;
82+
} else {
83+
sh.copy_file(path, dst)?;
84+
}
85+
}
86+
Ok(())
87+
}
88+
8189
// git sync implementation adapted from https://github.com/rust-lang/miri/blob/62039ac/miri-script/src/commands.rs
8290
impl flags::RustcPull {
8391
pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> {

xtask/src/release/changelog.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::fmt::Write;
22
use std::{env, iter};
33

4-
use anyhow::bail;
54
use xshell::{cmd, Shell};
65

76
pub(crate) fn get_changelog(
@@ -10,10 +9,13 @@ pub(crate) fn get_changelog(
109
commit: &str,
1110
prev_tag: &str,
1211
today: &str,
13-
) -> anyhow::Result<String> {
12+
) -> anyhow::Result<Option<String>> {
1413
let token = match env::var("GITHUB_TOKEN") {
1514
Ok(token) => token,
16-
Err(_) => bail!("Please obtain a personal access token from https://github.com/settings/tokens and set the `GITHUB_TOKEN` environment variable."),
15+
Err(_) => {
16+
eprintln!("GITHUB_TOKEN` not set, skipping changelog generation. Please obtain a personal access token from https://github.com/settings/tokens and set the `GITHUB_TOKEN` environment variable.");
17+
return Ok(None);
18+
}
1719
};
1820

1921
let git_log = cmd!(sh, "git log {prev_tag}..HEAD --reverse").read()?;
@@ -106,7 +108,7 @@ Release: release:{today}[] (`TBD`)
106108
{others}
107109
"
108110
);
109-
Ok(contents)
111+
Ok(Some(contents))
110112
}
111113

112114
#[derive(Clone, Copy)]

0 commit comments

Comments
 (0)