Skip to content

Commit

Permalink
Initialize gh-pages branch in the post hook
Browse files Browse the repository at this point in the history
  • Loading branch information
lucmos committed Feb 3, 2022
1 parent 995d2fe commit cda011f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
54 changes: 51 additions & 3 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Dependency:
class Query:
id: str
interactive: bool
default: bool
prompt: str
command: str
autorun: bool
Expand All @@ -64,6 +65,7 @@ class Query:
Query(
id="git_init",
interactive=True,
default=True,
prompt="Initializing git repository...",
command="git init\n"
"git add --all\n"
Expand All @@ -73,23 +75,37 @@ class Query:
Query(
id="git_remote",
interactive=True,
default=True,
prompt="Adding git remote...",
command="git remote add origin [email protected]:{{ cookiecutter.github_user }}/{{ cookiecutter.repository_name }}.git",
autorun=True,
dependencies=[
Dependency(id="git_init", expected=True),
],
),
Query(
id="git_push_main",
interactive=True,
default=True,
prompt="Pushing default branch to existing remote...",
command="git push -u origin HEAD",
autorun=True,
dependencies=[
Dependency(id="git_remote", expected=True),
],
),
Query(
id="conda_env",
interactive=True,
default=True,
prompt="Creating conda environment...",
command="conda env create -f env.yaml",
autorun=True,
),
Query(
id="precommit_install",
interactive=False,
interactive=True,
default=True,
prompt="Installing pre-commits...",
command="conda run -n {{ cookiecutter.conda_env_name }} pre-commit install",
autorun=True,
Expand All @@ -98,9 +114,35 @@ class Query:
Dependency(id="conda_env", expected=True),
],
),
Query(
id="mike_init",
interactive=True,
default=True,
prompt="Initializing gh-pages branch for GitHub Pages...",
command="conda run -n {{ cookiecutter.conda_env_name }} mike deploy --update-aliases 0.0 latest\n"
"conda run -n {{ cookiecutter.conda_env_name }} mike set-default latest",
autorun=True,
dependencies=[
Dependency(id="conda_env", expected=True),
Dependency(id="git_init", expected=True),
],
),
Query(
id="mike_push",
interactive=True,
default=True,
prompt="Pushing 'gh-pages' branch to existing remote...",
command="git push origin gh-pages",
autorun=True,
dependencies=[
Dependency(id="mike_init", expected=True),
Dependency(id="git_remote", expected=True),
],
),
Query(
id="conda_activate",
interactive=False,
default=True,
prompt="Activate your conda environment with:",
command="cd {{ cookiecutter.repository_name }}\n"
"conda activate {{ cookiecutter.conda_env_name }}\n"
Expand Down Expand Up @@ -137,7 +179,7 @@ def setup(setup_commands) -> None:
f'{textwrap.indent(query.command, prefix=" ")}\n'
f"\n"
f"Execute?",
default=True,
default=query.default,
)
else:
print(
Expand Down Expand Up @@ -165,9 +207,15 @@ def setup(setup_commands) -> None:
setup(setup_commands=SETUP_COMMANDS)

print(
"\nYou are all set!\n"
"\nYou are all set!\n\n"
"Remember that if you use PyCharm, you must:\n"
' - Mark the "src" directory as "Sources Root".\n'
' - Enable "Emulate terminal in output console" in the run configuration.\n'
)
print(
"Remember to:\n"
" - Enable the GitHub Actions in the repository.\n"
' - Enable the Github Pages in the "gh-pages" branch, auto-published on each release.'
)

print("Have fun! :]")
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:
run: |
git config user.name ci-bot
git config user.email [email protected]
mike deploy --push --rebase --update-aliases ${RELEASE_TAG_VERSION} latest
mike deploy --rebase --update-aliases ${RELEASE_TAG_VERSION} latest
mike set-default --push --rebase latest
# Uncomment to publish on PyPI on release
Expand Down

0 comments on commit cda011f

Please sign in to comment.