async def test_init_working_dir(mocker, branch): """init_working_dir should initialize a valid git repo, and clean up after itself""" repo_url = "https://github.com/mitodl/release-script.git" access_token = "fake_access_token" check_call_mock = mocker.async_patch("lib.check_call") default_branch = "a_branch" mocker.async_patch("lib.get_default_branch", return_value=default_branch) async with init_working_dir( access_token, repo_url, branch=branch, ) as other_directory: assert os.path.exists(other_directory) assert not os.path.exists(other_directory) calls = check_call_mock.call_args_list assert [call[0][0] for call in calls] == [ ["git", "init", "-q"], ["git", "config", "push.default", "simple"], [ "git", "remote", "add", "origin", url_with_access_token(access_token, repo_url), ], ["git", "fetch", "--tags", "-q"], [ "git", "checkout", default_branch if branch is None else branch, "-q" ], ]
def finish_release(repo_url, version): """Merge release to master and deploy to production""" validate_dependencies() with init_working_dir(repo_url): check_release_tag(version) merge_release_candidate() tag_release(version) merge_release()
async def finish_release(*, github_access_token, repo_url, version, timezone): """Merge release to master and deploy to production""" await validate_dependencies() async with init_working_dir(github_access_token, repo_url) as working_dir: await check_release_tag(version, root=working_dir) await set_release_date(version, timezone, root=working_dir) await merge_release_candidate(root=working_dir) await tag_release(version, root=working_dir) await merge_release(root=working_dir)
def finish_release(*, github_access_token, repo_url, version, timezone): """Merge release to master and deploy to production""" validate_dependencies() with init_working_dir(github_access_token, repo_url): check_release_tag(version) set_release_date(version, timezone) merge_release_candidate() tag_release(version) merge_release()
async def is_release_deployed(*, github_access_token, repo_url, hash_url, branch): """ Is server finished with the deploy? """ async with init_working_dir(github_access_token, repo_url) as working_dir: output = await check_output( ["git", "rev-parse", "origin/{}".format(branch)], cwd=working_dir) latest_hash = output.decode().strip() return await fetch_release_hash(hash_url) == latest_hash
async def test_init_working_dir_real(): """make sure init_working_dir can pull and checkout a real repo""" # the fake access token won't matter here since this operation is read-only repo_url = "https://github.com/mitodl/release-script.git" access_token = "" async with init_working_dir( access_token, repo_url, ) as other_directory: assert os.path.exists(other_directory) check_call(["git", "status"], cwd=other_directory) assert not os.path.exists(other_directory)
async def wait_for_deploy(repo_url, hash_url, watch_branch): """Wait until server is finished with the deploy""" validate_dependencies() with init_working_dir(repo_url): latest_hash = check_output( ["git", "rev-parse", "origin/{}".format(watch_branch)]).decode().strip() print("Polling {url} for {hash}...".format(url=hash_url, hash=latest_hash)) while fetch_release_hash(hash_url) != latest_hash: await asyncio.sleep(30) print(".", end='') print("Hashes match, deployment was successful!")
async def commits_since_last_release(self, command_args): """ Have doof show the release notes since the last release Args: command_args (CommandArgs): The arguments for this command """ repo_info = command_args.repo_info with init_working_dir(self.github_access_token, repo_info.repo_url): last_version = update_version("9.9.9") release_notes = create_release_notes(last_version, with_checkboxes=False) await self.say_with_attachment( channel_id=repo_info.channel_id, title="Release notes since {}".format(last_version), text=release_notes, )
async def finish_release(*, github_access_token, repo_info, version, timezone): """ Merge release to master and deploy to production Args: github_access_token (str): Github access token repo_info (RepoInfo): The info of the project being released version (str): The new version of the release timezone (any): Some timezone object to set the proper release datetime string """ await validate_dependencies() async with init_working_dir(github_access_token, repo_info.repo_url) as working_dir: await check_release_tag(version, root=working_dir) await set_release_date(version, timezone, root=working_dir) await merge_release_candidate(root=working_dir) await tag_release(version, root=working_dir) await merge_release(root=working_dir)
async def commits_since_last_release(self, repo_info): """ Have doof show the release notes since the last release Args: repo_info (RepoInfo): The info for a repo """ with init_working_dir(repo_info.repo_url): last_version = update_version("9.9.9") release_notes = create_release_notes(last_version, with_checkboxes=False) await self.say( repo_info.channel_id, "Release notes since {version}...\n\n{notes}".format( version=last_version, notes=release_notes, ), )
async def _upload_to_pypi(self, *, command_args, testing): """ Upload package for version to pypi server Args: command_args (CommandArgs): The arguments for this command """ repo_info = command_args.repo_info version = command_args.args[0] with init_working_dir(self.github_access_token, repo_info.repo_url, branch="v{}".format(version)): upload_to_pypi(repo_info=repo_info, testing=testing) await self.say( channel_id=command_args.channel_id, text='Successfully uploaded {version} to {pypi_server}.'.format( version=version, pypi_server="pypitest" if testing else "pypi", ), )
async def wait_for_deploy(*, github_access_token, repo_url, hash_url, watch_branch): """ Wait until server is finished with the deploy Args: github_access_token (str): A github access token repo_url (str): The repository URL which has the latest commit hash to check hash_url (str): The deployment URL which has the commit of the deployed app watch_branch (str): The branch in the repository which has the latest commit Returns: bool: True if the hashes matched immediately on checking, False if hashes matched only after checking """ async with init_working_dir(github_access_token, repo_url) as working_dir: output = await check_output( ["git", "rev-parse", f"origin/{watch_branch}"], cwd=working_dir ) latest_hash = output.decode().strip() while await fetch_release_hash(hash_url) != latest_hash: await asyncio.sleep(30)
def test_init_working_dir(): """init_working_dir should initialize a valid git repo, and clean up after itself""" repo_url = "https://github.com/mitodl/release-script.git" access_token = 'fake_access_token' with patch('release.check_call', autospec=True) as check_call_mock, init_working_dir( access_token, repo_url, ) as other_directory: assert os.path.exists(other_directory) assert not os.path.exists(other_directory) calls = check_call_mock.call_args_list assert [call[0][0] for call in calls] == [ ['git', 'init'], [ 'git', 'remote', 'add', 'origin', url_with_access_token(access_token, repo_url) ], ['git', 'fetch'], ['git', 'checkout', '-t', 'origin/master'], ]
async def test_init_working_dir(mocker, branch): """init_working_dir should initialize a valid git repo, and clean up after itself""" repo_url = "https://github.com/mitodl/release-script.git" access_token = 'fake_access_token' check_call_mock = mocker.async_patch('lib.check_call') async with init_working_dir( access_token, repo_url, branch=branch, ) as other_directory: assert os.path.exists(other_directory) assert not os.path.exists(other_directory) calls = check_call_mock.call_args_list assert [call[0][0] for call in calls] == [ ['git', 'init', '-q'], ['git', 'config', 'push.default', 'simple'], [ 'git', 'remote', 'add', 'origin', url_with_access_token(access_token, repo_url) ], ['git', 'fetch', '--tags', '-q'], ['git', 'checkout', "master" if branch is None else branch, '-q'], ]
def get_version_tag(github_access_token, repo_url, commit_hash): """Determines the version tag (or None) of the given commit hash""" with init_working_dir(github_access_token, repo_url): return check_output(["git", "tag", "-l", "--points-at", commit_hash]).decode().strip()
def test_init_working_dir(test_repo): """init_working_dir should initialize a valid git repo, and clean up after itself""" with init_working_dir(os.path.abspath(".git")) as other_directory: os.chdir(other_directory) check_call(["git", "status"]) assert not os.path.exists(other_directory)