Search in sources :

Example 1 with ShipkitExecTask

use of org.shipkit.gradle.exec.ShipkitExecTask in project shipkit by mockito.

the class UpgradeDependencyPlugin method apply.

@Override
public void apply(final Project project) {
    IncubatingWarning.warn("upgrade-dependency plugin");
    final ShipkitConfiguration conf = project.getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration();
    final GitOriginPlugin gitOriginPlugin = project.getRootProject().getPlugins().apply(GitOriginPlugin.class);
    project.getPlugins().apply(GitConfigPlugin.class);
    upgradeDependencyExtension = project.getExtensions().create("upgradeDependency", UpgradeDependencyExtension.class);
    // set defaults
    upgradeDependencyExtension.setBuildFile(project.file("build.gradle"));
    upgradeDependencyExtension.setBaseBranch("master");
    String dependency = (String) project.findProperty(DEPENDENCY_PROJECT_PROPERTY);
    new DependencyNewVersionParser(dependency).fillVersionUpgradeExtension(upgradeDependencyExtension);
    TaskMaker.task(project, CHECKOUT_BASE_BRANCH, GitCheckOutTask.class, new Action<GitCheckOutTask>() {

        @Override
        public void execute(final GitCheckOutTask task) {
            task.setDescription("Checks out the base branch.");
            deferredConfiguration(project, new Runnable() {

                @Override
                public void run() {
                    task.setRev(upgradeDependencyExtension.getBaseBranch());
                }
            });
        }
    });
    TaskMaker.task(project, PULL_UPSTREAM, GitPullTask.class, new Action<GitPullTask>() {

        @Override
        public void execute(final GitPullTask task) {
            task.setDescription("Performs git pull from upstream repository.");
            task.mustRunAfter(CHECKOUT_BASE_BRANCH);
            task.setDryRun(conf.isDryRun());
            deferredConfiguration(project, new Runnable() {

                @Override
                public void run() {
                    task.setRev(upgradeDependencyExtension.getBaseBranch());
                }
            });
            gitOriginPlugin.provideOriginRepo(task, new Action<String>() {

                public void execute(String originRepo) {
                    GitUrlInfo info = new GitUrlInfo(conf);
                    task.setUrl(info.getGitUrl());
                    task.setSecretValue(info.getWriteToken());
                }
            });
        }
    });
    final FindOpenPullRequestTask findOpenPullRequestTask = TaskMaker.task(project, FIND_OPEN_PULL_REQUEST, FindOpenPullRequestTask.class, new Action<FindOpenPullRequestTask>() {

        @Override
        public void execute(final FindOpenPullRequestTask task) {
            task.setDescription("Find an open pull request with version upgrade, if such exists.");
            task.mustRunAfter(PULL_UPSTREAM);
            task.setGitHubApiUrl(conf.getGitHub().getApiUrl());
            task.setAuthToken(conf.getLenient().getGitHub().getReadOnlyAuthToken());
            task.setUpstreamRepositoryName(conf.getGitHub().getRepository());
            task.setVersionBranchRegex(getVersionBranchName(upgradeDependencyExtension.getDependencyName(), ReplaceVersionTask.VERSION_REGEX));
        }
    });
    TaskMaker.task(project, CHECKOUT_VERSION_BRANCH, GitCheckOutTask.class, new Action<GitCheckOutTask>() {

        public void execute(final GitCheckOutTask task) {
            task.setDescription("Creates a new version branch and checks it out.");
            task.mustRunAfter(FIND_OPEN_PULL_REQUEST);
            findOpenPullRequestTask.provideOpenPullRequest(task, new Action<Optional<PullRequest>>() {

                @Override
                public void execute(Optional<PullRequest> pullRequest) {
                    if (pullRequest.isPresent()) {
                        // don't create a new branch if there is already a branch with open pull request with version upgrade
                        task.setNewBranch(false);
                    } else {
                        task.setNewBranch(true);
                    }
                    task.setRev(getCurrentVersionBranchName(upgradeDependencyExtension.getDependencyName(), upgradeDependencyExtension.getNewVersion(), pullRequest));
                }
            });
        }
    });
    final ReplaceVersionTask replaceVersionTask = TaskMaker.task(project, REPLACE_VERSION, ReplaceVersionTask.class, new Action<ReplaceVersionTask>() {

        @Override
        public void execute(final ReplaceVersionTask task) {
            task.setDescription("Replaces dependency version in build file.");
            task.mustRunAfter(CHECKOUT_VERSION_BRANCH);
            deferredConfiguration(project, new Runnable() {

                @Override
                public void run() {
                    task.setDependencyGroup(upgradeDependencyExtension.getDependencyGroup());
                    task.setNewVersion(upgradeDependencyExtension.getNewVersion());
                    task.setDependencyName(upgradeDependencyExtension.getDependencyName());
                    task.setBuildFile(upgradeDependencyExtension.getBuildFile());
                }
            });
        }
    });
    final ShipkitExecTask shipkitExecTask = TaskMaker.task(project, COMMIT_VERSION_UPGRADE, ShipkitExecTask.class, new Action<ShipkitExecTask>() {

        @Override
        public void execute(final ShipkitExecTask exec) {
            exec.setDescription("Commits updated build file.");
            exec.mustRunAfter(REPLACE_VERSION);
            exec.dependsOn(GitConfigPlugin.SET_EMAIL_TASK, GitConfigPlugin.SET_USER_TASK);
            deferredConfiguration(project, new Runnable() {

                @Override
                public void run() {
                    String message = String.format("%s version upgraded to %s", upgradeDependencyExtension.getDependencyName(), upgradeDependencyExtension.getNewVersion());
                    exec.execCommand(execCommand("Committing build file", "git", "commit", "--author", GitUtil.getGitGenericUserNotation(conf.getGit().getUser(), conf.getGit().getEmail()), "-m", message, upgradeDependencyExtension.getBuildFile().getAbsolutePath()));
                }
            });
            exec.onlyIf(wasBuildFileUpdatedSpec(replaceVersionTask));
        }
    });
    final GitPushTask gitPushTask = TaskMaker.task(project, PUSH_VERSION_UPGRADE, GitPushTask.class, new Action<GitPushTask>() {

        @Override
        public void execute(final GitPushTask task) {
            task.setDescription("Pushes updated config file to an update branch.");
            task.mustRunAfter(COMMIT_VERSION_UPGRADE);
            task.setDryRun(conf.isDryRun());
            gitOriginPlugin.provideOriginRepo(task, new Action<String>() {

                public void execute(String originRepo) {
                    GitUrlInfo info = new GitUrlInfo(conf);
                    task.setUrl(info.getGitUrl());
                    task.setSecretValue(info.getWriteToken());
                }
            });
            findOpenPullRequestTask.provideOpenPullRequest(task, new Action<Optional<PullRequest>>() {

                @Override
                public void execute(Optional<PullRequest> pullRequest) {
                    task.getTargets().add(getCurrentVersionBranchName(upgradeDependencyExtension.getDependencyName(), upgradeDependencyExtension.getNewVersion(), pullRequest));
                }
            });
            task.onlyIf(wasBuildFileUpdatedSpec(replaceVersionTask));
        }
    });
    final CreatePullRequestTask createPullRequestTask = TaskMaker.task(project, CREATE_PULL_REQUEST, CreatePullRequestTask.class, new Action<CreatePullRequestTask>() {

        @Override
        public void execute(final CreatePullRequestTask task) {
            task.setDescription("Creates a pull request from branch with version upgraded to master");
            task.mustRunAfter(PUSH_VERSION_UPGRADE);
            task.setGitHubApiUrl(conf.getGitHub().getApiUrl());
            task.setDryRun(conf.isDryRun());
            task.setAuthToken(conf.getLenient().getGitHub().getWriteAuthToken());
            task.setPullRequestTitle(getPullRequestTitle(upgradeDependencyExtension));
            task.setPullRequestDescription(getPullRequestDescription(upgradeDependencyExtension));
            task.setUpstreamRepositoryName(conf.getGitHub().getRepository());
            gitOriginPlugin.provideOriginRepo(task, new Action<String>() {

                @Override
                public void execute(String originRepoName) {
                    task.setForkRepositoryName(originRepoName);
                }
            });
            findOpenPullRequestTask.provideOpenPullRequest(task, new Action<Optional<PullRequest>>() {

                @Override
                public void execute(Optional<PullRequest> pullRequest) {
                    task.setVersionBranch(getCurrentVersionBranchName(upgradeDependencyExtension.getDependencyName(), upgradeDependencyExtension.getNewVersion(), pullRequest));
                }
            });
            deferredConfiguration(project, new Runnable() {

                @Override
                public void run() {
                    task.setBaseBranch(upgradeDependencyExtension.getBaseBranch());
                }
            });
            task.onlyIf(wasOpenPullRequestNotFound(findOpenPullRequestTask));
            task.onlyIf(wasBuildFileUpdatedSpec(replaceVersionTask));
        }
    });
    TaskMaker.task(project, MERGE_PULL_REQUEST, MergePullRequestTask.class, new Action<MergePullRequestTask>() {

        @Override
        public void execute(final MergePullRequestTask task) {
            task.setDescription("Merge pull request when all checks will be passed");
            task.mustRunAfter(CREATE_PULL_REQUEST);
            task.setGitHubApiUrl(conf.getGitHub().getApiUrl());
            task.setDryRun(conf.isDryRun());
            task.setAuthToken(conf.getLenient().getGitHub().getWriteAuthToken());
            task.setBaseBranch(upgradeDependencyExtension.getBaseBranch());
            task.setUpstreamRepositoryName(conf.getGitHub().getRepository());
            gitOriginPlugin.provideOriginRepo(task, new Action<String>() {

                @Override
                public void execute(String originRepoName) {
                    task.setForkRepositoryName(originRepoName);
                }
            });
            createPullRequestTask.provideCreatedPullRequest(task, new Action<PullRequest>() {

                @Override
                public void execute(PullRequest pullRequest) {
                    setPullRequestDataToTask(Optional.ofNullable(pullRequest), task);
                }
            });
            deferredConfiguration(project, new Runnable() {

                @Override
                public void run() {
                    task.setBaseBranch(upgradeDependencyExtension.getBaseBranch());
                }
            });
            task.onlyIf(wasOpenPullRequestNotFound(findOpenPullRequestTask));
            task.onlyIf(wasBuildFileUpdatedSpec(replaceVersionTask));
        }
    });
    TaskMaker.task(project, PERFORM_VERSION_UPGRADE, new Action<Task>() {

        @Override
        public void execute(Task task) {
            task.setDescription("Checkouts new version branch, updates Shipkit dependency in config file, commits and pushes.");
            task.dependsOn(CHECKOUT_BASE_BRANCH);
            task.dependsOn(FIND_OPEN_PULL_REQUEST);
            task.dependsOn(PULL_UPSTREAM);
            task.dependsOn(CHECKOUT_VERSION_BRANCH);
            task.dependsOn(REPLACE_VERSION);
            task.dependsOn(COMMIT_VERSION_UPGRADE);
            task.dependsOn(PUSH_VERSION_UPGRADE);
            task.dependsOn(CREATE_PULL_REQUEST);
            task.dependsOn(MERGE_PULL_REQUEST);
        }
    });
    addLazyDependencyValidation(dependency, createPullRequestTask, gitPushTask, findOpenPullRequestTask, replaceVersionTask, shipkitExecTask);
}
Also used : Action(org.gradle.api.Action) Task(org.gradle.api.Task) GitCheckOutTask(org.shipkit.internal.gradle.git.tasks.GitCheckOutTask) GitPushTask(org.shipkit.gradle.git.GitPushTask) ShipkitExecTask(org.shipkit.gradle.exec.ShipkitExecTask) GitPullTask(org.shipkit.internal.gradle.git.tasks.GitPullTask) ShipkitConfiguration(org.shipkit.gradle.configuration.ShipkitConfiguration) PullRequest(org.shipkit.internal.gradle.git.domain.PullRequest) GitPushTask(org.shipkit.gradle.git.GitPushTask) ShipkitConfigurationPlugin(org.shipkit.internal.gradle.configuration.ShipkitConfigurationPlugin) Optional(java.util.Optional) GitUrlInfo(org.shipkit.internal.gradle.git.GitUrlInfo) ShipkitExecTask(org.shipkit.gradle.exec.ShipkitExecTask) GitOriginPlugin(org.shipkit.internal.gradle.git.GitOriginPlugin) GitPullTask(org.shipkit.internal.gradle.git.tasks.GitPullTask) GitCheckOutTask(org.shipkit.internal.gradle.git.tasks.GitCheckOutTask)

Example 2 with ShipkitExecTask

use of org.shipkit.gradle.exec.ShipkitExecTask in project shipkit by mockito.

the class GitPlugin method apply.

public void apply(final Project project) {
    final ShipkitConfiguration conf = project.getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration();
    TaskMaker.task(project, GIT_COMMIT_TASK, GitCommitTask.class, new Action<GitCommitTask>() {

        public void execute(final GitCommitTask t) {
            t.setDescription("Commits all changed files using generic --author and aggregated commit message");
            t.setGitUserName(conf.getGit().getUser());
            t.setGitUserEmail(conf.getGit().getEmail());
            t.setCommitMessagePostfix(conf.getGit().getCommitMessagePostfix());
        }
    });
    TaskMaker.task(project, GIT_TAG_TASK, ShipkitExecTask.class, new Action<ShipkitExecTask>() {

        public void execute(final ShipkitExecTask t) {
            t.mustRunAfter(GIT_COMMIT_TASK);
            final String tag = GitUtil.getTag(conf, project);
            t.setDescription("Creates new version tag '" + tag + "'");
            t.execCommand(execCommand("Creating tag", "git", "tag", "-a", tag, "-m", GitUtil.getCommitMessage("Created new tag " + tag, conf.getGit().getCommitMessagePostfix())));
        }
    });
    TaskMaker.task(project, GIT_PUSH_TASK, GitPushTask.class, new Action<GitPushTask>() {

        public void execute(final GitPushTask t) {
            t.setDescription("Pushes automatically created commits to remote repo.");
            t.mustRunAfter(GIT_COMMIT_TASK);
            t.mustRunAfter(GIT_TAG_TASK);
            t.dependsOn(GitBranchPlugin.IDENTIFY_GIT_BRANCH);
            t.getTargets().add(GitUtil.getTag(conf, project));
            t.setDryRun(conf.isDryRun());
            GitUrlInfo info = new GitUrlInfo(conf);
            t.setUrl(info.getGitUrl());
            t.setSecretValue(info.getWriteToken());
            project.getPlugins().apply(GitBranchPlugin.class).provideBranchTo(t, new Action<String>() {

                @Override
                public void execute(String branch) {
                    t.getTargets().add(branch);
                }
            });
        }
    });
    final Task performPush = TaskMaker.task(project, PERFORM_GIT_PUSH_TASK, Task.class, new Action<Task>() {

        public void execute(final Task t) {
            t.setDescription("Performs gitCommit, gitTag and gitPush tasks and all tasks dependent on them.");
            t.dependsOn(GIT_COMMIT_TASK, GIT_TAG_TASK, GIT_PUSH_TASK);
        }
    });
    TaskMaker.task(project, PERFORM_GIT_COMMIT_CLEANUP_TASK, Task.class, new Action<Task>() {

        public void execute(final Task t) {
            t.setDescription("Performs " + SOFT_RESET_COMMIT_TASK + " and " + GIT_STASH_TASK + " tasks.");
            t.dependsOn(SOFT_RESET_COMMIT_TASK, GIT_STASH_TASK);
            t.mustRunAfter(performPush);
        }
    });
    TaskMaker.task(project, GIT_STASH_TASK, ShipkitExecTask.class, new Action<ShipkitExecTask>() {

        public void execute(final ShipkitExecTask t) {
            t.setDescription("Stashes current changes");
            t.execCommand(execCommand("Stashing changes", "git", "stash"));
            t.mustRunAfter(SOFT_RESET_COMMIT_TASK);
        }
    });
    TaskMaker.task(project, SOFT_RESET_COMMIT_TASK, ShipkitExecTask.class, new Action<ShipkitExecTask>() {

        public void execute(final ShipkitExecTask t) {
            t.setDescription("Removes last commit, using 'reset --soft HEAD~'");
            t.execCommand(execCommand("Removing last commit", "git", "reset", "--soft", "HEAD~"));
        }
    });
    TaskMaker.task(project, TAG_CLEANUP_TASK, ShipkitExecTask.class, new Action<ShipkitExecTask>() {

        public void execute(final ShipkitExecTask t) {
            t.setDescription("Deletes version tag '" + getTag(conf, project) + "'");
            t.execCommand(execCommand("Deleting version tag", "git", "tag", "-d", getTag(conf, project)));
            t.mustRunAfter(performPush);
        }
    });
}
Also used : Action(org.gradle.api.Action) ShipkitExecTask(org.shipkit.gradle.exec.ShipkitExecTask) IdentifyGitBranchTask(org.shipkit.gradle.git.IdentifyGitBranchTask) GitCommitTask(org.shipkit.gradle.git.GitCommitTask) Task(org.gradle.api.Task) GitPushTask(org.shipkit.gradle.git.GitPushTask) ShipkitConfiguration(org.shipkit.gradle.configuration.ShipkitConfiguration) ShipkitConfigurationPlugin(org.shipkit.internal.gradle.configuration.ShipkitConfigurationPlugin) ShipkitExecTask(org.shipkit.gradle.exec.ShipkitExecTask) GitPushTask(org.shipkit.gradle.git.GitPushTask) GitCommitTask(org.shipkit.gradle.git.GitCommitTask)

Example 3 with ShipkitExecTask

use of org.shipkit.gradle.exec.ShipkitExecTask in project shipkit by mockito.

the class GitConfigPlugin method apply.

@Override
public void apply(Project project) {
    final ShipkitConfiguration conf = project.getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration();
    TaskMaker.task(project, SET_USER_TASK, ShipkitExecTask.class, new Action<ShipkitExecTask>() {

        public void execute(final ShipkitExecTask t) {
            t.setDescription("Overwrites local git 'user.name' with a generic name. Intended for CI.");
            t.execCommand(ExecCommandFactory.execCommand("Setting git user name", "git", "config", "--local", "user.name", conf.getGit().getUser()));
        }
    });
    TaskMaker.task(project, SET_EMAIL_TASK, ShipkitExecTask.class, new Action<ShipkitExecTask>() {

        public void execute(final ShipkitExecTask t) {
            t.setDescription("Overwrites local git 'user.email' with a generic email. Intended for CI.");
            t.execCommand(ExecCommandFactory.execCommand("Setting git user email", "git", "config", "--local", "user.email", conf.getGit().getEmail()));
        }
    });
}
Also used : ShipkitConfiguration(org.shipkit.gradle.configuration.ShipkitConfiguration) ShipkitConfigurationPlugin(org.shipkit.internal.gradle.configuration.ShipkitConfigurationPlugin) ShipkitExecTask(org.shipkit.gradle.exec.ShipkitExecTask)

Example 4 with ShipkitExecTask

use of org.shipkit.gradle.exec.ShipkitExecTask in project shipkit by mockito.

the class CiUpgradeDownstreamPlugin method apply.

@Override
public void apply(Project project) {
    project.getRootProject().getPlugins().apply(CiReleasePlugin.class);
    project.getPlugins().apply(UpgradeDownstreamPlugin.class);
    ShipkitExecTask ciPerformReleaseTask = (ShipkitExecTask) project.getRootProject().getTasks().findByName(CiReleasePlugin.CI_PERFORM_RELEASE_TASK);
    ciPerformReleaseTask.getExecCommands().add(execCommand("Upgrading downstream projects", asList("./gradlew", UpgradeDownstreamPlugin.UPGRADE_DOWNSTREAM_TASK)));
}
Also used : ShipkitExecTask(org.shipkit.gradle.exec.ShipkitExecTask)

Aggregations

ShipkitExecTask (org.shipkit.gradle.exec.ShipkitExecTask)4 ShipkitConfiguration (org.shipkit.gradle.configuration.ShipkitConfiguration)3 ShipkitConfigurationPlugin (org.shipkit.internal.gradle.configuration.ShipkitConfigurationPlugin)3 Action (org.gradle.api.Action)2 Task (org.gradle.api.Task)2 GitPushTask (org.shipkit.gradle.git.GitPushTask)2 Optional (java.util.Optional)1 GitCommitTask (org.shipkit.gradle.git.GitCommitTask)1 IdentifyGitBranchTask (org.shipkit.gradle.git.IdentifyGitBranchTask)1 GitOriginPlugin (org.shipkit.internal.gradle.git.GitOriginPlugin)1 GitUrlInfo (org.shipkit.internal.gradle.git.GitUrlInfo)1 PullRequest (org.shipkit.internal.gradle.git.domain.PullRequest)1 GitCheckOutTask (org.shipkit.internal.gradle.git.tasks.GitCheckOutTask)1 GitPullTask (org.shipkit.internal.gradle.git.tasks.GitPullTask)1