-
-
Notifications
You must be signed in to change notification settings - Fork 405
Add versioning to docs #711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e0edcca
introduce mike
9bb4053
use default 'site' dir for output
a805402
install mike and pin material theme
a94c7a5
add task to build&publish docs using Mike
a11f45b
publish dev and versioned docs
2d256a2
narrow down env definition
5077dc9
add build script to handle versioning
6647930
invoke task, not mike directly
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# This file is part of arduino-cli. | ||
|
||
# Copyright 2020 ARDUINO SA (http://www.arduino.cc/) | ||
|
||
# This software is released under the GNU General Public License version 3, | ||
# which covers the main part of arduino-cli. | ||
# The terms of this license can be found at: | ||
# https://www.gnu.org/licenses/gpl-3.0.en.html | ||
|
||
# You can be released from the requirements of the above licenses by purchasing | ||
# a commercial license. Buying such a license is mandatory if you want to | ||
# modify or otherwise use the software for commercial activities involving the | ||
# Arduino software without disclosing the source code of your own applications. | ||
# To purchase a commercial license, send an email to license@arduino.cc. | ||
import os | ||
import sys | ||
import re | ||
import unittest | ||
import subprocess | ||
|
||
import semver | ||
from git import Repo | ||
|
||
|
||
class TestScript(unittest.TestCase): | ||
def test_get_docs_version(self): | ||
ver, alias = get_docs_version("master", []) | ||
self.assertEqual(ver, "dev") | ||
self.assertEqual(alias, "") | ||
|
||
release_names = ["1.4.x", "0.13.x"] | ||
ver, alias = get_docs_version("0.13.x", release_names) | ||
self.assertEqual(ver, "0.13") | ||
self.assertEqual(alias, "") | ||
ver, alias = get_docs_version("1.4.x", release_names) | ||
self.assertEqual(ver, "1.4") | ||
self.assertEqual(alias, "latest") | ||
|
||
ver, alias = get_docs_version("0.1.x", []) | ||
self.assertIsNone(ver) | ||
self.assertIsNone(alias) | ||
|
||
|
||
def get_docs_version(ref_name, release_branches): | ||
if ref_name == "master": | ||
return "dev", "" | ||
|
||
if ref_name in release_branches: | ||
# if version is latest, add an alias | ||
alias = "latest" if ref_name == release_branches[0] else "" | ||
# strip `.x` suffix from the branch name to get the version: 0.3.x -> 0.3 | ||
return ref_name[:-2], alias | ||
|
||
return None, None | ||
|
||
|
||
def get_rel_branch_names(blist): | ||
"""Get the names of the release branches, sorted from newest to older. | ||
|
||
Only process remote refs so we're sure to get all of them and clean up the | ||
name so that we have a list of strings like 0.6.x, 0.7.x, ... | ||
""" | ||
pattern = re.compile(r"origin/(\d+\.\d+\.x)") | ||
names = [] | ||
for b in blist: | ||
res = pattern.search(b.name) | ||
if res is not None: | ||
names.append(res.group(1)) | ||
|
||
# Since sorting is stable, first sort by major... | ||
names = sorted(names, key=lambda x: int(x.split(".")[0]), reverse=True) | ||
# ...then by minor | ||
return sorted(names, key=lambda x: int(x.split(".")[1]), reverse=True) | ||
|
||
|
||
def main(repo_dir): | ||
# Git remote must be set to publish docs | ||
remote = os.environ.get("REMOTE") | ||
if not remote: | ||
print("REMOTE env var must be set to publish, running dry mode") | ||
|
||
# Get current repo | ||
repo = Repo(repo_dir) | ||
|
||
# Get the list of release branch names | ||
rel_br_names = get_rel_branch_names(repo.refs) | ||
|
||
# Deduce docs version from current branch. Use the 'latest' alias if | ||
# version is the most recent | ||
docs_version, alias = get_docs_version(repo.active_branch.name, rel_br_names) | ||
if docs_version is None: | ||
print( | ||
f"Can't get version from current branch '{repo.active_branch}', skip docs generation" | ||
) | ||
return 0 | ||
|
||
args = [ | ||
"task", | ||
"docs:publish", | ||
f"DOCS_REMOTE={remote}", | ||
f"DOCS_VERSION={docs_version}", | ||
f"DOCS_ALIAS={alias}", | ||
] | ||
if remote: | ||
subprocess.run(args, shell=True, check=True, cwd=repo_dir) | ||
else: | ||
print(" ".join(args)) | ||
|
||
return 0 | ||
|
||
|
||
# Usage: | ||
# | ||
# To run the tests: | ||
# $python build.py test | ||
# | ||
# To run the script (must be run from within the repo tree): | ||
# $python build.py | ||
# | ||
if __name__ == "__main__": | ||
if len(sys.argv) > 1 and sys.argv[1] == "test": | ||
unittest.main(argv=[""], exit=False) | ||
sys.exit(0) | ||
|
||
here = os.path.dirname(os.path.realpath(__file__)) | ||
sys.exit(main(os.path.join(here, ".."))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@media only screen and (max-width:76.1875em) { | ||
#version-selector { | ||
padding: .6rem .8rem; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
window.addEventListener("DOMContentLoaded", function() { | ||
// This is a bit hacky. Figure out the base URL from a known CSS file the | ||
// template refers to... | ||
var ex = new RegExp("/?assets/fonts/material-icons.css$"); | ||
var sheet = document.querySelector('link[href$="material-icons.css"]'); | ||
|
||
var REL_BASE_URL = sheet.getAttribute("href").replace(ex, ""); | ||
var ABS_BASE_URL = sheet.href.replace(ex, ""); | ||
var CURRENT_VERSION = ABS_BASE_URL.split("/").pop(); | ||
|
||
function makeSelect(options, selected) { | ||
var select = document.createElement("select"); | ||
select.classList.add("form-control"); | ||
|
||
options.forEach(function(i) { | ||
var option = new Option(i.text, i.value, undefined, | ||
i.value === selected); | ||
select.add(option); | ||
}); | ||
|
||
return select; | ||
} | ||
|
||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", REL_BASE_URL + "/../versions.json"); | ||
xhr.onload = function() { | ||
var versions = JSON.parse(this.responseText); | ||
|
||
var realVersion = versions.find(function(i) { | ||
return i.version === CURRENT_VERSION || | ||
i.aliases.includes(CURRENT_VERSION); | ||
}).version; | ||
|
||
var select = makeSelect(versions.map(function(i) { | ||
return {text: i.title, value: i.version}; | ||
}), realVersion); | ||
select.addEventListener("change", function(event) { | ||
window.location.href = REL_BASE_URL + "/../" + this.value; | ||
}); | ||
|
||
var container = document.createElement("div"); | ||
container.id = "version-selector"; | ||
container.className = "md-nav__item"; | ||
container.appendChild(select); | ||
|
||
var sidebar = document.querySelector(".md-nav--primary > .md-nav__list"); | ||
sidebar.parentNode.insertBefore(container, sidebar); | ||
}; | ||
xhr.send(); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
mkdocs | ||
mkdocs-material | ||
mkdocs<1.2 | ||
mkdocs-material<5 | ||
mike | ||
gitpython |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An unwanted blank line maybe?