Skip to content

Commit c06591c

Browse files
authored
Fix docs publish (#288)
1 parent 3f0b276 commit c06591c

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

.github/scripts/build-pages.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
use std::env::var;
2+
use std::fs;
3+
use std::io::{Read, Write};
4+
use std::os::unix::net::UnixStream;
5+
use std::os::unix::prelude::*;
6+
use std::process::{Command, Stdio};
7+
8+
fn main() {
9+
let slug = var("BUILD_REPOSITORY_ID").unwrap();
10+
let key = var("GITHUB_DEPLOY_KEY").unwrap();
11+
12+
let socket = "/tmp/.github-deploy-socket";
13+
run(Command::new("ssh-agent").arg("-a").arg(&socket));
14+
while UnixStream::connect(&socket).is_err() {
15+
std::thread::sleep(std::time::Duration::from_millis(5));
16+
}
17+
18+
let mut decode = Command::new("base64")
19+
.arg("-d")
20+
.stdin(Stdio::piped())
21+
.stdout(Stdio::piped())
22+
.spawn()
23+
.unwrap();
24+
decode
25+
.stdin
26+
.take()
27+
.unwrap()
28+
.write_all(&key.as_bytes())
29+
.unwrap();
30+
let mut key = Vec::new();
31+
decode.stdout.take().unwrap().read_to_end(&mut key).unwrap();
32+
decode.wait().unwrap();
33+
34+
let path = "_the_key";
35+
fs::write(&path, key).unwrap();
36+
fs::set_permissions(&path, fs::Permissions::from_mode(0o600)).unwrap();
37+
run(Command::new("ssh-add")
38+
.arg(&path)
39+
.env("SSH_AUTH_SOCK", &socket));
40+
fs::remove_file(&path).unwrap();
41+
42+
let sha = var("BUILD_SOURCEVERSION").unwrap();
43+
let msg = format!("Deploy {sha} to gh-pages");
44+
45+
drop(fs::remove_dir_all(".git"));
46+
run(Command::new("git").arg("init"));
47+
run(Command::new("git")
48+
.arg("config")
49+
.arg("user.name")
50+
.arg("Deploy from CI"));
51+
run(Command::new("git").arg("config").arg("user.email").arg(""));
52+
run(Command::new("git").arg("add").arg("."));
53+
run(Command::new("git").arg("commit").arg("-m").arg(&msg));
54+
run(Command::new("git")
55+
.arg("push")
56+
.arg(format!("[email protected]:{}", slug))
57+
.arg("master:gh-pages")
58+
.env("GIT_SSH_COMMAND", "ssh -o StrictHostKeyChecking=no")
59+
.env("SSH_AUTH_SOCK", &socket)
60+
.arg("-f"));
61+
}
62+
63+
fn run(cmd: &mut Command) {
64+
println!("{cmd:?}");
65+
let status = cmd.status().unwrap();
66+
assert!(status.success());
67+
}

.github/workflows/rust-ci.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,19 @@ jobs:
177177
runs-on: ubuntu-22.04
178178
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
179179
steps:
180+
- uses: actions/checkout@v4
180181
- name: Download book
181182
uses: actions/download-artifact@v4
182183
with:
183184
name: doc-book
184-
- name: Assemble gh-pages
185-
run: |
186-
mv doc-book gh-pages
185+
path: gh-pages
187186
# If this is a push to the main branch push to the `gh-pages` using a
188187
# deploy key. Note that a deploy key is necessary for now because otherwise
189188
# using the default token for github actions doesn't actually trigger a page
190189
# rebuild.
191190
- name: Push to gh-pages
192191
# Uses a rust script to setup and push to the gh-pages branch
193-
run: curl -LsSf https://git.io/fhJ8n | rustc - && (cd gh-pages && ../rust_out)
192+
run: rustc .github/scripts/build-pages.rs && (cd gh-pages && ../build-pages)
194193
env:
195194
GITHUB_DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
196195
BUILD_REPOSITORY_ID: ${{ github.repository }}

0 commit comments

Comments
 (0)