~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to git_gate.py

  • Committer: Aaron Bentley
  • Date: 2015-07-27 19:19:56 UTC
  • mto: This revision was merged to the branch mainline in revision 1048.
  • Revision ID: aaron.bentley@canonical.com-20150727191956-uz4gdxuv28qhvv94
Use per-client JUJU_HOME.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
    goenv["GOPATH"] = gopath
50
50
    go = SubcommandRunner("go", goenv)
51
51
    git = SubcommandRunner("git")
52
 
 
53
 
    final_project = args.project
54
 
    if args.feature_branch:
55
 
        final_project = from_feature_dir(args.project)
56
 
 
57
 
    project_ellipsis = final_project + "/..."
58
 
    directory = os.path.join(gopath, "src", final_project)
59
 
 
60
 
    if args.tsv_path:
61
 
        print_now("Getting and installing godeps")
62
 
        go("get", "-v", "-d", "github.com/rogpeppe/godeps/...")
63
 
        go("install", "github.com/rogpeppe/godeps/...")
 
52
    project_ellipsis = args.project + "/..."
 
53
    directory = os.path.join(gopath, "src", args.project)
64
54
    if args.project_url:
65
 
        print_now("Cloning {} from {}".format(final_project, args.project_url))
 
55
        print_now("Cloning {} from {}".format(args.project, args.project_url))
66
56
        git("clone", args.project_url, directory)
67
 
    if args.go_get_all and not (args.project_url and args.merge_url):
 
57
    if args.go_get_all:
68
58
        print_now("Getting {} and dependencies using go".format(args.project))
69
59
        go("get", "-v", "-d", "-t", project_ellipsis)
70
60
    os.chdir(directory)
75
65
        print_now("Merging {} ref {}".format(args.merge_url, args.merge_ref))
76
66
        git("fetch", args.merge_url, args.merge_ref)
77
67
        git("merge", "--no-ff", "-m", "Merged " + args.merge_ref, "FETCH_HEAD")
78
 
        if args.go_get_all:
79
 
            print_now("Updating {} dependencies using go".format(args.project))
80
 
            go("get", "-v", "-d", "-t", project_ellipsis)
81
68
    if args.dependencies:
82
69
        for dep in args.dependencies:
83
70
            print_now("Getting {} and dependencies using go".format(dep))
84
71
            go("get", "-v", "-d", dep)
85
 
    if args.tsv_path:
86
 
        tsv_path = os.path.join(gopath, "src", final_project, args.tsv_path)
87
 
        print_now("Getting dependencies using godeps from {}".format(tsv_path))
88
 
        godeps = SubcommandRunner(os.path.join(gopath, "bin", "godeps"), goenv)
89
 
        godeps("-u", tsv_path)
90
72
    go("build", project_ellipsis)
91
73
    go("test", project_ellipsis)
92
74
 
93
75
 
94
 
def from_feature_dir(directory):
95
 
    """
96
 
    For feature branches on repos that are versioned with gopkg.in,  we need to
97
 
    do some special handling, since the test code expects the branch name to be
98
 
    appended to the reponame with a ".".  However, for a feature branch, the
99
 
    branchname is different than the base gopkg.in branch.  To account for
100
 
    this, we use the convention of base_branch_name.featurename, and thus this
101
 
    code can know that it needs to strip out the featurename when locating the
102
 
    code on disk.
103
 
 
104
 
    Thus, the feature branch off of gopkg.in/juju/charm.v6 would be a branch
105
 
    named charm.v6.myfeature, which should end up in
106
 
    $GOPATH/src/gokpg.in/juju/charm.v6
107
 
    """
108
 
    name = os.path.basename(directory)
109
 
    parts = name.split(".")
110
 
    if len(parts) == 3:
111
 
        return directory[:-len(parts[2]) - 1]
112
 
    return directory
113
 
 
114
 
 
115
76
def parse_args(args=None):
116
77
    """Parse arguments for gating script."""
117
78
    parser = argparse.ArgumentParser()
118
79
    project_group = parser.add_argument_group()
119
80
    project_group.add_argument(
120
 
        "--keep", action="store_true",
121
 
        help="Do not remove working dir after testing.")
122
 
    project_group.add_argument(
123
81
        "--project", required=True, help="Go import path of package to test.")
124
82
    project_group.add_argument(
125
83
        "--project-url", help="URL to git repository of package.")
126
84
    project_group.add_argument(
127
85
        "--project-ref", help="Branch name or tag to use as basis.")
128
 
    project_group.add_argument(
129
 
        "--feature-branch", action="store_true",
130
 
        help="Use special handling for pending feature branches.")
131
86
    merge_group = parser.add_argument_group()
132
87
    merge_group.add_argument(
133
88
        "--merge-url", help="URL to git repository to merge before testing.")
141
96
    dep_group.add_argument(
142
97
        "--go-get-all", action="store_true",
143
98
        help="Go import path of package needed to for build or testing.")
144
 
    dep_group.add_argument(
145
 
        "--tsv-path",
146
 
        help="Path to dependencies.tsv file relative to project dir.")
 
99
    # GZ: Add dependencies.tsv argument option
147
100
    args = parser.parse_args(args)
148
101
    if args.project_url is None and not args.go_get_all:
149
102
        parser.error("Must supply either --project-url or --go-get-all")
150
 
    if args.feature_branch and args.go_get_all:
151
 
        parser.error("Cannot use --feature-branch and --go-get-all together")
152
103
    return args
153
104
 
154
105
 
155
106
def main():
156
107
    args = parse_args()
157
 
    with temp_dir(keep=args.keep) as d:
 
108
    with temp_dir() as d:
158
109
        try:
159
110
            go_test(args, d)
160
111
        except SubcommandError as err: