use of org.shipkit.internal.gradle.git.tasks.GitCheckOutTask 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);
}
use of org.shipkit.internal.gradle.git.tasks.GitCheckOutTask in project shipkit by mockito.
the class TravisPlugin method apply.
@Override
public void apply(final Project project) {
project.getPlugins().apply(CiReleasePlugin.class);
final String branch = System.getenv("TRAVIS_BRANCH");
LOG.info("Branch from 'TRAVIS_BRANCH' env variable: {}", branch);
// configure branch based on Travis' env variable
IdentifyGitBranchTask identifyBranch = (IdentifyGitBranchTask) project.getTasks().getByName(GitBranchPlugin.IDENTIFY_GIT_BRANCH);
if (!StringUtil.isEmpty(branch)) {
identifyBranch.setBranch(branch);
}
// set the branch to be checked out on ci build
final GitCheckOutTask checkout = (GitCheckOutTask) project.getTasks().getByName(GitSetupPlugin.CHECKOUT_TASK);
checkout.setRev(branch);
LazyConfiguration.lazyConfiguration(checkout, new Runnable() {
public void run() {
BasicValidator.notNull(checkout.getRev(), "Task " + checkout.getPath() + " does not know the target revision to check out.\n" + "In Travis CI builds, it is automatically configured from 'TRAVIS_BRANCH' environment variable.\n" + "If you are trying to run this task outside Travis, you can export the environment variable.\n" + "Alternatively, you can set the task's 'rev' property explicitly.");
}
});
// update release needed task based on Travis' env variables
String pr = System.getenv("TRAVIS_PULL_REQUEST");
LOG.info("Pull request from 'TRAVIS_PULL_REQUEST' env variable: {}", pr);
final boolean isPullRequest = pr != null && !pr.trim().isEmpty() && !pr.equals("false");
LOG.info("Pull request build: {}", isPullRequest);
project.getTasks().withType(ReleaseNeededTask.class, new Action<ReleaseNeededTask>() {
public void execute(ReleaseNeededTask t) {
t.setCommitMessage(System.getenv("TRAVIS_COMMIT_MESSAGE"));
t.setPullRequest(isPullRequest);
}
});
}
Aggregations