Skip to content

Instantly share code, notes, and snippets.

@RaphaelS1
Last active September 19, 2022 05:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RaphaelS1/1e1de87218eb8d58b0c2907e4a947fd5 to your computer and use it in GitHub Desktop.
Save RaphaelS1/1e1de87218eb8d58b0c2907e4a947fd5 to your computer and use it in GitHub Desktop.
Workflow to check if all objects in Julia package documented as expected.
using MyPackage
documented = map(x -> replace(string(x), "MyPackage." => ""),
collect(keys(Docs.meta(MyPackage))));
expected = [];
map(x ->
x != :MyPackage && ## remove package name
Symbol(eval(x)) == x && # remove aliases
parentmodule(eval(x)) == MyPackage && ## check if this package is parent module
push!(expected, strip(String(x))), names(MyPackage)); ## push if all true
missings = setdiff(expected, documented); ## under-documented, critical error
extras = setdiff(documented, expected); ## over-documented, warning
if length(missings) > 0
error("Forgot to document: ", missings)
elseif length(extras) > 0
@warn "Extra objects documented:" extras
else
@info "All objects documented as expected:" expected
end
name: Documentation
on:
push:
branches:
- main
- master
tags: '*'
pull_request:
jobs:
build:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1.6'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key
run: julia --project=docs/ docs/make.jl
- name: Check expected and documented objects
if: github.event_name == 'pull_request'
run: julia --project=docs/ check_doc_coverage.jl
module MyPackage
export FunctionA, FunctionB, FunctionC
end
@RaphaelS1
Copy link
Author

RaphaelS1 commented Sep 2, 2022

Some notes about this:

1. For MyModule.jl the only commented tags that matter are # documented. Make sure your objects to document are between these.
2. For check_doc_coverage.jl you might want to consider putting this in docs/check_doc_coverage.jl to be cleaner - if so then make sure you update L30 in Documentation.yml
3. This assumes your package is fully setup and working with Documenter.jl

To see a working example look at my package SurvivalAnalysis.jl. In particular:

  1. Main project file
  2. Comparison script
  3. Workflow

Example of failing as expected and warning as expected.

@RaphaelS1
Copy link
Author

UPDATE: Massively simplified the above to require no extra dependencies or syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment