Search in sources :

Example 1 with ReleaseNeededTask

use of org.shipkit.gradle.release.ReleaseNeededTask 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)1 ReleaseNeededTask (org.shipkit.gradle.release.ReleaseNeededTask)1 GitCheckOutTask (org.shipkit.internal.gradle.git.tasks.GitCheckOutTask)1