-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
81 additions
and
8 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains 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,41 @@ | ||
"""Create/modify switcher.json to allow docs to switch between different versions.""" | ||
|
||
import json, os | ||
from argparse import ArgumentParser | ||
from pathlib import Path | ||
|
||
|
||
def get_versions(root: str) -> list[str]: | ||
"""Generate a list of versions.""" | ||
versions = sorted([ f.name for f in os.scandir(root) if f.is_dir() ]) | ||
print(f"Sorted versions: {versions}") | ||
return versions | ||
|
||
|
||
def write_json(path: Path, repository: str, versions: list[str]): | ||
"""Write the JSON switcher to path.""" | ||
org, repo_name = repository.split("/") | ||
struct = [ | ||
{"version": version, "url": f"https://{org}.github.io/{repo_name}/{version}/"} | ||
for version in versions | ||
] | ||
text = json.dumps(struct, indent=2) | ||
print(f"JSON switcher:\n{text}") | ||
path.write_text(text, encoding="utf-8") | ||
|
||
|
||
def main(args=None): | ||
"""Parse args and write switcher.""" | ||
parser = ArgumentParser(description="Make a versions.json file") | ||
parser.add_argument("root", type=Path, help="Path to root directory with all versions of docs") | ||
parser.add_argument("repository", help="The GitHub org and repository name: ORG/REPO") | ||
parser.add_argument("output", type=Path, help="Path of write switcher.json to") | ||
args = parser.parse_args(args) | ||
|
||
# Write the versions file | ||
versions = get_versions(args.root) | ||
write_json(args.output, args.repository, versions) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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 |
---|---|---|
|
@@ -50,9 +50,3 @@ jobs: | |
with: | ||
name: docs-${{ inputs.tag }} | ||
path: artifacts | ||
|
||
- name: Upload index.html as Artifact | ||
uses: actions/[email protected] | ||
with: | ||
name: docs-index-html | ||
path: docs/index.html |
This file contains 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 |
---|---|---|
|
@@ -14,7 +14,7 @@ jobs: | |
- name: Setup Pages | ||
uses: actions/[email protected] | ||
|
||
- name: Download Latest Docs Artifact | ||
- name: Download All Docs Artifact | ||
uses: actions/[email protected] | ||
with: | ||
pattern: docs-* | ||
|
This file contains 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,32 @@ | ||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
version_switcher: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout PtyPy Code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Upload index.html as Artifact | ||
uses: actions/[email protected] | ||
with: | ||
name: docs-index-html | ||
path: .github/pages/index.html | ||
|
||
- name: Download All Docs Artifact | ||
uses: actions/[email protected] | ||
with: | ||
pattern: docs-* | ||
merge-multiple: true | ||
path: ./doc_versions | ||
|
||
- name: Create Switcher File | ||
run: python .github/pages/switcher.py ./doc_versions ${{ github.repository }} .github/pages/switcher.json | ||
|
||
- name: Upload switcher.json as Artifact | ||
uses: actions/[email protected] | ||
with: | ||
name: docs-switcher-json | ||
path: .github/pages/switcher.json | ||
|
This file contains 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