ajoberstar / gradle-git

Git plugin for Gradle
Apache License 2.0
560 stars 89 forks source link

Don't attempt to fetch from remote when using non final versioning strategy #270

Closed cdancy closed 6 years ago

cdancy commented 6 years ago

Not exactly sure of the best way to word this but I'd like to be able to have not only developers but our CICD process as well call ./gradle release and have the correct path be taken. For developers I'd like the version generated from the local tag as things work now but NO attempting to talk to the remote repository. I ask how to do this as we, as part of our process, add a dependsOn "publishing" task to the release task. This "publishing" task will publish snapshot versions, which is legal for developers to do, but I don't want any remote checking lest we get a Caused by: org.eclipse.jgit.api.errors.TransportException: <git-url>: not authorized exception.

Any ideas? Am I missing something simple? Posted a snippet of our setup below if that helps at all. Thanks in advance!

    release {
        def credentials = new org.ajoberstar.grgit.Credentials(releaseUsername, releasePassword)
        grgit = org.ajoberstar.grgit.Grgit.open(dir: project.rootDir.absolutePath, creds: credentials)
        versionStrategy org.ajoberstar.gradle.git.release.opinion.Strategies.FINAL
        defaultVersionStrategy = org.ajoberstar.gradle.git.release.opinion.Strategies.SNAPSHOT
        tagStrategy {
            generateMessage = { version -> "Version ${->project.version}" }
        }
    }
ajoberstar commented 6 years ago

I think if you want to skip the fetch you could just exclude the prepare task.

./gradlew release -x prepare

or permanently:

build.gradle

prepare.enabled = false
cdancy commented 6 years ago

@ajoberstar that's exactly what I was looking for. Thanks!

cdancy commented 6 years ago

@ajoberstar so while that gets us further, meaning the initial call out to the remote repo in the prepare task is "skipped", we still get a failed build at the end when the release task fails to push remotely (even though we're on a SNAPSHOT) version. Any thoughts/ideas?

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':release'.
> Problem pushing to remote.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':release'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
        at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.ajoberstar.grgit.exception.GrgitException: Problem pushing to remote.
        at org.ajoberstar.grgit.operation.PushOp.call(PushOp.groovy:117)
        at org.ajoberstar.grgit.operation.PushOp.call(PushOp.groovy)
        at java_util_concurrent_Callable$call.call(Unknown Source)
        at java_util_concurrent_Callable$call.call(Unknown Source)
        at org.ajoberstar.grgit.util.OpSyntaxUtil.tryOp(OpSyntaxUtil.groovy:45)
        at org.ajoberstar.grgit.Grgit.methodMissing(Grgit.groovy:188)
        at org.ajoberstar.gradle.git.release.base.BaseReleasePlugin$_addReleaseTask_closure4_closure6.doCall(BaseReleasePlugin.groovy:97)
        at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:718)
        at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:691)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
        ... 29 more
Caused by: org.eclipse.jgit.api.errors.TransportException: https://git.pega.io/scm/pp/gradle-prpc-platform-plugins.git: not authorized
        at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:164)
        at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:80)
        at java_util_concurrent_Callable$call$0.call(Unknown Source)
        at org.ajoberstar.grgit.operation.PushOp.call(PushOp.groovy:114)
        ... 44 more
Caused by: org.eclipse.jgit.errors.TransportException: https://git.pega.io/scm/pp/gradle-prpc-platform-plugins.git: not authorized
        at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:498)
        at org.eclipse.jgit.transport.TransportHttp.openPush(TransportHttp.java:387)
        at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:154)
        at org.eclipse.jgit.transport.Transport.push(Transport.java:1200)
        at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:157)
        ... 47 more
ajoberstar commented 6 years ago

Ah, missed the push in release. It will always try to push the branch you're on if it's not a detached head, even if there's no tag to push. This isn't configurable right now, and given the maintenance status of this project, I'd rather not change it now.

You can probably work around this by not running release and leaving prepare disabled. Neither of them is doing anything you want, given your use case.

Alternatively, my replacement plugin for the release-* plugins (reckon) only interacts with the remote if you explicitly call reckonTagPush. That might work better for your use case.

cdancy commented 6 years ago

Thanks. Yeah I ended up getting around by doing something like "if releaseStage == 'final' apply and configure plugin; else read tag from disk and invoke publish task only". It's not pretty IMO but gets the job done.

I'll check out your reckon plugin when I've got a few cycles to spare.