Search in sources :

Example 1 with IdentifyGitBranchTask

use of org.shipkit.gradle.git.IdentifyGitBranchTask in project shipkit by mockito.

the class GitBranchPlugin method provideBranchTo.

/**
 * Configures some task that needs branch information
 * and an action that is executed when the branch info is available.
 *
 * @param needsBranch some task that needs branch information. Necessary 'dependsOn' will be added.
 * @param branchAction executed when branch info is ready. Hooked up as 'doLast' action.
 */
public void provideBranchTo(Task needsBranch, final Action<String> branchAction) {
    final IdentifyGitBranchTask branchTask = (IdentifyGitBranchTask) needsBranch.getProject().getTasks().getByName(GitBranchPlugin.IDENTIFY_GIT_BRANCH);
    needsBranch.dependsOn(branchTask);
    branchTask.doLast(new Action<Task>() {

        @Override
        public void execute(Task task) {
            branchAction.execute(branchTask.getBranch());
        }
    });
}
Also used : Task(org.gradle.api.Task) IdentifyGitBranchTask(org.shipkit.gradle.git.IdentifyGitBranchTask) IdentifyGitBranchTask(org.shipkit.gradle.git.IdentifyGitBranchTask)

Example 2 with IdentifyGitBranchTask

use of org.shipkit.gradle.git.IdentifyGitBranchTask 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);
        }
    });
}
Also used : IdentifyGitBranchTask(org.shipkit.gradle.git.IdentifyGitBranchTask) ReleaseNeededTask(org.shipkit.gradle.release.ReleaseNeededTask) GitCheckOutTask(org.shipkit.internal.gradle.git.tasks.GitCheckOutTask)

Aggregations

IdentifyGitBranchTask (org.shipkit.gradle.git.IdentifyGitBranchTask)2 Task (org.gradle.api.Task)1 ReleaseNeededTask (org.shipkit.gradle.release.ReleaseNeededTask)1 GitCheckOutTask (org.shipkit.internal.gradle.git.tasks.GitCheckOutTask)1