def init_environment(): # Create the agent first globals()['puppet_agent'] = PuppetAgent(workspace = WORKSPACE, stub_branch = identity) puppet_agent.reset_branch(AGENT_BRANCH) puppet_agent[AGENT_BRANCH]( rewrite_file("VERSION", AGENT_BRANCH.replace("x", "30")), commit("Rewrite the version file for the agent repo!") ) # Now create each of the components for component, (constructor, branch) in COMPONENT_BRANCHES.items(): edited_name = component.replace("-", "_") globals()[edited_name] = constructor(workspace = WORKSPACE, puppet_agent = puppet_agent, stub_branch = identity, update_ref = False) globals()[edited_name].reset_branch(branch) globals()[edited_name].update_url(branch) prev_version = branch.replace("x", "30") next_version = branch.replace("x", "31") globals()[edited_name].in_repo(sequence( lambda : git('push --delete origin %s' % prev_version), lambda : git('tag --delete origin %s' % prev_version), )) globals()[edited_name][branch]( bump_version(prev_version), bump_version(next_version) ) tag_sha = globals()[edited_name].in_branch(branch, exec_stdout('git', 'rev-parse', 'HEAD^')).decode("utf-8") globals()[edited_name].in_repo(sequence( lambda : git('tag -a %s %s -m "Tagging to %s!"' % (prev_version, tag_sha, prev_version)), lambda : git('push origin --tags') )) puppet_agent[AGENT_BRANCH]( bump_component(component, "refs/tags/%s" % prev_version), commit("Pinning '%s' back to previous tag!" % component) )
def reset_component(component_repo): revert_new_maint_branch(component_repo) component_repo.update_url("master") component_repo["master"]( code_change("Creating a 'code-change' merge-base!")) latest = latest_maint_branch(component_repo) fix_version = to_fix_version(latest) component_repo[latest](git_action("reset --hard refs/heads/master"), bump_version(fix_version)) component_repo.update_url(latest) component_repo.in_branch( latest, sequence( delete_tag(fix_version), git_action("tag -a %s -m 'Setting up a z-release tag!'" % fix_version), push('--tags --force'))) # Push all changes made to the component to origin component_repo[latest](noop_action, push=True) component_repo["master"](noop_action, push=True) agent_repo = component_repo.puppet_agent latest = latest_maint_branch(agent_repo) agent_repo[latest]( bump_component(component_repo.component_name, "refs/tags/%s" % fix_version), commit("Pinning %s to the tag %s!" % (component_repo.component_name, fix_version)), )
def to_branch(self, branch, *actions, **kwargs): prompt_push = self.prompt_push if not kwargs.get('prompt_push') is None: prompt_push = kwargs.get('prompt_push') if kwargs.get('push', False): actions = actions + (push('--force', prompt_push), self.__print_context()) self.in_branch(branch, sequence(*actions))
def revert_new_maint_branch(repo): repo.reset_branch("master") master_version = repo.in_branch("master", read_version) maint_branch = to_maint_branch(master_version) repo.in_branch( "master", sequence(git_action("branch -D %s" % maint_branch), git_action("push origin --delete %s" % maint_branch)))
def setup_happy_cases(): init_environment() # facter, pxp-agent, and puppet will be the ones that will be bumped for (component, branch) in [(facter, "3.6.x"), (puppet, "4.10.x"), (pxp_agent, "1.5.x")]: next_version = branch.replace("x", "31") component[branch](bump_version(next_version), update_ref=True) component.in_repo( sequence( lambda: git('push --delete origin %s' % next_version), lambda: git('tag --delete origin %s' % next_version), ))
def no_code_changes_case(): reset_environment("no-code-changes") no_code_change_features = ("one", "two", "three", "four") hiera["3.4.x"]( sequence(*[ add_feature( "%s" % name, "Added no-code-change feature '%s' [no-promote]" % name) for name in no_code_change_features ]), add_feature( "five", "Added no-code-change feature 'five'\n\nHere is the [no-promote] tag in the message body!" ))
def reset_branch(self, branch, **kwargs): @to_action def print_reset_info(): print("RESETTING BRANCH %s ..." % branch) remote = kwargs.get('remote', 'upstream') if remote != "origin" and not remote in self.remotes.keys(): raise Exception("'%s' is not a part of this repository's remotes!") self.in_branch(branch, sequence( print_reset_info(), git_action('fetch %s' % remote), git_action('reset --hard %s/%s' % (remote, branch)), git_action('clean -f -d') )) if kwargs.get('push', False): self.in_branch(branch, push('--set-upstream origin %s --force' % self.branches[branch], self.prompt_push), ) self.in_branch(branch, self.__print_context())
git, git_head, sequence, exec_stdout) from workflow.actions.repo_actions import (bump_version, bump_component) from workflow.actions.file_actions import (new_file, modify_line, rewrite_file) import os # The agent branch itself AGENT_BRANCH = "5.3.x" RELEASE_BRANCH = AGENT_BRANCH.replace("x", "50") + "-release" GITHUB_DIR = "%s/%s" % (os.environ['HOME'], "GitHub") WORKSPACE = "%s/%s" % (GITHUB_DIR, "puppet-agent-workflow/workspaces/PA-1762") # Create the agent first globals()['puppet_agent'] = PuppetAgent(workspace=WORKSPACE, stub_branch=identity, use_private_fork=True) puppet_agent.reset_branch(AGENT_BRANCH) puppet_agent.in_repo( sequence( lambda: git('branch -D %s' % RELEASE_BRANCH), lambda: git('checkout -b %s' % RELEASE_BRANCH), lambda: git('push --set-upstream origin %s --force' % RELEASE_BRANCH))) puppet_agent.in_repo( sequence( lambda: new_file("feature_one", "first feature")("", ""), lambda: new_file("feature_two", "second feature")("", ""), lambda: commit("Added some features to set-up stuff to merge-up") ("", ""), lambda: git("push")))
def sequence(*version_bumpers): return lambda version: utils.sequence( *[version_bumper(version) for version_bumper in version_bumpers])
globals()[edited_name].in_repo( sequence( lambda: git('tag -a %s %s -m "Tagging to %s!"' % (prev_version, tag_sha, prev_version)), lambda: git('push origin --tags'))) puppet_agent[AGENT_BRANCH]( bump_component(component, "refs/tags/%s" % prev_version), commit("Pinning '%s' back to previous tag!" % component)) def setup_happy_cases(): init_environment() # facter, pxp-agent, and puppet will be the ones that will be bumped for (component, branch) in [(facter, "3.6.x"), (puppet, "4.10.x"), (pxp_agent, "1.5.x")]: next_version = branch.replace("x", "31") component[branch](bump_version(next_version), update_ref=True) component.in_repo( sequence( lambda: git('push --delete origin %s' % next_version), lambda: git('tag --delete origin %s' % next_version), )) setup_happy_cases() puppet_agent.in_repo( sequence( lambda: git('branch -D %s' % AGENT_VERSION), lambda: git('checkout -b %s' % AGENT_VERSION), lambda: git('push --set-upstream origin %s --force' % AGENT_VERSION)))
def n_times(commit_action, n): return sequence(*[commit_action("%s" % i) for i in range(1, n + 1)])
def create_commit(msg): return sequence(new_file(uuid.uuid4().hex, "new temporary file"), commit(msg))
def delete_tag(tag): return sequence(git_action('tag -d %s' % tag), git_action('push origin :refs/tags/%s' % tag))
def add_feature(feature_name, commit_msg): return sequence(new_file(feature_name, "contents"), commit(commit_msg))