BreadMoirai / github-release-gradle-plugin

A Gradle Plugin to send Releases to Github
Apache License 2.0
108 stars 26 forks source link

question: is it possible to add a doLast clause to githubRelease ? #29

Closed akasolace closed 4 years ago

akasolace commented 4 years ago

This is not a bug report but just a question and I don't know where to ask it otherwise.

I want to have a message printed after release has been published. However, the block githubRelease is read during configuration, hence my message is printed even if I do not actually run the tasks.

Usually for this I add a doLast block, but I can't do that within the github release block as it is not really a task. Can someone please indicate me how I can achieve this? thank you

BreadMoirai commented 4 years ago

Hi, if the dynamic task configuration does not work, you can access the Task object using any of the following

tasks['githubRelease']
tasks.getByName('githubRelease')
tasks.getByPath('githubRelease')
akasolace commented 4 years ago

@BreadMoirai thank you for your answer, but actually I still have the following issue:

I am trying to have githubRelease executed at the end of my build script. The problem is that releaseAssets = file("$target_dir").listFiles() is executed only during the configuration phase, at that time my directory is empty because the executables have not be produced yet. Hence when githubRelease is finally executed at the end of my script it fails.

Hence, at the moment I am force to run first my build script without githubRelease task and then run githubRelease separately. I was wondering if there was a way of doing what I wanted or if it simply not possible but so far I could not find a way to force the configuration of githubRelease to be kind of re-run ...

BreadMoirai commented 4 years ago

I think the normal use case is to run the task after the build script runs but in the case that you need more flexibility you can work with the task graph. I'm not wholly familiar with the task graph api so some parts of the code might be redundant.

gradle.taskGraph.whenReady { graph ->
    graph.beforeTask { task ->
        if (task.name == "githubRelease") {
            task.releaseAssets = file("$target_dir").listFiles()
        }
    }
}

To my knowledge, the listFiles() call is redundant and may be whats causing issues. you are assigning a list of files to the releaseAssets where the directory itself should be sufficient. releaseAssets = file(target_dir)

akasolace commented 4 years ago

@BreadMoirai ok thank you I will give this a try