Skip to content

Instantly share code, notes, and snippets.

@InsanusMokrassar
Last active October 16, 2020 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InsanusMokrassar/52fe87ab2fb218d886b8b1e6964bcdf2 to your computer and use it in GitHub Desktop.
Save InsanusMokrassar/52fe87ab2fb218d886b8b1e6964bcdf2 to your computer and use it in GitHub Desktop.
Changelog parser and gradle github release script
#!/bin/bash
function parse() {
version="$1"
while IFS= read -r line && [ -z "`echo "$line" | grep -e "^#\+ $version"`" ]
do
: # do nothing
done
while IFS= read -r line && [ -z "`echo "$line" | grep -e "^#\+"`" ]
do
echo "$line"
done
}
version="$1"
file="$2"
if [ -n "$file" ]; then
parse "$version" < "$file"
else
parse "$version"
fi
private String getCurrentVersionChangelog() {
OutputStream changelogDataOS = new ByteArrayOutputStream()
exec {
commandLine 'chmod', "+x", './changelog_parser.sh'
}
exec {
standardOutput = changelogDataOS
commandLine './changelog_parser.sh', "${project.version}", 'CHANGELOG.md'
}
return changelogDataOS.toString().trim()
}
if (new File(projectDir, "secret.gradle").exists()) {
apply from: './secret.gradle'
apply plugin: "com.github.breadmoirai.github-release"
githubRelease {
token "${project.property('GITHUB_RELEASE_TOKEN')}"
owner "HERE MUST BE PROJECT OWNER NAME"
repo "${rootProject.name}"
tagName "${project.version}"
releaseName "${project.version}"
targetCommitish "${project.version}"
body getCurrentVersionChangelog()
}
}
@InsanusMokrassar
Copy link
Author

Please, remember that you must add following lines to your main build gradle:

buildscript {
    ...
    dependencies {
        ...
        classpath "com.github.breadmoirai:github-release:2.2.12"
        ...
    }
}

apply from: 'github_release.gradle'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment