__init__.py 3.58 KB
Newer Older
Emmanuel Milou's avatar
Emmanuel Milou committed
1
2
import docker
from deploy  import *
3
import drush
4
import behat
5
import patternlab
6
7
from .environments import e

8
from fabric.api import task, env, execute
9
10

import helpers as h
Samuel Sirois's avatar
Samuel Sirois committed
11
import re
12
13
from os import path
from fabric.colors import red, green
14
15
16
17
18
19
20
21
22
23

@task
def init():
    """
    Complete local installation process, used generally when building the docker image for install and configure Drupal.
    """

    execute(docker.image_create)
    execute(docker.container_start)
    execute(drush.make, 'install')
24
    execute(drush.site_install, host='root@{}'.format(env.container_ip))
25
    execute(drush.aliases)
26
    execute(behat.init, host='root@{}'.format(env.container_ip))
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53



@task
def test():
    """
    Setup Behat and run the complete tests suite. Default output formatters: pretty and JUnit.
    The JUnit report file is specified in the Behat configuration file. Default: tests/behat/out/behat.junit.xml.

    :param tag Specific Behat tests tags to run.

    """
    execute(behat.init)
    execute(behat.run)



@task
def install():

    """
    Run the full installation process.
    """

    execute(drush.make, 'install')
    execute(drush.site_install)
    execute(behat.init)
54

55
56
57
58
59
60
61
62
63


@task
def update():

    """
    Update the full codebase and run the availabe database updates.
    """

64
    verif()
65
66
67
    execute(drush.make, 'update')
    execute(drush.updatedb)
    execute(behat.init)
68

69
70
71
72
73
74
75
76
@task
def verif():
    # STEP 1
    h.fab_cd('local', env.workspace)
    repos = local('find ./ -type d -name ".git"', capture=True).splitlines()
    for repo in repos:
        repoLocalPath = path.normpath(path.join(env.workspace, repo, '..'))
        with h.fab_cd('local', repoLocalPath):
Samuel Sirois's avatar
Samuel Sirois committed
77
78
            print green('Verify repo in ' + repoLocalPath)

79
            remoteName = local('git remote', capture=True)
Samuel Sirois's avatar
Samuel Sirois committed
80
81

            localBranches = _getLocalBranchNames()
82
            for localBranch in localBranches:
Samuel Sirois's avatar
Samuel Sirois committed
83
                if (not _remoteBranchExists(localBranch)):
84
85
86
87
88
89
90
91
92
93
94
95
96
                    print red('Local branch "' + localBranch + '" is not present on "' + remoteName + '" remote.')
                    # to do, la pusher (git push remoteName localBranch)

            # - pour chaque Branch, est ce qu'il y a des commits non-pushes (git branch -vv)
            # - est ce qu'il y a du code non-stage (git status -s)
            # on s'arrete a chaque alerte, et on demande quoi faire...


    # STEP 2
    # plutot que s'arreter ou continuer betement, on est intelligent et on demande quoi faire:
    # - s'il y a du code non-stage, en faire un commit
    # - si la Branch n'est pas trackee, la pusher
    # - s'il y a des commits non pushes, les pusher
97

Samuel Sirois's avatar
Samuel Sirois committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
def _getLocalBranchNames():
    branches = local('git branch --list', capture=True).splitlines()
    branchNames = []
    for (i, branch) in enumerate(branches):
        branchName = branch.replace('*', '').strip()
        if (not _isBranchDetached(branchName)):
            branchNames.append(branchName)

    return branchNames


def _isBranchDetached(branchName):
    pattern = re.compile('\(.*\)')
    return pattern.match(branchName)


def _remoteBranchExists(branchName):
    return (len(local('git branch --list --remote "*' + branchName + '"', capture=True).splitlines()) > 0)


118
119
120
121
122
123
@task
def release():

    """
    Generate all artefacts related to a release process or a deployment process.
    """
124

125
    execute(drush.archive_dump)
126
    execute(drush.gen_doc)
Emmanuel Milou's avatar
Emmanuel Milou committed
127
128
129
130
131
132
133
134


@task
def deploy(environment):
    """Deploy code and run database updates on a target Drupal environment.
    """

    execute(provision, environment)
135
136
    execute(push, environment, hosts=env.hosts)
    execute(migrate, environment, hosts=env.hosts)