Ejemplo n.º 1
0
 def git_setup(user="******", email="*****@*****.**"):
     """git config --global user.email, user.name
     Args:
         user (str, optional): username, defaults to "GitHub Actions"
         email (str, optional): e-mail, defaults to "*****@*****.**"
     """
     if 'CI' not in os.environ:
         return
     Console.run('git config --global user.email "' + email + '"',
                 GHA.git_dir)
     Console.run('git config --global user.name "' + user + '"',
                 GHA.git_dir)
Ejemplo n.º 2
0
    def git_add(pathspec):
        """git add `pathspec` from current branch in git_dir to target_branch
        Args:
            pathspec (str): files to add, can be a fileglob
        Returns:
            str: commit hash or False
        """
        if 'CI' not in os.environ:
            return False
        Console.run('git add ' + pathspec, GHA.git_dir)

        return Console.run('git rev-parse HEAD', GHA.git_dir)
Ejemplo n.º 3
0
 def git_clone(repo_slug):
     """git clone
     Args:
         repo_slug (str): "user/repo", defaults to the one used
             by GHA
     """
     if 'CI' not in os.environ:
         return
     token = os.environ['GH_TOKEN']
     Console.run('git clone '
                 + 'https://'
                 + token + '@github.com/'
                 + repo_slug + '.git > /dev/null 2>&1')
Ejemplo n.º 4
0
 def git_unbork_gha_root(repo_slug=None):
     """git remove and re-add origin
     Args:
         repo_slug (str, optional): "user/repo", defaults to the one used
             by GHA
     """
     if 'CI' not in os.environ:
         return
     if not repo_slug:
         repo_slug = os.environ['GITHUB_REPOSITORY']
     token = os.environ['GH_TOKEN']
     Console.run('git remote set-url origin https://'
                 + token + '@github.com/'
                 + repo_slug + '.git > /dev/null 2>&1')
Ejemplo n.º 5
0
 def git_get_commit():
     """get latest git commit message from current branch/repo
     Returns:
         str: commit hash or False
     """
     if 'CI' not in os.environ:
         return False
     return Console.run('git log -1 --pretty=%B', GHA.git_dir)
Ejemplo n.º 6
0
    def git_commit_all(message, sanitize=True):
        """git commit from current branch in git_dir to target_branch
        Args:
            message (str): branch name to push to
            sanitize (bool, optional): whether to bash-sanitize message,
                defaults to True
        Returns:
            str: commit hash or False
        """
        if 'CI' not in os.environ:
            return False
        if sanitize:
            Console.run('git commit -am "' + message.replace('"', '\\"') + '"',
                        GHA.git_dir)
        else:
            Console.run('git commit -am "' + message + '"', GHA.git_dir)

        return Console.run('git rev-parse HEAD', GHA.git_dir)
Ejemplo n.º 7
0
 def git_push(target_branch='master'):
     """force git push from current branch in git_dir to target_branch
     Args:
         target_branch (str): branch name to push to
     Returns:
         str: commit hash or False
     """
     if 'CI' not in os.environ:
         return False
     Console.run('pwd', GHA.git_dir)
     Console.run('env', GHA.git_dir)
     Console.run('cat .git/config', GHA.git_dir)
     Console.run('git push origin $(git rev-parse --abbrev-ref HEAD):'
                 + target_branch
                 + ' --quiet',
                 GHA.git_dir)
     return Console.run('git rev-parse HEAD', GHA.git_dir)
Ejemplo n.º 8
0
 def git_checkout(branch):
     """git checkout
     Args:
         branch (str): branch name
     Returns:
         bool: non-False if script is running on GHA CI
     """
     if 'CI' not in os.environ:
         return False
     Console.run('cd ' + GHA.git_dir)
     Console.run('git fetch', GHA.git_dir)
     Console.run('git checkout ' + branch, GHA.git_dir)
     return True