We assume that you already have a basic knowledge of GitHub actions and understand how they work.
Let's create a GitHub action which first checks out the source code of your project
and then it builds the documentation for your Project.
We assume that your awesome project has its Swift source files at the path Sources/AwesomeProject
in your repository.
Add the file .github/workflows/documentation.yml
to your repository:
name: Documentation
on:
push:
branches:
- main
paths:
- .github/workflows/documentation.yml
- Sources/AwesomeProject/**.swift
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Generate Documentation
uses: SwiftDocOrg/swift-doc@master
with:
inputs: "Sources/SwiftDoc"
output: "Documentation"
Then the next time you push a commit to your main
branch,
the workflow is triggered
and builds the documentation.
Now, building the documentation is already the first step. But very likely you also want to publish the generated documentation somewhere. That's why we also provide another GitHub action to automatically upload your documentation to your project's GitHub Wiki.
The Github Wiki Publish Action
publishes the contents of a directory to your project's wiki from a GitHub action workflow
and is the ideal addition to the swift-doc
action.
We will extend the example from above and check out the project's source code in a first step, then build the documentation in a second step and then upload the created documentation to your project's wiki in a third step.
name: Documentation
on:
push:
branches:
- main
paths:
- .github/workflows/documentation.yml
- Sources/SwiftDoc/**.swift
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Generate Documentation
uses: SwiftDocOrg/swift-doc@master
with:
inputs: "Sources/SwiftDoc"
output: "Documentation"
- name: Upload Documentation to Wiki
uses: SwiftDocOrg/github-wiki-publish-action@v1
with:
path: "Documentation"
env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
You might have noticed that the generated documentation contained less symbols that your library actually has.
This is because swift-doc
only includes public symbols by default
— as this are also the symbols which are exposed to users of your library.
But if you want to generate documentation for apps and not only for libraries or if you want to generate a documentation for developers and not only end users of your library, then you might want to include additional symbols.
Therefore swift-doc
also provides the possibility to decide which symbols are included
by setting the minimum access level from which symbols should be included.
This is done via the --minimum-access-level
option.
Its possible values are:
-
public
(default). This will only include symbols which are declaredpublic
oropen
. For example, given the following swift source file:public func publicFunction() { } func internalFunction() { } private func privateFunction() { } public class PublicClass { public func publicMethod() { } open func openMethod() { } func internalMethod() { } } internal class InternalClass { private func privateMethod() { } }
Then the generated documentation will include the function
publicFunction()
and the classPublicClass
. For the documentation ofPublicClass
, it will only include the methodspublicMethod()
andopenMethod()
. -
internal
. This will include all symbols which are declaredpublic
,open
, andinternal
. So in the example above, it will additionally include the functioninternalFunction()
and the classInternalClass
. But for the documentation ofInternalClass
, it will not include the methodprivateMethod()
. -
private
. This will also include all symbols which are declaredprivate
andfileprivate
and effectively include symbols.
Now you know which symbols appear in the generated documentation. Continue with the guide to understand how to write documentation comments in your source code to make the best of your documentation.