Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions pretext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,11 +945,39 @@ def callback(actual_port: int) -> None:
)
@nice_errors
@click.pass_context
@click.option("-u", "--update-source", is_flag=True, required=False)
@click.option("-s", "--stage-only", is_flag=True, required=False)
@click.option("-p", "--preview", is_flag=True, required=False)
@click.option(
"-u",
"--update-source",
is_flag=True,
required=False,
help="Commit and push changes tot he source files at the same time as deploying output.",
)
@click.option(
"-s",
"--stage-only",
is_flag=True,
required=False,
help="Create a staged deployment, but do not deploy.",
)
@click.option(
"-p",
"--preview",
is_flag=True,
required=False,
help="Preview the staged deployment, but do not actually deploy.",
)
@click.option(
"--no-push",
is_flag=True,
required=False,
help="Do not push to remote. Useful for CI/CD workflows or in case of authentication errors.",
Comment on lines +969 to +973
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me what this does.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it only push the gh-pages branch to deploy? (Not the main/active branch?) Or is this supposed to trigger a CI/CD workflow?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not push anything. So the user (or action) needs to run git push origin gh-pages manually.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action deploys should be using https://github.com/marketplace/actions/deploy-github-pages-site rather than a gh-pages branch, so the CI/CD note here is a little confusing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define "should". I would like to allow a workflow where an author could deploy from the command line or an action, which I think needs to use the pretext deploy command. But that doesn't seem to work on an action for authentication reasons. I'm hoping that this would let the action deploy the branch itself

)
def deploy(
ctx: click.Context, update_source: bool, stage_only: bool, preview: bool
ctx: click.Context,
update_source: bool,
stage_only: bool,
preview: bool,
no_push: bool,
) -> None:
"""
Automatically deploys project to GitHub Pages,
Expand All @@ -963,11 +991,13 @@ def deploy(
project = ctx.obj["project"]
project.stage_deployment()
if stage_only:
# Stop here
return
if preview:
# run view command
ctx.invoke(view, stage=True)
else:
project.deploy(update_source=update_source, skip_staging=True)
project.deploy(update_source=update_source, skip_staging=True, no_push=no_push)


# pretext import
Expand Down
5 changes: 4 additions & 1 deletion pretext/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1610,11 +1610,14 @@ def deploy(
update_source: bool = True,
stage_only: bool = False,
skip_staging: bool = False,
no_push: bool = False,
) -> None:
if not skip_staging:
self.stage_deployment()
if not stage_only:
utils.publish_to_ghpages(self.stage_abspath(), update_source)
utils.publish_to_ghpages(
self.stage_abspath(), update_source, no_push=no_push
)

def is_git_managed(self) -> bool:
return (self.abspath() / ".git").exists()
Expand Down
11 changes: 11 additions & 0 deletions pretext/resources/resource_hash_table.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,16 @@
".gitignore": "4a7a09d3441f01b6a9bf658e68d1deff640b6b2cf463af3f5e77c2507600b602",
".devcontainer.json": "d65bac0873f7f46bbc636b2854c7a3bc8e7f21028885a624b9745d53ef4e95f9",
"pretext-cli.yml": "0ea2df984dcfb76ecfaa9bfde26a0da22c006fca1fafd156ca6c57c75679b907"
},
"2.15.3": {
"project.ptx": "04a5cc261a1e79a9f343e09453ec4f9e33db72d41558c99e809f5f79a5500302",
"codechat_config.yaml": "c5fd966cb16207a319bfea049202128f5138acd0a6c6b16a79146723209c3c6f",
".gitignore": "cc22fcc43511794aaca2fb780622ac41942323f66b6177377ac21b058b26df5d",
"devcontainer.json": "ca9b8929b791644c6f051c2b02552438a8d042362ab53da4aca039c8e0e41124",
"pretext-cli.yml": "8b77b4d693dc8bf373e536f48a0fe03d0772c50bd4aef9097fc1ff9d0f8de197",
"installPretext.sh": "fef7c96f58879bbbb81eed409f53b41561750d34dbac2edae8a82af2e9a8502e",
"installPandoc.sh": "615e3111ba699ee387e3f1dd829a4d19f3be0f5dea94895f5f52fcb7dac48dfd",
"installLatex.sh": "2a72ac6d45c58c81126e7d743113f4d08510496d0ae8ce015c18da6f2a954968",
"installSage.sh": "66364cf54d30a278a3de9cf643e0497548a5f49b7c738bfc2dd56088471813f9"
}
}
40 changes: 27 additions & 13 deletions pretext/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,9 @@ def parse_git_remote(string: str) -> t.List[str]:
return repo_info[-2:]


def publish_to_ghpages(directory: Path, update_source: bool) -> None:
def publish_to_ghpages(
directory: Path, update_source: bool, no_push: bool = False
) -> None:
"""
Publish the current project to GitHub pages.
"""
Expand Down Expand Up @@ -666,13 +668,13 @@ def publish_to_ghpages(directory: Path, update_source: bool) -> None:
repo.active_branch.rename("main")
log.info("Successfully initialized new Git repository!")
log.info("")
log.info(f"Preparing to deploy from active `{repo.active_branch.name}` git branch.")
log.info("")
log.info(
f"Preparing to deploy from active `{repo.active_branch.name}` git branch.\n"
)
if repo.bare or repo.is_dirty() or len(repo.untracked_files) > 0:
log.info("Changes to project source since last commit detected.")
if update_source:
log.info("Add/committing these changes to local Git repository.")
log.info("")
log.info("Committing these changes to local Git repository.\n")
repo.git.add(all=True)
repo.git.commit(message="Update to PreTeXt project source.")
# Should we push this commit?
Expand All @@ -684,12 +686,10 @@ def publish_to_ghpages(directory: Path, update_source: bool) -> None:
"Just deploying your built project will not save changes to your source on GitHub.`"
)
# Note, we no longer return here; continue with deployment even though repo isn't clean.

try:
origin = repo.remotes.origin
except AttributeError:
log.warning("Remote GitHub repository is not yet configured.")
log.info("")
log.warning("Remote GitHub repository is not yet configured.\n")
log.info(
"And if you haven't already, create a remote GitHub repository for this project at:"
)
Expand Down Expand Up @@ -724,6 +724,7 @@ def publish_to_ghpages(directory: Path, update_source: bool) -> None:
directory,
mesg="Latest build deployed.",
nojekyll=True,
no_history=True,
)
log.info(f"Attempting to connect to remote repository at `{origin.url}`...")
# log.info("(Your SSH password may be required.)")
Expand All @@ -736,24 +737,37 @@ def publish_to_ghpages(directory: Path, update_source: bool) -> None:
pages_url = f"https://{repo_name}"
else:
pages_url = f"https://{repo_user}.github.io/{repo_name}/"
except Exception:
except Exception as e:
log.error(f"Unable to parse GitHub URL from {origin.url}")
log.error("Deploy unsuccessful")
log.debug(e, exc_info=True)
return
# Stop here if we are not pushing to GitHub.
if no_push:
log.info(
"Skipping push to GitHub. You can push manually with `git push origin gh-pages`."
)
log.info("")
log.info("Output committed to the `gh-pages` branch.")
return
# Otherwise we try to push to GitHub.
try:
origin.push(refspec=f"{repo.active_branch.name}:{repo.active_branch.name}")
origin.push(refspec="gh-pages:gh-pages")
except git.exc.GitCommandError: # type: ignore
except git.exc.GitCommandError as e: # type: ignore
log.warning(
f"There was an issue connecting to GitHub repository located at {repo_url}"
f"There was an issue connecting to GitHub repository located at {repo_url}\n"
)
log.info("")
log.debug(e, exc_info=True)
log.info(
"Make sure you have set up authentication for GitHub. For more information, visit:"
)
log.info(" https://docs.github.com/en/authentication")
log.info(
"Make sure you can push changes, either from the command line or in VS Code. Then try to deploy again."
"Make sure you can push changes, either from the command line or in VS Code. Then try to deploy again.\n"
)
log.info(
"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."
)
log.info("")
log.info(f"(If `{origin.url}` doesn't match your GitHub repository,")
Expand Down