Skip to content

Commit 1d79573

Browse files
Massimiliano Pippimasci
Massimiliano Pippi
authored andcommitted
expand build.py CLI to simplify action's code
1 parent 15a569b commit 1d79573

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

.github/workflows/docs.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ jobs:
8080
- name: Publish docs
8181
# determine docs version for the commit pushed and publish accordingly using Mike
8282
if: github.event_name == 'push'
83-
env:
84-
REMOTE: https://x-access-token:${{secrets.GITHUB_TOKEN}}@github.com/${{github.repository}}.git
8583
run: |
8684
git config --global user.email "bot@arduino.cc"
8785
git config --global user.name "ArduinoBot"
88-
python docs/build.py
86+
git remote add upstream https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
87+
python docs/build.py --remote upstream

docs/build.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import unittest
1919
import subprocess
2020

21+
import click
2122
from git import Repo
2223

2324

@@ -75,11 +76,19 @@ def get_rel_branch_names(blist):
7576
return sorted(names, key=lambda x: int(x.split(".")[1]), reverse=True)
7677

7778

78-
def main(repo_dir):
79-
# Git remote must be set to publish docs
80-
remote = os.environ.get("REMOTE")
81-
if not remote:
82-
print("REMOTE env var must be set to publish, running dry mode")
79+
@click.command()
80+
@click.option("--test", is_flag=True)
81+
@click.option("--dry", is_flag=True)
82+
@click.option("--remote", default="origin", help="The git remote where to push.")
83+
def main(test, dry, remote):
84+
# Run tests if requested
85+
if test:
86+
unittest.main(argv=[""], exit=False)
87+
sys.exit(0)
88+
89+
# Detect repo root folder
90+
here = os.path.dirname(os.path.realpath(__file__))
91+
repo_dir = os.path.join(here, "..")
8392

8493
# Get current repo
8594
repo = Repo(repo_dir)
@@ -102,12 +111,12 @@ def main(repo_dir):
102111
f"DOCS_VERSION={docs_version}",
103112
f"DOCS_ALIAS={alias}",
104113
]
105-
if remote:
106-
subprocess.run(args, shell=True, check=True, cwd=repo_dir)
107-
else:
114+
115+
if dry:
108116
print(" ".join(args))
117+
return 0
109118

110-
return 0
119+
subprocess.run(args, shell=True, check=True, cwd=repo_dir)
111120

112121

113122
# Usage:
@@ -119,9 +128,4 @@ def main(repo_dir):
119128
# $python build.py
120129
#
121130
if __name__ == "__main__":
122-
if len(sys.argv) > 1 and sys.argv[1] == "test":
123-
unittest.main(argv=[""], exit=False)
124-
sys.exit(0)
125-
126-
here = os.path.dirname(os.path.realpath(__file__))
127-
sys.exit(main(os.path.join(here, "..")))
131+
sys.exit(main())

requirements_docs.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mkdocs<1.2
22
mkdocs-material<5
33
mike
4-
gitpython
4+
gitpython
5+
click<7.2

0 commit comments

Comments
 (0)