-
Notifications
You must be signed in to change notification settings - Fork 33
Simplify Gradle build logic for making releases. #700
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
name: Publish package to GitHub Packages | ||
on: | ||
push: | ||
branches: | ||
tags: | ||
- '*-rc*' | ||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-tags: true | ||
- uses: actions/setup-java@v1 | ||
with: | ||
java-version: 11 | ||
- name: Publish package | ||
run: ./gradlew publishAllPublicationsToGitHubPackagesRepository | ||
run: ./gradlew publishAllPublicationsToGitHubPackagesRepository -PpublishVersion="$REFNAME" | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
REFNAME: ${{ github.ref_name }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ subprojects { | |
} | ||
|
||
ext.scmInfo = getScmInfo() | ||
logger.lifecycle("Making ${scmInfo.type()} build: ${scmInfo.version}") | ||
|
||
allprojects { | ||
group = 'org.metafacture' | ||
|
@@ -270,7 +271,7 @@ subprojects { | |
password = System.getenv("GITHUB_TOKEN") | ||
} | ||
} | ||
if (scmInfo.isRelease() && project.hasProperty('releaseRepositoryUrl')) { | ||
if (scmInfo.isRelease && project.hasProperty('releaseRepositoryUrl')) { | ||
maven { | ||
url = releaseRepositoryUrl | ||
credentials { | ||
|
@@ -284,7 +285,7 @@ subprojects { | |
|
||
signing { | ||
required { | ||
scmInfo.isRelease() | ||
scmInfo.isRelease | ||
} | ||
sign publishing.publications.mavenArtifacts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the The Signing Plugin, no? It needs the gpg properties as explained here : https://docs.gradle.org/current/userguide/signing_plugin.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is, and it does. @TobiasNx: Is there anything that needs to be changed in the context of this pull request or can we merge? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With regard to code I dont know. With regard to the build process of RC I think both of my questions are still unanswered: #700 (comment) With regard to the documentation of the Signing Plugin we could open another ticket where we could improve it. |
||
} | ||
|
@@ -310,114 +311,60 @@ nexusPublishing { | |
class ScmInfo { | ||
def version | ||
def tag | ||
def isRelease | ||
|
||
ScmInfo(version, tag, isRelease) { | ||
if (!isRelease) version += '-SNAPSHOT' | ||
|
||
ScmInfo(version, tag) { | ||
this.version = version | ||
this.tag = tag | ||
this.isRelease = isRelease | ||
} | ||
|
||
def isRelease() { | ||
return tag != null | ||
def type() { | ||
return isRelease ? 'release' : tag != null ? 'release candidate' : 'snapshot' | ||
} | ||
} | ||
|
||
def getScmInfo() { | ||
def tag = getGitTag() | ||
if (tag != null) { | ||
logger.lifecycle('SCM tag found. Making a release build') | ||
version = extractVersionFromTag(tag) | ||
} else { | ||
logger.lifecycle('No SCM tag found. Making a snapshot build') | ||
version = getSnapshotVersion() | ||
} | ||
logger.lifecycle("Version is $version") | ||
return new ScmInfo(version, tag) | ||
} | ||
def version = null | ||
def tag = null | ||
def isRelease = false | ||
|
||
def getSnapshotVersion() { | ||
if (grgit == null) { | ||
logger.warn('No Git repository found') | ||
return 'non-scm-build-SNAPSHOT' | ||
} | ||
if (grgit.branch.current().fullName == 'HEAD') { | ||
logger.lifecycle('Detached HEAD found') | ||
return "commit-${grgit.head().id}-SNAPSHOT" | ||
} | ||
if (grgit.branch.current().name == 'master') { | ||
logger.lifecycle('On master branch') | ||
return 'master-SNAPSHOT' | ||
} | ||
if (grgit.branch.current().name.startsWith('releases/')) { | ||
logger.lifecycle('Release branch found') | ||
return "${extractVersionFromBranch(grgit.branch.current().name)}-SNAPSHOT" | ||
if (project.hasProperty('publishVersion')) { | ||
version = publishVersion | ||
|
||
def matcher = version =~ /\d+(?:\.\d+)+(-rc\d+)?/ | ||
if (matcher.matches()) { | ||
tag = getGitTag(version) | ||
isRelease = matcher.group(1) == null | ||
} | ||
} | ||
if (grgit.branch.current().name.contains('-rc')) { | ||
logger.lifecycle('Release candidate branch found') | ||
return "${grgit.branch.current().name}-SNAPSHOT" | ||
else { | ||
version = grgit != null ? grgit.branch.current().name : rootProject.name | ||
} | ||
logger.lifecycle('Feature branch found') | ||
return "feature-${grgit.branch.current().name}-SNAPSHOT" | ||
|
||
return new ScmInfo(version, tag, isRelease) | ||
} | ||
|
||
def getGitTag() { | ||
def getGitTag(version) { | ||
if (grgit == null) { | ||
logger.warn('No Git repository found') | ||
return null | ||
throw new GradleException('No Git repository found') | ||
} | ||
if (!grgit.status().isClean()) { | ||
logger.warn('Working copy has modifications. Will not look for tags') | ||
return null | ||
} | ||
def tags = getAnnotatedTags() | ||
if (tags.isEmpty()) { | ||
logger.lifecycle('HEAD has no annotated tags') | ||
return null | ||
} | ||
if (tags.size() > 1) { | ||
logger.warn("HEAD has ${tags.size()} annotated tags") | ||
return null | ||
throw new GradleException('Working copy has modifications') | ||
} | ||
def tag = tags[0] | ||
logger.lifecycle("Found annotated tag $tag.name") | ||
return tag.name | ||
} | ||
|
||
def getAnnotatedTags() { | ||
def tags = [] | ||
def tagName = "${rootProject.name}-$version" | ||
for (tag in grgit.tag.list()) { | ||
if (tag.commit == grgit.head() | ||
&& tag.tagger != null | ||
&& tag.dateTime != null) { | ||
tags.add tag | ||
if ( | ||
tag.name == tagName && // matching name | ||
tag.commit == grgit.head() && // pointing at HEAD | ||
tag.tagger != null && tag.dateTime != null // annotated | ||
) { | ||
return tagName | ||
} | ||
} | ||
return tags | ||
} | ||
|
||
def static extractVersionFromTag(tag) { | ||
Matcher matcher = | ||
tag =~ /metafacture-core-(\d+\.\d+\.\d+(-[-A-Za-z0-9]+)?)/ | ||
if (!matcher.matches()) { | ||
throw new GradleException("""\ | ||
Unsupported tag format: $tag | ||
Could not extract version from tag. Supported tag formats are | ||
metafacture-core-X.Y.Z and | ||
metafacture-core-X.Y.Z-QUALIFIER | ||
""".stripIndent()) | ||
} | ||
return matcher.group(1) | ||
} | ||
|
||
def static extractVersionFromBranch(branch) { | ||
Matcher matcher = | ||
branch =~ /releases\/metafacture-core-(\d+\.\d+\.\d+(-[-A-Za-z0-9]+)?)/ | ||
if (!matcher.matches()) { | ||
throw new GradleException("""\ | ||
Unsupported branch format: $branch | ||
Could not extract version from branch. Supported branch formats are | ||
releases/metafacture-core-X.Y.Z and | ||
releases/metafacture-core-X.Y.Z-QUALIFIER | ||
""".stripIndent()) | ||
} | ||
return matcher.group(1) | ||
throw new GradleException("HEAD has no matching annotated tag: $tagName") | ||
} |
Uh oh!
There was an error while loading. Please reload this page.