| Marc Kupietz | 437d7af | 2026-09-09 14:40:02 +0200 | [diff] [blame^] | 1 | # Rebuilds the documentation and fails on links roxygen2 cannot resolve. |
| 2 | # |
| 3 | # Those arise from linking to a function marked @noRd, which has no topic to |
| 4 | # link to. They never reach a manual page, so R CMD check says nothing and a |
| 5 | # comparison of the generated files finds nothing either - the only trace is a |
| 6 | # message while documenting, which is easy to miss. |
| 7 | on: |
| 8 | push: |
| 9 | branches: [main, master] |
| 10 | paths: |
| 11 | - 'R/**' |
| 12 | - 'man/**' |
| 13 | - 'NAMESPACE' |
| 14 | - 'DESCRIPTION' |
| 15 | - '.github/workflows/document.yaml' |
| 16 | pull_request: |
| 17 | branches: [main, master] |
| 18 | |
| 19 | name: document |
| 20 | |
| 21 | jobs: |
| 22 | document: |
| 23 | runs-on: ubuntu-latest |
| 24 | |
| 25 | env: |
| 26 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} |
| 27 | |
| 28 | steps: |
| 29 | - uses: actions/checkout@v3 |
| 30 | |
| 31 | - uses: r-lib/actions/setup-r@v2 |
| 32 | with: |
| 33 | use-public-rspm: true |
| 34 | |
| 35 | - uses: r-lib/actions/setup-r-dependencies@v2 |
| 36 | with: |
| 37 | extra-packages: any::roxygen2 |
| 38 | |
| 39 | - name: Document, and refuse links that do not resolve |
| 40 | shell: Rscript {0} |
| 41 | run: | |
| 42 | messages <- character() |
| 43 | withCallingHandlers( |
| 44 | roxygen2::roxygenise(), |
| 45 | message = function(m) { |
| 46 | messages <<- c(messages, conditionMessage(m)) |
| 47 | invokeRestart("muffleMessage") |
| 48 | } |
| 49 | ) |
| 50 | cat(messages, sep = "") |
| 51 | |
| 52 | # reported as a message rather than a warning, so it has to be looked for |
| 53 | unresolved <- grep("Could not resolve link", messages, value = TRUE) |
| 54 | if (length(unresolved) > 0) { |
| 55 | stop( |
| 56 | sprintf( |
| 57 | "roxygen2 could not resolve %d link%s. A function marked @noRd has no topic to link to; write it as `code` instead.", |
| 58 | length(unresolved), |
| 59 | if (length(unresolved) == 1) "" else "s" |
| 60 | ), |
| 61 | call. = FALSE |
| 62 | ) |
| 63 | } |