Skip to content

Commit

Permalink
Add GitHub Actions workflow to build and deploy documentation. (these…
Browse files Browse the repository at this point in the history
  • Loading branch information
apogeeoak authored Jun 26, 2021
1 parent 0793ea3 commit ea7447a
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 52 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Documentation

on: [push, pull_request]

jobs:
documentation:
name: Build and deploy
runs-on: ubuntu-latest
steps:
- name: Checkout repository and submodules
uses: actions/checkout@v2
with:
submodules: recursive

- name: Cache build artifacts
uses: actions/cache@v2
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
${{ runner.os }}-
# Remove documentation directory cache before publishing.
- name: Clean source documentation directory before publishing
if: github.event_name == 'push' && github.ref == 'refs/heads/theseus_main'
run: cargo clean --doc

- name: Install mdbook
uses: peaceiris/actions-mdbook@v1
with:
mdbook-version: '0.4.10'

- name: Install mdbook-linkcheck
run: |
version="v0.7.4"
file="mdbook-linkcheck"
zip_file="mdbook-linkcheck.${version}.x86_64-unknown-linux-gnu.zip"
curl -sSL https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/download/${version}/${zip_file} --output ${zip_file}
unzip -d bin ${zip_file} ${file}
chmod +x bin/${file}
rm ${zip_file}
echo "$(pwd)/bin" >> ${GITHUB_PATH}
- name: Report versions
run: |
rustc --version --verbose
mdbook --version
mdbook-linkcheck --version
- name: Build book
run: make book

- name: Build source documentation
run: make doc

# Move build artifacts to publish directory on push to main branch.
- name: Move build artifacts
if: github.event_name == 'push' && github.ref == 'refs/heads/theseus_main'
run: |
rm -rf ./github_pages/book
rm -rf ./github_pages/doc
mv ./build/book/html/ ./github_pages/book/
mv ./build/doc/ ./github_pages/doc/
# Deploy on push to main branch.
- name: Deploy
if: github.event_name == 'push' && github.ref == 'refs/heads/theseus_main'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: ${{ github.event.head_commit.message }}
publish_branch: github_pages
publish_dir: ./github_pages
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ target/
# Build directory
build/

# Generated documentation, used for GitHub Pages
github_pages/book/
github_pages/doc/

# patched GDB directory
/rust-os-gdb/

Expand Down
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

52 changes: 30 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ APP_CRATE_NAMES += $(EXTRA_APP_CRATE_NAMES)
libtheseus \
simd_personality_sse build_sse simd_personality_avx build_avx \
$(assembly_source_files) \
gdb doc docs view-doc view-docs book view-book
gdb doc docs view-doc view-docs book view-book clean-doc


### If we compile for SIMD targets newer than SSE (e.g., AVX or newer),
Expand Down Expand Up @@ -334,10 +334,10 @@ $(THESEUS_CARGO_BIN): $(THESEUS_CARGO)/Cargo.* $(THESEUS_CARGO)/src/*



### Removes all build files
### Removes all built source files
clean:
cargo clean
@rm -rf build
@rm -rf $(BUILD_DIR)



Expand Down Expand Up @@ -454,20 +454,19 @@ preserve_old_modules:
###################################################################################################

## The output directory for source-level documentation.
DOC_BUILD := $(BUILD_DIR)/doc
## The top-level (root) documentation file built by `rustdoc` (`cargo doc`).
RUSTDOC_OUT := $(DOC_BUILD)/___Theseus_Crates___/index.html
RUSTDOC_OUT := $(BUILD_DIR)/doc
RUSTDOC_OUT_FILE := $(RUSTDOC_OUT)/___Theseus_Crates___/index.html

## Builds Theseus's source-level documentation for all Rust crates except applications.
## The entire project is built as normal using the `cargo doc` command.
## The entire project is built as normal using the `cargo doc` command (`rustdoc` under the hood).
docs: doc
doc: check_rustc
@cargo doc --all --no-deps $(addprefix --exclude , $(APP_CRATE_NAMES))
@cargo doc --workspace --no-deps $(addprefix --exclude , $(APP_CRATE_NAMES))
@rustdoc --output target/doc --crate-name "___Theseus_Crates___" $(ROOT_DIR)/kernel/_doc_root.rs
@rm -rf $(DOC_BUILD)
@mkdir -p $(DOC_BUILD)
@cp -rf target/doc $(BUILD_DIR)/
@echo -e "\nDocumentation is now available at: \"$(RUSTDOC_OUT)\"."
@rm -rf $(RUSTDOC_OUT)
@mkdir -p $(RUSTDOC_OUT)
@cp -rf target/doc/. $(RUSTDOC_OUT)
@echo -e "\nTheseus source docs are now available at: \"$(RUSTDOC_OUT_FILE)\"."


## Opens the documentation root in the system's default browser.
Expand All @@ -476,39 +475,46 @@ view-docs: view-doc
view-doc: doc
@echo -e "Opening documentation index file in your browser..."
ifneq ($(IS_WSL), )
wslview "$(shell realpath --relative-to="$(ROOT_DIR)" "$(RUSTDOC_OUT)")" &
wslview "$(shell realpath --relative-to="$(ROOT_DIR)" "$(RUSTDOC_OUT_FILE)")" &
else
@xdg-open $(RUSTDOC_OUT) > /dev/null 2>&1 || open $(RUSTDOC_OUT) &
@xdg-open $(RUSTDOC_OUT_FILE) > /dev/null 2>&1 || open $(RUSTDOC_OUT_FILE) &
endif


### The location of Theseus's book-style documentation.
BOOK_DIR := $(ROOT_DIR)/book
BOOK_OUT := $(BOOK_DIR)/book/html/index.html
### The locations of Theseus's book-style documentation.
BOOK_SRC := $(ROOT_DIR)/book
BOOK_OUT := $(BUILD_DIR)/book
BOOK_OUT_FILE := $(BOOK_OUT)/html/index.html

### Builds the Theseus book-style documentation using `mdbook`.
book: $(wildcard $(BOOK_DIR)/src/*) $(BOOK_DIR)/book.toml
book: $(wildcard $(BOOK_SRC)/src/*) $(BOOK_SRC)/book.toml
ifneq ($(shell mdbook --version > /dev/null 2>&1 && echo $$?), 0)
@echo -e "\nError: please install mdbook:"
@echo -e " cargo +stable install mdbook --force"
@echo -e "You can optionally install linkcheck too:"
@echo -e " cargo +stable install mdbook-linkcheck --force"
@exit 1
endif
@(cd $(BOOK_DIR) && mdbook build)
@echo -e "\nThe Theseus Book is now available at \"$(BOOK_OUT)\"."
@mdbook build $(BOOK_SRC) -d $(BOOK_OUT)
@echo -e "\nThe Theseus Book is now available at \"$(BOOK_OUT_FILE)\"."


### Opens the Theseus book.
view-book: book
@echo -e "Opening the Theseus book in your browser..."
ifneq ($(IS_WSL), )
wslview "$(shell realpath --relative-to="$(ROOT_DIR)" "$(BOOK_OUT)")" &
wslview "$(shell realpath --relative-to="$(ROOT_DIR)" "$(BOOK_OUT_FILE)")" &
else
@xdg-open $(BOOK_OUT) > /dev/null 2>&1 || open $(BOOK_OUT) &
@xdg-open $(BOOK_OUT_FILE) > /dev/null 2>&1 || open $(BOOK_OUT_FILE) &
endif


### Removes all built documentation
clean-doc:
@cargo clean --doc
@rm -rf $(RUSTDOC_OUT) $(BOOK_OUT)


### The primary documentation for this makefile itself.
help:
@echo -e "\nThe following make targets are available:"
Expand Down Expand Up @@ -589,6 +595,8 @@ help:
@echo -e "\t Builds the Theseus book using the mdbook Markdown tool."
@echo -e " view-book:"
@echo -e "\t Builds the Theseus book and then opens it in your default browser."
@echo -e " clean-doc:"
@echo -e "\t Remove all generated documentation files."
@echo ""


Expand Down
1 change: 1 addition & 0 deletions github_pages/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Specify any content here to exclude it from GitHub Pages.
9 changes: 9 additions & 0 deletions github_pages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Published Documentation

This directory contains files used to publish Theseus's documentation online, which is realized using GitHub Pages at [https://theseus-os.github.io/Theseus](https://theseus-os.github.io/Theseus).

Any file in this directory is included in the published output (e.g., `index.html`), unless it is explicitly added to the local `.gitignore` file here.

## Automatically Generated Directories

When building Theseus's book and source code documentation (rustdoc) automtically using GitHub Actions, the `book/` and `doc/` directories are generated here. Those directories are ignored by git in the top-level `.gitignore` file.
12 changes: 12 additions & 0 deletions github_pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en-US">

<h1>Theseus Documentation</h1>

<p>Welcome to the online docs for Theseus! There are two kinds of docs available: </p>
<ul>
<li> <a href="./doc/___Theseus_Crates___/index.html">Source-level documentation</a> (rustdoc) </li>
<li> The <a href="./book/index.html">Theseus Book</a>, a higher-level overview of Theseus design concepts. </li>
</ul>

<p>You can also check out the main Theseus <a href="https://github.com/theseus-os/Theseus/blob/theseus_main/README.md">README</a> file for a quick start guide. </p>

0 comments on commit ea7447a

Please sign in to comment.