Skip to content

Commit d14618f

Browse files
authored
add no-push option to pretext deploy (#952)
1 parent f2d6b86 commit d14618f

4 files changed

Lines changed: 77 additions & 19 deletions

File tree

pretext/cli.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -945,11 +945,39 @@ def callback(actual_port: int) -> None:
945945
)
946946
@nice_errors
947947
@click.pass_context
948-
@click.option("-u", "--update-source", is_flag=True, required=False)
949-
@click.option("-s", "--stage-only", is_flag=True, required=False)
950-
@click.option("-p", "--preview", is_flag=True, required=False)
948+
@click.option(
949+
"-u",
950+
"--update-source",
951+
is_flag=True,
952+
required=False,
953+
help="Commit and push changes tot he source files at the same time as deploying output.",
954+
)
955+
@click.option(
956+
"-s",
957+
"--stage-only",
958+
is_flag=True,
959+
required=False,
960+
help="Create a staged deployment, but do not deploy.",
961+
)
962+
@click.option(
963+
"-p",
964+
"--preview",
965+
is_flag=True,
966+
required=False,
967+
help="Preview the staged deployment, but do not actually deploy.",
968+
)
969+
@click.option(
970+
"--no-push",
971+
is_flag=True,
972+
required=False,
973+
help="Do not push to remote. Useful for CI/CD workflows or in case of authentication errors.",
974+
)
951975
def deploy(
952-
ctx: click.Context, update_source: bool, stage_only: bool, preview: bool
976+
ctx: click.Context,
977+
update_source: bool,
978+
stage_only: bool,
979+
preview: bool,
980+
no_push: bool,
953981
) -> None:
954982
"""
955983
Automatically deploys project to GitHub Pages,
@@ -963,11 +991,13 @@ def deploy(
963991
project = ctx.obj["project"]
964992
project.stage_deployment()
965993
if stage_only:
994+
# Stop here
966995
return
967996
if preview:
997+
# run view command
968998
ctx.invoke(view, stage=True)
969999
else:
970-
project.deploy(update_source=update_source, skip_staging=True)
1000+
project.deploy(update_source=update_source, skip_staging=True, no_push=no_push)
9711001

9721002

9731003
# pretext import

pretext/project/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1610,11 +1610,14 @@ def deploy(
16101610
update_source: bool = True,
16111611
stage_only: bool = False,
16121612
skip_staging: bool = False,
1613+
no_push: bool = False,
16131614
) -> None:
16141615
if not skip_staging:
16151616
self.stage_deployment()
16161617
if not stage_only:
1617-
utils.publish_to_ghpages(self.stage_abspath(), update_source)
1618+
utils.publish_to_ghpages(
1619+
self.stage_abspath(), update_source, no_push=no_push
1620+
)
16181621

16191622
def is_git_managed(self) -> bool:
16201623
return (self.abspath() / ".git").exists()

pretext/resources/resource_hash_table.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,16 @@
8282
".gitignore": "4a7a09d3441f01b6a9bf658e68d1deff640b6b2cf463af3f5e77c2507600b602",
8383
".devcontainer.json": "d65bac0873f7f46bbc636b2854c7a3bc8e7f21028885a624b9745d53ef4e95f9",
8484
"pretext-cli.yml": "0ea2df984dcfb76ecfaa9bfde26a0da22c006fca1fafd156ca6c57c75679b907"
85+
},
86+
"2.15.3": {
87+
"project.ptx": "04a5cc261a1e79a9f343e09453ec4f9e33db72d41558c99e809f5f79a5500302",
88+
"codechat_config.yaml": "c5fd966cb16207a319bfea049202128f5138acd0a6c6b16a79146723209c3c6f",
89+
".gitignore": "cc22fcc43511794aaca2fb780622ac41942323f66b6177377ac21b058b26df5d",
90+
"devcontainer.json": "ca9b8929b791644c6f051c2b02552438a8d042362ab53da4aca039c8e0e41124",
91+
"pretext-cli.yml": "8b77b4d693dc8bf373e536f48a0fe03d0772c50bd4aef9097fc1ff9d0f8de197",
92+
"installPretext.sh": "fef7c96f58879bbbb81eed409f53b41561750d34dbac2edae8a82af2e9a8502e",
93+
"installPandoc.sh": "615e3111ba699ee387e3f1dd829a4d19f3be0f5dea94895f5f52fcb7dac48dfd",
94+
"installLatex.sh": "2a72ac6d45c58c81126e7d743113f4d08510496d0ae8ce015c18da6f2a954968",
95+
"installSage.sh": "66364cf54d30a278a3de9cf643e0497548a5f49b7c738bfc2dd56088471813f9"
8596
}
8697
}

pretext/utils.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,9 @@ def parse_git_remote(string: str) -> t.List[str]:
630630
return repo_info[-2:]
631631

632632

633-
def publish_to_ghpages(directory: Path, update_source: bool) -> None:
633+
def publish_to_ghpages(
634+
directory: Path, update_source: bool, no_push: bool = False
635+
) -> None:
634636
"""
635637
Publish the current project to GitHub pages.
636638
"""
@@ -666,13 +668,13 @@ def publish_to_ghpages(directory: Path, update_source: bool) -> None:
666668
repo.active_branch.rename("main")
667669
log.info("Successfully initialized new Git repository!")
668670
log.info("")
669-
log.info(f"Preparing to deploy from active `{repo.active_branch.name}` git branch.")
670-
log.info("")
671+
log.info(
672+
f"Preparing to deploy from active `{repo.active_branch.name}` git branch.\n"
673+
)
671674
if repo.bare or repo.is_dirty() or len(repo.untracked_files) > 0:
672675
log.info("Changes to project source since last commit detected.")
673676
if update_source:
674-
log.info("Add/committing these changes to local Git repository.")
675-
log.info("")
677+
log.info("Committing these changes to local Git repository.\n")
676678
repo.git.add(all=True)
677679
repo.git.commit(message="Update to PreTeXt project source.")
678680
# Should we push this commit?
@@ -684,12 +686,10 @@ def publish_to_ghpages(directory: Path, update_source: bool) -> None:
684686
"Just deploying your built project will not save changes to your source on GitHub.`"
685687
)
686688
# Note, we no longer return here; continue with deployment even though repo isn't clean.
687-
688689
try:
689690
origin = repo.remotes.origin
690691
except AttributeError:
691-
log.warning("Remote GitHub repository is not yet configured.")
692-
log.info("")
692+
log.warning("Remote GitHub repository is not yet configured.\n")
693693
log.info(
694694
"And if you haven't already, create a remote GitHub repository for this project at:"
695695
)
@@ -724,6 +724,7 @@ def publish_to_ghpages(directory: Path, update_source: bool) -> None:
724724
directory,
725725
mesg="Latest build deployed.",
726726
nojekyll=True,
727+
no_history=True,
727728
)
728729
log.info(f"Attempting to connect to remote repository at `{origin.url}`...")
729730
# log.info("(Your SSH password may be required.)")
@@ -736,24 +737,37 @@ def publish_to_ghpages(directory: Path, update_source: bool) -> None:
736737
pages_url = f"https://{repo_name}"
737738
else:
738739
pages_url = f"https://{repo_user}.github.io/{repo_name}/"
739-
except Exception:
740+
except Exception as e:
740741
log.error(f"Unable to parse GitHub URL from {origin.url}")
741742
log.error("Deploy unsuccessful")
743+
log.debug(e, exc_info=True)
742744
return
745+
# Stop here if we are not pushing to GitHub.
746+
if no_push:
747+
log.info(
748+
"Skipping push to GitHub. You can push manually with `git push origin gh-pages`."
749+
)
750+
log.info("")
751+
log.info("Output committed to the `gh-pages` branch.")
752+
return
753+
# Otherwise we try to push to GitHub.
743754
try:
744755
origin.push(refspec=f"{repo.active_branch.name}:{repo.active_branch.name}")
745756
origin.push(refspec="gh-pages:gh-pages")
746-
except git.exc.GitCommandError: # type: ignore
757+
except git.exc.GitCommandError as e: # type: ignore
747758
log.warning(
748-
f"There was an issue connecting to GitHub repository located at {repo_url}"
759+
f"There was an issue connecting to GitHub repository located at {repo_url}\n"
749760
)
750-
log.info("")
761+
log.debug(e, exc_info=True)
751762
log.info(
752763
"Make sure you have set up authentication for GitHub. For more information, visit:"
753764
)
754765
log.info(" https://docs.github.com/en/authentication")
755766
log.info(
756-
"Make sure you can push changes, either from the command line or in VS Code. Then try to deploy again."
767+
"Make sure you can push changes, either from the command line or in VS Code. Then try to deploy again.\n"
768+
)
769+
log.info(
770+
"You can also try to run `pretext deploy --no-push` to skip this step, then switch to the `gh-pages` branch (using `git checkout gh-pages`) and push manually."
757771
)
758772
log.info("")
759773
log.info(f"(If `{origin.url}` doesn't match your GitHub repository,")

0 commit comments

Comments
 (0)