Skip to content

Commit

Permalink
Deploy several documentations
Browse files Browse the repository at this point in the history
This PR adds the ability to deploy several documentations of Alt-Ergo.
Basically, we push the documentation of the dev version in `/dev` on
gh-pages if we push on `next`.
  • Loading branch information
Halbaroth committed Jul 22, 2024
1 parent 6f843ce commit 05fc660
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 375 deletions.
144 changes: 26 additions & 118 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -1,153 +1,61 @@
name: Documentation

# This workflow is divided in 3 jobs, ocaml_docs, sphinx_docs, deploy_docs.
# - The ocaml_docs build the ocaml documentation, it runs for every push,
# if it fails no more work is done
# - The sphinx_docs job build the sphinx documentation, it runs only if a PR
# is open. if it fails no more work is done
# - deploy_docs only run on the next branch when code is pushed. It retrieve
# the ocaml and sphinx documentation and deploy them on the gh-pages branch
name: Build documentation

on: [push, pull_request]

env:
OCAML_DEFAULT_VERSION: 4.10.0
OCAML_DEFAULT_VERSION: 4.14.2
# Add OPAMYES=true to the environment, this is usefill to replace `-y` option
# in any opam call
OPAMYES: true

jobs:
# For any push and PR, build the documentation from the ocaml comments
# If this build fails, the documentation workflow stops
# If it succeeds, an artifact is made with the generated documentation
# (html format only). This artifact is used in the deploying job
ocaml_docs:
name: OCaml documentation

build:
runs-on: ubuntu-latest

env:
OPAMWITHDOC: true

steps:
# Checkout the code of the current branch
- name: Checkout code
- name: Checkout
uses: actions/checkout@v4

# Update apt-get database
- name: Update apt-get database
run: sudo apt-get update

# Get an OCaml environment with opam installed and the proper ocaml version
# opam will used opam cache environment if retrieved
- name: Use OCaml ${{ env.OCAML_DEFAULT_VERSION }}
uses: ocaml/setup-ocaml@v3
with:
ocaml-compiler: ${{ env.OCAML_DEFAULT_VERSION }}
dune-cache: true

# Install dependencies if the cache is not retrieved
# odoc is installed as deps with { with-doc } in opam files
- name: opam install deps
run: opam exec -- make deps
# if: steps.cache-opam.outputs.cache-hit != 'true'

# Try to upgrade installed packages and fix dependencies if needed,
# when the cache is retrieved
# - run: opam upgrade --fixup
# if: steps.cache-opam.outputs.cache-hit == 'true'

# Make the documentation
- name: Make OCaml documentation
run: opam exec -- make odoc

# Create and upload an artifact `ocaml_doc` that contains the ocaml
# documentation in html format.
# This is only done if this workflow is triggered in a PR or on the
# following branches : next, main
- name: Upload ocaml documentation
uses: actions/upload-artifact@v4
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/next' || github.ref == 'refs/heads/main'
- name: Setup python
uses: actions/setup-python@v5
with:
name: ocaml_doc
path: _build/default/_doc/_html/


# On PR, or push on next/main, build the sphinx general documentation
# If this build fails, the documentation workflow stops
# If it succeeds, an artifact is made with the generated documentation
# This artifact is used in the deploying job
sphinx_docs:
name: Sphinx documentation
python-version: '3.10'

# We only run this if the ocaml documentation build is successful
needs: ocaml_docs
- name: Install dependencies
run: opam exec -- make doc-deps

# Sphinx documentation is only builded if a PR is open or when it's
# pushed on next or main
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/next' || github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
- name: Build documentation
run: opam exec -- make doc

steps:
# Checkout the code of the current branch
- name: Checkout code
uses: actions/checkout@v4

# Build the sphinx documentation
# and automatically print any error or warning
- name: Build sphinx documentation
uses: ammaraskar/sphinx-action@master
with:
docs-folder: "docs/sphinx_docs/"
build-command: "sphinx-build -b html . _build"

# Create and upload an artifact `sphinx_doc` that contains the sphinx
# documentation in html format.
- name: Upload sphinx documentation
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: sphinx_doc
path: docs/sphinx_docs/_build


# For every push on main, retrieve ocaml and sphinx documentation
# and publish them on gh-pages branch
deploy_docs:
name: Deploy documentation

if: github.ref == 'refs/heads/main'

needs:
- ocaml_docs
- sphinx_docs
name: artifact-doc
path: _build/doc

deploy:
needs: build
runs-on: ubuntu-latest
steps:
# Retrieve ocaml documentation artifact
- name: Download ocaml documentation
uses: actions/download-artifact@v4
with:
name: ocaml_doc
path: _build/odoc/dev
if: github.ref == 'refs/heads/next'

# Retrieve sphinx documentation artifact
- name: Download sphinx documentation
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: sphinx_doc
path: _build

- name: Add files to bypass nojekyll
run: |
touch _build/.nojekyll
touch _build/odoc/.nojekyll
touch _build/odoc/dev/.nojekyll
name: artifact-doc
path: build_doc

# Deploy files contain in _build directory on gh-pages branch
- name: deploy-doc
uses: JamesIves/[email protected]
- name: Deploy
uses: JamesIves/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: _build
CLEAN: false
github_token: ${{ secrets.GITHUB_TOKEN }}
folder: build_doc
target-folder: dev
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Build the distribution archive
run: opam exec -- dune-release distrib

- name: Upload the artefact
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: alt-ergo-${{github.sha}}.tbz
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ __pycache__

# Generated nix files
/result*

# Virtual environment to build sphinx docs
sphinx-venv
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The following terms apply to all such contributions:

In addition to agreeing to the terms of the Alt-Ergo's [License], we ask our contributors to sign the [Contributor License Agreement (CLA)].

[License]: ../About/licenses/index
[License]: ../About/index
[Contributor License Agreement (CLA)]: https://www.ocamlpro.com/files/CLA-OCamlPro-corporate.txt

## Develop with Nix
Expand Down
33 changes: 15 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ SPHINX_DOC_DIR := docs/sphinx_docs
BUILD_DIR := _build
INSTALL_DIR := $(BUILD_DIR)/install
DEFAULT_DIR := $(BUILD_DIR)/default
SPHINX_BUILD_DIR := $(BUILD_DIR)/sphinx_docs
SPHINX_BUILD_DIR := $(BUILD_DIR)/doc

# Some variables to help with adding
# flags and/or renaming the dune binary
DUNE=dune
DUNE_FLAGS?=

# Definining the sphinx build command
SPHINXBUILD = sphinx-build
SPHINXBUILD = sphinx-venv/bin/sphinx-build

# List the files:
# - generated by rules in this makefile,
Expand Down Expand Up @@ -157,26 +157,15 @@ uninstall: packages
# Documentation generation
# ========================

# Build the documentations
doc: odoc sphinx-doc

# Build the sphinx documentation
sphinx-doc:
# cp LICENSE.md $(SPHINX_DOC_DIR)/About/license.md
# cp -r licenses $(SPHINX_DOC_DIR)/About
$(SPHINXBUILD) "$(SPHINX_DOC_DIR)" "$(SPHINX_BUILD_DIR)"

# Build the odoc
odoc:
doc:
$(SPHINXBUILD) -W "$(SPHINX_DOC_DIR)" "$(SPHINX_BUILD_DIR)"
$(DUNE) build $(DUNE_FLAGS) @doc
cp -rf $(DEFAULT_DIR)/_doc/_html/* $(SPHINX_BUILD_DIR)/API

# Open the html doc generated by sphinx and odoc in browser
html: doc
mkdir -p $(SPHINX_BUILD_DIR)/odoc/dev
cp -r $(DEFAULT_DIR)/_doc/_html/* $(SPHINX_BUILD_DIR)/odoc/dev
xdg-open $(SPHINX_BUILD_DIR)/index.html

.PHONY: doc sphinx-doc odoc html
.PHONY: doc html

# ======================
# Javascript generation
Expand Down Expand Up @@ -257,13 +246,21 @@ js-deps:
deps:
opam install -y . --locked --deps-only

doc-deps: deps
python -m venv sphinx-venv
sphinx-venv/bin/pip install \
sphinx \
sphinx-rtd-theme \
sphinx-markdown-tables \
myst-parser

test-deps:
opam install -y . --locked --deps-only --with-test

dune-deps:
dune-deps . | dot -Tpng -o docs/deps.png

.PHONY: archi deps test-deps dune-deps dev-switch lock
.PHONY: archi deps doc-deps test-deps dune-deps dev-switch lock

# ===============
# PUBLIC RELEASES
Expand Down
Loading

0 comments on commit 05fc660

Please sign in to comment.