Skip to content

Commit 88c43ad

Browse files
authored
Merge pull request #88 from per1234/mkdocs-cli
Add template workflow to generate Cobra docs and deploy a versioned MkDocs-based website to GitHub Pages
2 parents 3a56fe8 + 609ca91 commit 88c43ad

File tree

13 files changed

+430
-2
lines changed

13 files changed

+430
-2
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ indent_style = space
2525
indent_size = 2
2626
indent_style = space
2727

28-
[*.go]
28+
[*.{go,mod}]
2929
indent_style = tab
3030

3131
[*.java]

workflow-templates/assets/check-markdown-task/Taskfile.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
version: "3"
33

44
tasks:
5+
docs:generate:
6+
desc: Create all generated documentation content
7+
# This is an "umbrella" task used to call any documentation generation processes the project has.
8+
# It can be left empty if there are none.
9+
510
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
611
markdown:lint:
712
desc: Check for problems in Markdown files
@@ -17,6 +22,8 @@ tasks:
1722
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
1823
markdown:check-links:
1924
desc: Check for broken links
25+
deps:
26+
- task: docs:generate
2027
cmds:
2128
- |
2229
if [[ "{{.OS}}" == "Windows_NT" ]]; then

workflow-templates/assets/check-mkdocs-task/Taskfile.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
version: "3"
33

44
tasks:
5+
docs:generate:
6+
desc: Create all generated documentation content
7+
# This is an "umbrella" task used to call any documentation generation processes the project has.
8+
# It can be left empty if there are none.
9+
510
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-mkdocs-task/Taskfile.yml
611
website:check:
712
desc: Check whether the MkDocs-based website will build
813
deps:
14+
- task: docs:generate
915
- task: poetry:install-deps
1016
cmds:
1117
- poetry run mkdocs build --strict
@@ -14,6 +20,7 @@ tasks:
1420
website:serve:
1521
desc: Run website locally
1622
deps:
23+
- task: docs:generate
1724
- task: poetry:install-deps
1825
cmds:
1926
- poetry run mkdocs serve

workflow-templates/assets/deploy-cobra-mkdocs-versioned-poetry/.gitkeep

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: "3"
2+
3+
vars:
4+
PROJECT_NAME: TODO
5+
6+
tasks:
7+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/deploy-cobra-mkdocs-versioned-poetry/Taskfile.yml
8+
docs:generate:
9+
desc: Create all generated documentation content
10+
deps:
11+
- task: go:cli-docs
12+
# Make the formatting consistent with the non-generated Markdown
13+
- task: general:format-prettier
14+
15+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/deploy-cobra-mkdocs-versioned-poetry/Taskfile.yml
16+
go:cli-docs:
17+
desc: Generate command line interface reference documentation
18+
dir: ./docsgen
19+
cmds:
20+
# Command examples use os.Args[0] so the docs generation binary must have the same filename as the project
21+
- go build -o {{.PROJECT_NAME}}{{exeExt}}
22+
# The binary is invoked like this instead of `./{{.PROJECT_NAME}}` to remove the `./` chars from the examples
23+
- PATH=. {{.PROJECT_NAME}} ../docs/commands
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/deploy-cobra-mkdocs-versioned-poetry/docsgen/go.mod
2+
// TODO: replace MODULE_NAME with the project's module name
3+
module MODULE_NAME/docsgen
4+
5+
go 1.14
6+
7+
replace MODULE_NAME => ../
8+
9+
require (
10+
MODULE_NAME v0.0.0
11+
github.com/spf13/cobra v1.1.1
12+
)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/deploy-cobra-mkdocs-versioned-poetry/docsgen/main.go
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3.
6+
// The terms of this license can be found at:
7+
// https://www.gnu.org/licenses/gpl-3.0.en.html
8+
//
9+
// You can be released from the requirements of the above licenses by purchasing
10+
// a commercial license. Buying such a license is mandatory if you want to
11+
// modify or otherwise use the software for commercial activities involving the
12+
// Arduino software without disclosing the source code of your own applications.
13+
// To purchase a commercial license, send an email to [email protected].
14+
15+
// Package main generates Markdown documentation for the project's CLI.
16+
package main
17+
18+
import (
19+
"os"
20+
21+
// TODO: Replace CLI_PACKAGE_NAME with the project's Cobra CLI package name
22+
"CLI_PACKAGE_NAME"
23+
"github.com/spf13/cobra/doc"
24+
)
25+
26+
func main() {
27+
if len(os.Args) < 2 {
28+
print("error: Please provide the output folder argument")
29+
os.Exit(1)
30+
}
31+
32+
cli := cli.Root()
33+
cli.DisableAutoGenTag = true // Disable addition of auto-generated date stamp
34+
err := doc.GenMarkdownTree(cli, os.Args[1])
35+
if err != nil {
36+
panic(err)
37+
}
38+
}

workflow-templates/assets/shared/.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ indent_style = space
2525
indent_size = 2
2626
indent_style = space
2727

28-
[*.go]
28+
[*.{go,mod}]
2929
indent_style = tab
3030

3131
[*.java]

workflow-templates/check-markdown-task.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ The code style defined in `.markdownlint.yml` is the official standardized style
2828

2929
### Configuration
3030

31+
#### Taskfile
32+
33+
Add any documentation generation processes to the `docs:generate` umbrella task.
34+
3135
#### markdownlint
3236

3337
In the event the repository contains externally maintained Markdown files, `markdownlint` can be configured to ignore them via a `.markdownlintignore` file:

workflow-templates/check-mkdocs-task.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ See [the "Deploy Website" (MkDocs, Poetry) workflow documentation](deploy-mkdocs
2424

2525
### Configuration
2626

27+
#### Taskfile
28+
29+
Add any documentation generation processes to the `docs:generate` umbrella task.
30+
31+
#### MkDocs
32+
2733
See [the "Deploy Website" (MkDocs, Poetry) workflow documentation](deploy-mkdocs-poetry.md#configuration)
2834

2935
### Readme badge
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/deploy-cobra-mkdocs-versioned-poetry.md
2+
name: Deploy Website
3+
4+
on:
5+
push:
6+
branches:
7+
# Branch to base "dev" website on. Set in siteversion.py also.
8+
- main
9+
# Release branches have names like 0.8.x, 0.9.x, ...
10+
- "[0-9]+.[0-9]+.x"
11+
paths:
12+
- "docs/**"
13+
- ".github/workflows/deploy-cobra-mkdocs-versioned-poetry.ya?ml"
14+
- "go.mod"
15+
- "go.sum"
16+
- "Taskfile.ya?ml"
17+
- "**.go"
18+
- "docsgen/**"
19+
- "mkdocs.ya?ml"
20+
- "poetry.lock"
21+
- "pyproject.toml"
22+
# Run on branch or tag creation (will be filtered by the publish-determination job).
23+
create:
24+
25+
jobs:
26+
publish-determination:
27+
runs-on: ubuntu-latest
28+
outputs:
29+
result: ${{ steps.determination.outputs.result }}
30+
steps:
31+
- name: Determine if documentation should be published on this workflow run
32+
id: determination
33+
run: |
34+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
35+
if [[ "${{ github.event_name }}" == "push" || ( "${{ github.event_name }}" == "create" && "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX ) ]]; then
36+
RESULT="true"
37+
else
38+
RESULT="false"
39+
fi
40+
41+
echo "::set-output name=result::$RESULT"
42+
43+
publish:
44+
runs-on: ubuntu-latest
45+
needs: publish-determination
46+
if: needs.publish-determination.outputs.result == 'true'
47+
48+
steps:
49+
- name: Checkout repository
50+
uses: actions/checkout@v2
51+
52+
- name: Install Python
53+
uses: actions/setup-python@v2
54+
with:
55+
python-version: "3.9"
56+
57+
- name: Install Poetry
58+
run: |
59+
python -m pip install --upgrade pip
60+
python -m pip install poetry
61+
62+
- name: Install Task
63+
uses: arduino/setup-task@v1
64+
with:
65+
repo-token: ${{ secrets.GITHUB_TOKEN }}
66+
version: 3.x
67+
68+
- name: Create all generated documentation content
69+
run: task docs:generate
70+
71+
- name: Install Python dependencies
72+
run: poetry install --no-root
73+
74+
- name: Determine versioning parameters
75+
id: determine-versioning
76+
run: echo "::set-output name=data::$(poetry run python docs/siteversion/siteversion.py)"
77+
78+
- name: Publish documentation
79+
if: fromJson(steps.determine-versioning.outputs.data).version != null
80+
run: |
81+
# Publishing implies creating a git commit on the gh-pages branch, we let @ArduinoBot own these commits.
82+
git config --global user.email "[email protected]"
83+
git config --global user.name "ArduinoBot"
84+
git fetch --no-tags --prune --depth=1 origin +refs/heads/gh-pages:refs/remotes/origin/gh-pages
85+
poetry run mike deploy \
86+
--update-aliases \
87+
--push \
88+
--remote origin \
89+
${{ fromJson(steps.determine-versioning.outputs.data).version }} \
90+
${{ fromJson(steps.determine-versioning.outputs.data).alias }}

0 commit comments

Comments
 (0)