Skip to content

Commit 0d8c9b8

Browse files
authored
Initial implementation (#1)
* First pass at generating and deploying jazzy docs to github pages
1 parent 8d2f551 commit 0d8c9b8

File tree

688 files changed

+111491
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

688 files changed

+111491
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ bower_components
3333
build/Release
3434

3535
# Dependency directories
36-
node_modules/
3736
jspm_packages/
3837

3938
# TypeScript v1 declaration files

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Publish Jazzy Docs to Github Pages
2+
This is a GitHub Action generate and publish [Jazzy](https://github.com/realm/jazzy/) documentation for your Swift and/or Objective-C projects.
3+
4+
## Assumptions
5+
This Action expects the following to be true:
6+
* Your workflow runs on macOS
7+
* You have documentation comments present in your Swift/Objective-C project (otherwise you will be generating a pretty useless website)
8+
* You have a `gh-pages` branch in your repository
9+
* A personal access token with `repo` scope. The `GITHUB_TOKEN` available as part of an action will not trigger a Github Pages build. See [this discussion thread](https://github.community/t5/GitHub-Actions/Github-action-not-triggering-gh-pages-upon-push/td-p/26869) for more information.
10+
11+
## Configuration
12+
|Key|Description|Required|
13+
|---|---|:---:|
14+
| `personal_access_token` | A personal access token with repo scope for pushing documentation to `gh-pages` branch. See [Creating a Personal Access Token](https://help.github.com/en/enterprise/2.17/user/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) for creating the token and [Creating and Using Secrets](https://help.github.com/en/github/automating-your-workflow-with-github-actions/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) for including secrets to be used in tandem with Github Actions. | Yes |
15+
| `config` | The path to a Jazzy yaml configuration file| No |
16+
| `args` | Command line arguments to be passed to Jazzy. See `jazzy --help` on your local machine for available options| No |
17+
| `version` | The Jazzy version to run. Defaults to latest | No
18+
19+
## Limitations
20+
This Action will never support the following:
21+
* Generating and deploying documentation to `master` or in a docs folder on `master`
22+
* Maintain commit history of the `gh-pages` branch.
23+
24+
This Action does not currently support the following:
25+
* .json configuration files
26+
* Specifying both `config` and `args`. Any `args` provided along with `config` will be ignored.
27+
28+
## Usage
29+
Documentation generation can be as minimal as the following:
30+
```yaml
31+
name: PublishDocumentation
32+
33+
on:
34+
release:
35+
types: [published]
36+
37+
jobs:
38+
deploy_docs:
39+
runs-on: macOS-latest
40+
steps:
41+
- uses: actions/checkout@v1
42+
- name: Publish Jazzy Docs
43+
uses: steven0351/publish-jazzy-docs@v1
44+
with:
45+
personal_access_token: ${{ secrets.ACCESS_TOKEN }}
46+
```
47+
48+
Specify a Jazzy config file:
49+
```yaml
50+
...
51+
- name: Publish Jazzy Docs
52+
uses: steven0351/publish-jazzy-docs@v1
53+
with:
54+
personal_access_token: ${{ secrets.ACCESS_TOKEN }}
55+
config: .jazzy.yml
56+
```
57+
58+
Pass CLI args:
59+
```yaml
60+
...
61+
- name: Publish Jazzy Docs
62+
uses: steven0351/publish-jazzy-docs@v1
63+
with:
64+
personal_access_token: ${{ secrets.ACCESS_TOKEN }}
65+
args: "--theme fullwidth --author Johnny Appleseed"
66+
```
67+
68+
Specify a Jazzy version:
69+
```yaml
70+
...
71+
- name: Publish Jazzy Docs
72+
uses: steven0351/publish-jazzy-docs@v1
73+
with:
74+
personal_access_token: ${{ secrets.ACCESS_TOKEN }}
75+
version: 0.11.2
76+
```
77+
78+
## Contributions
79+
Pull requests are the preferred method of contributing. If you are unable to create a pull request, a detailed GitHub Issue describing the bug or feature request is more than welcome.

action.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "Publish Jazzy Docs:"
2+
desc: "Generate Swift/Obj-C documentation with Jazzy and publish to Github Pages"
3+
inputs:
4+
config:
5+
description: "Path to .jazzy.yml file - preferred"
6+
required: false
7+
args:
8+
description: "Arguments to pass to Jazzy"
9+
required: false
10+
version:
11+
description: "Jazzy Version"
12+
required: false
13+
personal_access_token:
14+
description: "Personal access token"
15+
required: true
16+
runs:
17+
using: "node12"
18+
main: "main.js"

main.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
const core = require("@actions/core")
2+
const github = require("@actions/github")
3+
const shell = require("shelljs")
4+
const yaml = require("js-yaml")
5+
const fs = require("fs")
6+
7+
const context = github.context
8+
9+
const branch = "gh-pages"
10+
11+
// User defined input
12+
const jazzyVersion = core.getInput("version")
13+
const configFilePath = core.getInput("config")
14+
const jazzyArgs = core.getInput("args")
15+
const token = core.getInput("personal_access_token")
16+
17+
const remote = `https://${token}@github.com/${context.repo.owner}/${context.repo.repo}.git`
18+
19+
const generateJazzyInstallCommand = () => {
20+
let gemInstall = "sudo gem install jazzy"
21+
22+
if (jazzyVersion) {
23+
gemInstall + ` -v ${jazzyVersion}`
24+
}
25+
26+
return gemInstall
27+
}
28+
29+
const generateJazzyArguments = () => {
30+
if (configFilePath) {
31+
return `jazzy --config ${configFilePath}`
32+
}
33+
34+
if (jazzyArgs) {
35+
return `jazzy ${jazzyArgs}`
36+
}
37+
38+
return "jazzy"
39+
}
40+
41+
const sliceDocumentsFromJazzyArgs = (outputArg) => {
42+
const startIndexOfDocsDir = jazzyArgs.indexOf(outputArg) + outputArg.length + 1
43+
const endIndexOfDocsDir = jazzyArgs.indexOf(" ", startIndexOfDocsDir)
44+
45+
if (endIndexOfDocsDir != -1) {
46+
return jazzyArgs.slice(startIndexOfDocsDir, endIndexOfDocsDir)
47+
} else {
48+
return jazzyArgs.slice(startIndexOfDocsDir)
49+
}
50+
}
51+
52+
const getDocumentationFolder = () => {
53+
if (configFilePath) {
54+
const config = yaml.safeLoad(fs.readFileSync(configFilePath, "utf8"))
55+
if (config.output) {
56+
return config.output
57+
}
58+
}
59+
60+
if (jazzyArgs) {
61+
// --output needs to be checked first, because --output includes -o
62+
if (jazzyArgs.includes("--output")) {
63+
return sliceDocumentsFromJazzyArgs("--output")
64+
}
65+
66+
if (jazzyArgs.includes("-o")) {
67+
return sliceDocumentsFromJazzyArgs("-o")
68+
}
69+
}
70+
71+
return "docs"
72+
}
73+
74+
const generateAndDeploy = () => {
75+
shell.exec(generateJazzyInstallCommand())
76+
shell.exec(generateJazzyArguments())
77+
shell.cp("-r", `${getDocumentationFolder()}/*`, "../")
78+
79+
shell.cd("../")
80+
shell.rm("-rf", `${process.env.GITHUB_WORKSPACE}`)
81+
82+
shell.exec("git init")
83+
shell.exec(`git config user.name ${context.actor}`)
84+
shell.exec(`git config user.email ${context.actor}@users.noreply.github.com`)
85+
shell.exec("git add .")
86+
shell.exec("git commit -m 'Deploying Updated Jazzy Docs'")
87+
shell.exec(`git push --force ${remote} master:${branch}`)
88+
}
89+
90+
try {
91+
generateAndDeploy()
92+
} catch (error) {
93+
core.setFailed(error.message)
94+
}
95+

node_modules/.bin/esparse

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/esvalidate

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/js-yaml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/rimraf

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/semver

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/shjs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)