Apache Solr open-source search software
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
logchange {
rootPath = "."
inputDir = "changelog"
outputFile = "CHANGELOG.md"
generateChangesXml = false
}
// Shared comment block placed at the top of generated changelog YAML files
def changelogYamlComments = '''\
# (DELETE ALL COMMENTS UP HERE AFTER FILLING THIS IN
# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
# If the change is minor, don't bother adding a changelog entry.
# For `other` type entries, the threshold to bother with a changelog entry should be even higher.
# title:
# * The audience is end-users and administrators, not committers.
# * Be short and focused on the user impact. Multiple sentences is fine!
# * For technical/geeky details, prefer the commit message instead of changelog.
# * Reference JIRA issues like `SOLR-12345`, or if no JIRA but have a GitHub PR then `PR#12345`.
# type:
# `added` for new features/improvements, opt-in by the user typically documented in the ref guide
# `changed` for improvements; not opt-in
# `fixed` for improvements that are deemed to have fixed buggy behavior
# `deprecated` for marking things deprecated
# `removed` for code removed
# `dependency_update` for updates to dependencies
# `other` for anything else, like large/significant refactorings, build changes,
# test infrastructure, or documentation.
# Most such changes are too small/minor to bother with a changelog entry.'''
// Returns a map with: gitBranch, sanitizedBranchName, configuredName, nick, asfIdUrl
def changelogSetup = {
def gitBranchFull = 'git rev-parse --abbrev-ref HEAD'.execute().text.trim()
if (gitBranchFull == 'main' || gitBranchFull.startsWith('branch_')) {
throw new GradleException("Cannot create changelog on branch '${gitBranchFull}'. This task should only be run on feature branches.")
}
def gitBranch = gitBranchFull.replaceFirst(/^.*\//, "")
def sanitizedBranchName = gitBranch.replaceAll(/[^a-zA-Z0-9._-]/, "-")
def gitUserName = 'git config user.name'.execute().text.trim()
def configuredName = providers.gradleProperty("user.name").getOrElse(gitUserName)
def githubId = providers.gradleProperty("user.githubid").getOrElse(null)
def nick = githubId ? "\n nick: ${githubId}" : ""
def asfId = providers.gradleProperty("user.asfid").getOrElse(null)
def asfIdUrl = asfId ? "\n url: https://home.apache.org/phonebook.html?uid=${asfId}" : ""
return [gitBranch: gitBranch, sanitizedBranchName: sanitizedBranchName,
configuredName: configuredName, nick: nick, asfIdUrl: asfIdUrl]
}
// Writes the changelog YAML file; linksYaml is either "" or a "links:\n - ..." block
def writeChangelogFile = {String fileName, String title, Map ctx, String linksYaml ->
if (title.isEmpty()) {
println "WARNING: Title in generated changelog is empty, please edit"
}
def file = new File(fileName)
file.parentFile.mkdirs()
file.text = """${changelogYamlComments}
title: >
${title}
type:
authors:
- name: ${ctx.configuredName}${ctx.nick}${ctx.asfIdUrl}
${linksYaml}
"""
println "Generated file: ${fileName} -- open and edit before committing"
println "Read dev-docs/changelog.adoc if you don't contribute here often."
}
task writeChangelog {
description = 'Generates a change/log description file (YAML)'
doLast {
def ctx = changelogSetup()
def jiraMatcher = ctx.gitBranch =~ /(?i)SOLR-\d\d\d+/
def jiraRef = jiraMatcher ? jiraMatcher[0].toUpperCase() : "SOLR-XXXX"
def jiraLinks = jiraMatcher ? "links:\n - name: ${jiraRef}\n url: https://issues.apache.org/jira/browse/${jiraRef}" :
""
def title = ctx.gitBranch.replaceFirst(/(?i)SOLR-\d\d\d+\b-?/, "")
.replace("-", " ").capitalize()
writeChangelogFile("changelog/unreleased/${ctx.sanitizedBranchName}.yml", title, ctx, jiraLinks)
}
}
task changelog {
dependsOn writeChangelog
description = 'Generates a change/log description file (YAML)'
}
task newChangelog {
dependsOn writeChangelog
description = 'Generates a change/log description file (YAML)'
}
task writeChangelogPr {
description = 'Generates a changelog entry file (YAML) for the current GitHub PR. ' +
'Pass -Ppr=<number-or-url> if the PR cannot be auto-detected from the current branch.'
doLast {
def ctx = changelogSetup()
def prArg = providers.gradleProperty("pr").getOrNull()
def prCommand = prArg ? ['gh', 'pr', 'view', prArg, '--json', 'number,title'] :
['gh', 'pr', 'view', '--json', 'number,title']
def prInfoProc = prCommand.execute()
prInfoProc.waitFor()
if (prInfoProc.exitValue() != 0) {
def target = prArg ? "PR '${prArg}'" : "a GitHub PR for branch '${ctx.gitBranch}'"
throw new GradleException("Could not find ${target}. Make sure you've pushed this branch and created a PR, or pass -Ppr=<number-or-url>.\n${prInfoProc.err.text.trim()}")
}
def prJson = new groovy.json.JsonSlurper().parseText(prInfoProc.text)
def prNumber = prJson.number
def title = prJson.title ?: ctx.gitBranch.replace("-", " ").capitalize()
def prLinks = "links:\n - name: PR#${prNumber}\n url: https://github.com/apache/solr/pull/${prNumber}"
writeChangelogFile("changelog/unreleased/PR#${prNumber}-${ctx.sanitizedBranchName}.yml",
title,
ctx,
prLinks)
}
}