-
-
Notifications
You must be signed in to change notification settings - Fork 963
#14316 Use local repo commands instead of the github api for Release Drop Down population #14834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 7.0.x
Are you sure you want to change the base?
Conversation
- Rewrote listRepoTags to use Git commands instead of GitHub API - Refactored visitFile to generate output without copying files - Rewrote parseSoftwareVersions to work with new input format & add optional minimum value
- Only assign patch values for integers, prevents tags such as 0.2.RC2 - Fixes error thrown by AddReleaseDropDown.parseSoftwareVersions
- Include single.html and index.html in new corrected paths to add dropdown to
@@ -144,34 +141,34 @@ abstract class AddReleaseDropDown extends DefaultTask { | |||
|
|||
softwareVersions | |||
.forEach { softwareVersion -> | |||
final String versionName = softwareVersion.versionText | |||
final String versionName = softwareVersion?.versionText |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoids a null pointer after moving to git commands, which included a null tag.
@@ -118,7 +116,6 @@ abstract class AddReleaseDropDown extends DefaultTask { | |||
|
|||
filesToChange.remove(absolutePath) | |||
} | |||
Files.copy(file, targetFile, StandardCopyOption.REPLACE_EXISTING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was overwriting the file which just had the drop down added with the original which did not have the dropdown. The delete code above was also removed, since the only files changed were targetFile's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original intent of my changes was to split the guide steps from a single step into many so that the following happens
- generate guide to original (input is the adoc files and output is the original folder)
- update the guide in modified (input is the original folder and output is the modified folder)
- copy modified to end location (input is the modified folder and output is the staging location for the generated docs)
Each of the above steps then has a consistent input/output which means they can be easily cached by Gradle. This also means that whenever the task runs, it should always remove the target directory since it' "owns" those files.
@@ -128,7 +128,7 @@ tasks.register('createReleaseDropdown', AddReleaseDropDown).configure { AddRelea | |||
it.group = 'documentation' | |||
it.dependsOn 'publishGuide' | |||
|
|||
it.inputFiles = project.layout.buildDirectory.files('original-guide/guide/single.html') | |||
it.inputFiles = project.layout.buildDirectory.files('modified-guide/guide/single.html', 'modified-guide/index.html') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grails-core/grails-doc/build.gradle
Line 151 in 3c04692
def inputFiles = [project.layout.buildDirectory.file('manual/guide/single.html').get().asFile, project.layout.buildDirectory.file('manual/index.html').get().asFile] |
This historically added the drop down to both files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution. After reviewing this, it looks like this is a bigger change to ensure we're using task configuration avoidance / lazy properties & cacheing. I've tried to make comments inline, but if you'd like to pair on some of this, I can make time given the scope of the changes required.
@@ -118,7 +116,6 @@ abstract class AddReleaseDropDown extends DefaultTask { | |||
|
|||
filesToChange.remove(absolutePath) | |||
} | |||
Files.copy(file, targetFile, StandardCopyOption.REPLACE_EXISTING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original intent of my changes was to split the guide steps from a single step into many so that the following happens
- generate guide to original (input is the adoc files and output is the original folder)
- update the guide in modified (input is the original folder and output is the modified folder)
- copy modified to end location (input is the modified folder and output is the staging location for the generated docs)
Each of the above steps then has a consistent input/output which means they can be easily cached by Gradle. This also means that whenever the task runs, it should always remove the target directory since it' "owns" those files.
@@ -80,9 +80,10 @@ abstract class AddReleaseDropDown extends DefaultTask { | |||
@TaskAction | |||
void addReleaseDropDown() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's another task in grails-gradle that seems to also be for adding a drop down. Can we move this file there and eliminate the duplication? Especially because we're making it generic now and not specific to the apache grails-core repo.
@@ -80,9 +80,10 @@ abstract class AddReleaseDropDown extends DefaultTask { | |||
@TaskAction | |||
void addReleaseDropDown() { | |||
String projectVersion = version.get() | |||
SoftwareVersion minimumVersion = new SoftwareVersion(major: 5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please change the 5
to a gradle property? To be correctly cacheable, you can't call methods on project
from a task action so you'll have to make it an argument to the task and then in the constructor you will have to use a convention to default it from a property.
@@ -103,9 +104,6 @@ abstract class AddReleaseDropDown extends DefaultTask { | |||
@Override | |||
FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { | |||
Path targetFile = targetOutputDirectory.resolve(guideDirectory.relativize(file)) | |||
if (Files.exists(targetFile)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order for this task to be correctly cacheable, we need to always purge the target location. It sounds like we overlapped the target files and that was a bug. We need to add this back.
@@ -144,34 +141,34 @@ abstract class AddReleaseDropDown extends DefaultTask { | |||
|
|||
softwareVersions | |||
.forEach { softwareVersion -> | |||
final String versionName = softwareVersion.versionText | |||
final String versionName = softwareVersion?.versionText | |||
final String href = GRAILS_DOC_BASE_URL + "/" + versionName + page |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As part of removing the duplicate task, we should make this an argument to the task. Then in our build file where we register this task, we'll just default this as an argument to the task.
if(token) { | ||
connection.setRequestProperty("Authorization", "Bearer ${token}") | ||
} | ||
private List<String> listRepoTags() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The more I think about this, I think we need to split this task into 2 tasks. 1 task to extract the tags and 1 task to update the guide. The main reason for this is we don't want to run the tag list every time. You can make it cache via inputs/outputs. The inputs/outputs for the tags task should be: input = CI build || 1 day cache, output = file with the tag lists for this task to read from. The inputs to this task then are the tag list & the base generated documentation.
} | ||
private List<String> listRepoTags() { | ||
File repoRoot = project.rootProject.projectDir | ||
def command = ["git", "-C", repoRoot.absolutePath, "tag", "-l", "--sort=-creatordate"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In CI, the tags aren't fetched by default. We'll need to change the checkout commands so they're fetched.
File repoRoot = project.rootProject.projectDir | ||
def command = ["git", "-C", repoRoot.absolutePath, "tag", "-l", "--sort=-creatordate"] | ||
|
||
def process = new ProcessBuilder(command) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't be opening processes directly from Gradle. This is another reason to split the tasks - the tag task should be a JavaExec with a doLast{} that saves the output.
@@ -128,7 +128,7 @@ tasks.register('createReleaseDropdown', AddReleaseDropDown).configure { AddRelea | |||
it.group = 'documentation' | |||
it.dependsOn 'publishGuide' | |||
|
|||
it.inputFiles = project.layout.buildDirectory.files('original-guide/guide/single.html') | |||
it.inputFiles = project.layout.buildDirectory.files('modified-guide/guide/single.html', 'modified-guide/index.html') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
Summary
Replaces the GitHub API call with a local Git command to fetch version tags for the Releases drop down. Fixes #14316
Changes
minimumVersion
parameter for parsing the tags to limit the amount shown in the dropdown. This avoids the dropdown having all of these values:Edited
visitFile()
function inside ofFiles.walkFileTree()
to correctly copy the modified text over tomodified-guide/
. It seemed to be overwriting the new changes by copying the original file onto the target, but now the files undermodified-guide/
show correct HTML.Added
modified-guide/index.html
to the list of files for which the dropdown should be generated, which was the behavior prior to a recent change.Edited

SoftwareVersion.groovy
to only initialize apatch
value when the data type matches. This avoids building versions like these:Let me know if there are any concerns!