Skip to content

Commit 685578a

Browse files
authored
Sync documentation assets with templates (#104)
We have assembled a collection of reusable project assets: https://github.com/arduino/tooling-project-assets These assets will be used in the repositories of all Arduino tooling projects. Some significant improvements and standardizations have been made in the upstream "template" website assets, and those are introduced to this repository here. Notable: - Streamline website versioning system - Update website dependencies - Bump Python version used by the workflow from 3.8 to 3.9 Some tasks have changed: - `docs:gen:commands` -> `go:cli-docs` - `docs:publish` -> removed
1 parent 9ea0bd4 commit 685578a

13 files changed

+631
-128
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
name: publish-docs
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+
env:
5+
# See: https://github.com/actions/setup-python/tree/v2#available-versions-of-python
6+
PYTHON_VERSION: "3.9"
27

38
on:
49
push:
510
branches:
6-
# Branch to base "dev" website on. Set in build.py also.
11+
# Branch to base "dev" website on. Set in siteversion.py also.
712
- main
8-
# release branches have names like 0.8.x, 0.9.x, ...
13+
# Release branches have names like 0.8.x, 0.9.x, ...
914
- "[0-9]+.[0-9]+.x"
1015
paths:
1116
- "docs/**"
12-
- "docsgen/**"
13-
- "cli/**"
14-
- ".github/workflows/publish-docs.ya?ml"
17+
- ".github/workflows/deploy-cobra-mkdocs-versioned-poetry.ya?ml"
18+
- "go.mod"
19+
- "go.sum"
1520
- "Taskfile.ya?ml"
21+
- "**.go"
22+
- "docsgen/**"
1623
- "mkdocs.ya?ml"
1724
- "poetry.lock"
1825
- "pyproject.toml"
19-
- "go.mod"
20-
- "go.sum"
21-
# Run on branch or tag creation (will be filtered by the publish-determination job)
26+
# Run on branch or tag creation (will be filtered by the publish-determination job).
2227
create:
2328

2429
jobs:
@@ -38,44 +43,52 @@ jobs:
3843
fi
3944
4045
echo "::set-output name=result::$RESULT"
46+
4147
publish:
4248
runs-on: ubuntu-latest
4349
needs: publish-determination
4450
if: needs.publish-determination.outputs.result == 'true'
4551

4652
steps:
47-
- name: Checkout
53+
- name: Checkout repository
4854
uses: actions/checkout@v2
4955

50-
- name: Install Taskfile
51-
uses: arduino/setup-task@v1
52-
with:
53-
repo-token: ${{ secrets.GITHUB_TOKEN }}
54-
version: 3.x
55-
56-
- name: Setup Go
57-
uses: actions/setup-go@v2
58-
with:
59-
go-version: "1.16"
60-
6156
- name: Install Python
6257
uses: actions/setup-python@v2
6358
with:
64-
python-version: "3.8"
59+
python-version: ${{ env.PYTHON_VERSION }}
6560

66-
- name: Install Python dependencies
61+
- name: Install Poetry
6762
run: |
6863
python -m pip install --upgrade pip
6964
python -m pip install poetry
7065
66+
- name: Install Task
67+
uses: arduino/setup-task@v1
68+
with:
69+
repo-token: ${{ secrets.GITHUB_TOKEN }}
70+
version: 3.x
71+
72+
- name: Create all generated documentation content
73+
run: task docs:generate
74+
7175
- name: Install Python dependencies
7276
run: poetry install --no-root
7377

74-
- name: Publish docs
75-
# Determine docs version for the commit pushed and publish accordingly using Mike.
76-
# Publishing implies creating a git commit on the gh-pages branch, we let @ArduinoBot own these commits.
78+
- name: Determine versioning parameters
79+
id: determine-versioning
80+
run: echo "::set-output name=data::$(poetry run python docs/siteversion/siteversion.py)"
81+
82+
- name: Publish documentation
83+
if: fromJson(steps.determine-versioning.outputs.data).version != null
7784
run: |
85+
# Publishing implies creating a git commit on the gh-pages branch, we let @ArduinoBot own these commits.
7886
git config --global user.email "[email protected]"
7987
git config --global user.name "ArduinoBot"
8088
git fetch --no-tags --prune --depth=1 origin +refs/heads/gh-pages:refs/remotes/origin/gh-pages
81-
poetry run python docs/build/build.py
89+
poetry run mike deploy \
90+
--update-aliases \
91+
--push \
92+
--remote origin \
93+
${{ fromJson(steps.determine-versioning.outputs.data).version }} \
94+
${{ fromJson(steps.determine-versioning.outputs.data).alias }}

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ __pycache__/
1515
/site/
1616
/docsgen/arduino-fwuploader
1717
/docsgen/arduino-fwuploader.exe
18-
/docs/commands/*.md
18+
/docs/commands/

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The Arduino Firmware Uploader is a tool made to update the firmware and/or add S
44
equipped with WINC or NINA Wi-Fi module.
55

66
[![tests-badge]](https://github.com/arduino/arduino-fwuploader/actions/workflows/test.yaml)
7-
[![docs-badge]](https://github.com/arduino/arduino-fwuploader/actions/workflows/publish-docs.yaml)
7+
[![Deploy Website status](https://github.com/arduino/arduino-fwuploader/actions/workflows/deploy-cobra-mkdocs-versioned-poetry.yml/badge.svg)](https://github.com/arduino/arduino-fwuploader/actions/workflows/deploy-cobra-mkdocs-versioned-poetry.yml)
88

99
## ❗❗❗Notice regarding versions before 2.0.0 ❗❗❗
1010

@@ -29,7 +29,6 @@ and report the bug to our Security Team 🛡️ Thank you!
2929
e-mail contact: [email protected]
3030

3131
[tests-badge]: https://github.com/arduino/arduino-fwuploader/actions/workflows/test.yaml/badge.svg
32-
[docs-badge]: https://github.com/arduino/arduino-fwuploader/actions/workflows/publish-docs.yaml/badge.svg
3332
[security policy]: https://github.com/arduino/arduino-fwuploader/security/policy
3433
[user documentation]: https://arduino.github.io/arduino-fwuploader/
3534
[install]: https://arduino.github.io/arduino-fwuploader/latest/installation

Taskfile.yml

+22-24
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,18 @@ tasks:
1414
desc: Run website locally
1515
deps:
1616
- task: poetry:install-deps
17-
- task: docs:gen:commands
17+
- task: docs:generate
1818
cmds:
1919
- poetry run mkdocs serve
2020

21-
docs:publish:
22-
desc: Use Mike to build and push versioned docs
23-
deps:
24-
- docs:gen:commands
25-
cmds:
26-
- poetry run mike deploy --update-aliases --push --remote {{.DOCS_REMOTE}} {{.DOCS_VERSION}} {{.DOCS_ALIAS}}
27-
21+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/deploy-cobra-mkdocs-versioned-poetry/Taskfile.yml
2822
docs:generate:
2923
desc: Create all generated documentation content
3024
deps:
31-
- task: docs:gen:commands
32-
33-
docs:gen:commands:
34-
desc: Generate command reference files
35-
dir: ./docsgen
25+
- task: go:cli-docs
3626
cmds:
37-
# docs will generate examples using os.Args[0] so we need to call
38-
# the generator `arduino-fwuploader`
39-
- go build -o {{.PROJECT_NAME}}{{exeExt}}
40-
# we invoke `arduino-fwuploader` like this instead of `./arduino-fwuploader` to remove
41-
# the `./` chars from the examples
42-
- PATH=. {{.PROJECT_NAME}} ../docs/commands
43-
- task: docs:format
27+
# Make the formatting consistent with the non-generated Markdown
28+
- task: general:format-prettier
4429

4530
docs:check:
4631
desc: Run documentation linting
@@ -55,11 +40,27 @@ tasks:
5540
docs:build:
5641
desc: Build documentation website contents
5742
deps:
58-
- docs:gen:commands
43+
- docs:generate
5944
- poetry:install-deps
6045
cmds:
6146
- poetry run mkdocs build -s
6247

48+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting-task/Taskfile.yml
49+
general:format-prettier:
50+
desc: Format all supported files with Prettier
51+
cmds:
52+
- npx prettier --write .
53+
54+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/deploy-cobra-mkdocs-versioned-poetry/Taskfile.yml
55+
go:cli-docs:
56+
desc: Generate command line interface reference documentation
57+
dir: ./docsgen
58+
cmds:
59+
# Command examples use os.Args[0] so the docs generation binary must have the same filename as the project
60+
- go build -o {{.PROJECT_NAME}}{{exeExt}}
61+
# The binary is invoked like this instead of `./{{.PROJECT_NAME}}` to remove the `./` chars from the examples
62+
- PATH=. {{.PROJECT_NAME}} ../docs/commands
63+
6364
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
6465
go:lint:
6566
desc: Lint Go code
@@ -245,6 +246,3 @@ vars:
245246
'
246247
# check-lint vars
247248
248-
DOCS_VERSION: dev
249-
DOCS_ALIAS: ""
250-
DOCS_REMOTE: "origin"

docs/commands/.gitkeep

Whitespace-only changes.

docs/build/build.py renamed to docs/siteversion/siteversion.py

+13-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Source:
2-
# https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/deploy-mkdocs-versioned/build/build.py
2+
# https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/deploy-mkdocs-versioned/siteversion/siteversion.py
33

44
# Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
55

@@ -13,11 +13,9 @@
1313
# Arduino software without disclosing the source code of your own applications.
1414
# To purchase a commercial license, send an email to [email protected].
1515
import os
16-
import sys
1716
import re
18-
import subprocess
17+
import json
1918

20-
import click
2119
from git import Repo
2220

2321
# In order to provide support for multiple project releases, Documentation is versioned so that visitors can select
@@ -41,19 +39,20 @@
4139

4240
def get_docs_version(ref_name, release_branches):
4341
if ref_name in DEV_BRANCHES:
44-
return "dev", ""
42+
return {"version": "dev", "alias": ""}
4543

4644
if ref_name in release_branches:
4745
# if version is latest, add an alias
4846
alias = "latest" if ref_name == release_branches[0] else ""
4947
# strip `.x` suffix from the branch name to get the version: 0.3.x -> 0.3
50-
return ref_name[:-2], alias
48+
return {"version": ref_name[:-2], "alias": alias}
5149

52-
return None, None
50+
return {"version": None, "alias": None}
5351

5452

5553
def get_rel_branch_names(blist):
5654
"""Get the names of the release branches, sorted from newest to older.
55+
5756
Only process remote refs so we're sure to get all of them and clean up the
5857
name so that we have a list of strings like 0.6.x, 0.7.x, ...
5958
"""
@@ -70,10 +69,7 @@ def get_rel_branch_names(blist):
7069
return sorted(names, key=lambda x: int(x.split(".")[1]), reverse=True)
7170

7271

73-
@click.command()
74-
@click.option("--dry", is_flag=True)
75-
@click.option("--remote", default="origin", help="The git remote where to push.")
76-
def main(dry, remote):
72+
def main():
7773
# Detect repo root folder
7874
here = os.path.dirname(os.path.realpath(__file__))
7975
repo_dir = os.path.join(here, "..", "..")
@@ -84,26 +80,16 @@ def main(dry, remote):
8480
# Get the list of release branch names
8581
rel_br_names = get_rel_branch_names(repo.refs)
8682

87-
# Deduce docs version from current branch. Use the 'latest' alias if
88-
# version is the most recent
89-
docs_version, alias = get_docs_version(repo.active_branch.name, rel_br_names)
90-
if docs_version is None:
91-
print(f"Can't get version from current branch '{repo.active_branch}', skip docs generation")
92-
return 0
93-
94-
# Taskfile args aren't regular args so we put everything in one string
95-
cmd = (f"task docs:publish DOCS_REMOTE={remote} DOCS_VERSION={docs_version} DOCS_ALIAS={alias}",)
96-
97-
if dry:
98-
print(cmd)
99-
return 0
83+
# Deduce docs version from current branch.
84+
versioning_data = get_docs_version(repo.active_branch.name, rel_br_names)
10085

101-
subprocess.run(cmd, shell=True, check=True, cwd=repo_dir)
86+
# Return the data as JSON on stdout
87+
print(json.dumps(versioning_data))
10288

10389

10490
# Usage:
10591
# To run the script (must be run from within the repo tree):
106-
# $python build.py
92+
# $python siteversion.py
10793
#
10894
if __name__ == "__main__":
109-
sys.exit(main())
95+
main()

docsgen/go.mod

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/cobra/docsgen/go.mod
2+
module github.com/arduino/arduino-fwuploader/docsgen
3+
4+
go 1.16
5+
6+
replace github.com/arduino/arduino-fwuploader => ../
7+
8+
require (
9+
github.com/arduino/arduino-fwuploader v0.0.0
10+
github.com/spf13/cobra v1.1.3
11+
)

0 commit comments

Comments
 (0)