Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deploy): added a --set-default flag to set the deployed version the new default #210

Closed
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ the setting of `alias_type`/`--alias-type`.)
Like `deploy` and `delete` above, you can specify `--branch`, `--push`,
etc to control how the commit is handled.

As with `deploy`, you can pass `-d`/`--set-default` to set the published version
as the new default.

### Changing a Version's Title

As you update your docs, you may want to change the title of a particular
Expand Down
10 changes: 9 additions & 1 deletion mike/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def make_nojekyll():
@contextmanager
def deploy(cfg, version, title=None, aliases=[], update_aliases=False,
alias_type=AliasType.symlink, template=None, *, branch='gh-pages',
message=None, allow_empty=False, deploy_prefix='', set_props=[]):
message=None, allow_empty=False, deploy_prefix='', set_props=[],
set_default=False):
if message is None:
message = (
'Deployed {rev} to {doc_version}{deploy_prefix} with MkDocs ' +
Expand Down Expand Up @@ -118,6 +119,13 @@ def deploy(cfg, version, title=None, aliases=[], update_aliases=False,
commit.add_file(versions_to_file_info(all_versions, deploy_prefix))
commit.add_file(make_nojekyll())

if set_default:
t = _redirect_template(template)
commit.add_file(git_utils.FileInfo(
os.path.join(deploy_prefix, 'index.html'),
t.render(href=version_str + '/')
))


def delete(identifiers=None, all=False, *, branch='gh-pages', message=None,
allow_empty=False, deploy_prefix=''):
Expand Down
5 changes: 4 additions & 1 deletion mike/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ def deploy(parser, args):
branch=args.branch, message=args.message,
allow_empty=args.allow_empty,
deploy_prefix=args.deploy_prefix,
set_props=args.set_props or []), \
set_props=args.set_props or [],
set_default=args.set_default), \
mkdocs_utils.inject_plugin(args.config_file) as config_file:
mkdocs_utils.build(config_file, args.version)
if args.push:
Expand Down Expand Up @@ -350,6 +351,8 @@ def main():
'%(choices)s; default: symlink)'))
deploy_p.add_argument('-T', '--template', complete='file',
help='template file to use for redirects')
deploy_p.add_argument('-d', '--set-default', action='store_true',
help='set the deployed version as the new default')
add_git_arguments(deploy_p)
add_set_prop_arguments(deploy_p, prefix='prop-')
deploy_p.add_argument('version', metavar='VERSION',
Expand Down
9 changes: 9 additions & 0 deletions test/integration/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ def test_update_aliases_with_version(self):
versions.VersionInfo('1.0b1'),
])

def test_set_default(self):
assertPopen(['mike', 'deploy', '1.0', '--set-default'])
check_call_silent(['git', 'checkout', 'gh-pages'])
self._test_deploy(expected_versions=[
versions.VersionInfo('1.0'),
])
with open('index.html') as f:
self.assertRegex(f.read(), match_redir('1.0/'))

def test_from_subdir(self):
os.mkdir('sub')
with pushd('sub'):
Expand Down
14 changes: 13 additions & 1 deletion test/unit/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ def setUp(self):
commit_files(['page.html', 'file.txt', 'dir/index.html'])

def _test_state(self, expected_message, expected_versions,
alias_type=AliasType.symlink, directory='.'):
alias_type=AliasType.symlink, directory='.',
expected_files=None):
message = check_output(['git', 'log', '-1', '--pretty=%B']).rstrip()
self.assertRegex(message, expected_message)

files = {'versions.json'}
if expected_files:
files.update(expected_files)
for v in expected_versions:
vstr = str(v.version)
files |= {vstr, vstr + '/page.html', vstr + '/file.txt',
Expand Down Expand Up @@ -281,6 +284,15 @@ def test_update_aliases(self):
versions.VersionInfo('1.0', '1.0', []),
])

def test_set_default(self):
with commands.deploy(self.cfg, '1.0', set_default=True):
self._mock_build()
check_call_silent(['git', 'checkout', 'gh-pages'])
self._test_deploy(expected_files=["index.html"])

with open('index.html') as f:
self.assertRegex(f.read(), match_redir("1.0/"))


class TestDelete(TestBase):
stage_dir = 'delete'
Expand Down