Skip to content

Commit

Permalink
Automate release artifact checks:
Browse files Browse the repository at this point in the history
- POM correct?
- Manifest correct?
- Thirdparty repackaged?
- Sources uploaded?
- Javadoc uploaded?

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
  • Loading branch information
codecholeric committed Jul 30, 2019
1 parent 56e6770 commit 41a7b65
Show file tree
Hide file tree
Showing 8 changed files with 348 additions and 1 deletion.
3 changes: 2 additions & 1 deletion build-steps/build-steps.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ def utilsPath = { "build-steps/${it}" }

apply from: utilsPath('archiving/archiving.gradle')
apply from: utilsPath('codequality/spotbugs.gradle')
apply from: utilsPath('publish/publish.gradle')
apply from: utilsPath('release/publish.gradle')
apply from: utilsPath('license/license.gradle')
apply from: utilsPath('maven-integration-test/maven-integration-test.gradle')
apply from: utilsPath('build-scan/build-scan.gradle')
apply from: utilsPath('ci/ci-config.gradle')
apply from: utilsPath('release/check-uploaded-artifacts.gradle')
apply from: utilsPath('release/release.gradle')
111 changes: 111 additions & 0 deletions build-steps/release/check-uploaded-artifacts.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import java.nio.file.Files
import java.time.LocalDateTime
import java.util.jar.JarFile
import java.util.jar.Manifest

File scriptRoot = currentScriptRootOf this
def rootUrl = {
if (!project.hasProperty('tngRepoId')) {
throw new IllegalArgumentException(
'You must pass the repo id (see Sonatype Repository Manager -> comtngtech-${repoId}) as parameter, e.g. -P tngRepoId=1162')
}
"https://oss.sonatype.org/service/local/repositories/comtngtech-${tngRepoId}/content/com/tngtech/archunit"
}

def createArtifactUrl = { String artifactId ->
"${rootUrl()}/${artifactId}/${version}/${artifactId}-${version}"
}

def getUploadedFile = { String artifactId, String ending, String suffix ->
def fullEnding = (!suffix.isEmpty() ? "-${suffix}" : '') + ".${ending}"
File result = Files.createTempFile(artifactId, fullEnding).toFile()
result.bytes = new URL("${createArtifactUrl(artifactId)}${fullEnding}").bytes
result
}

def getUploadedFileText = { String artifactId, String ending ->
new URL("${createArtifactUrl(artifactId)}.${ending}").text.stripIndent()
}

def getExpectedFile = { String artifactId, String ending ->
new File(scriptRoot, "expected/${artifactId}.${ending}").text.replace('${archunit.version}', version).stripIndent()
}

def checkPom = { String artifactId ->
println "Verifying correct POM of ${artifactId}"

String actual = getUploadedFileText(artifactId, 'pom')
String expected = getExpectedFile(artifactId, 'pom')
if (actual.replaceAll("\\s", "") != expected.replaceAll("\\s", "")) {
throw new AssertionError("""POM of artifact '${artifactId}' does not match:
--------
Actual:
${actual}
--------
Expected:
${expected}
--------
""")
}
}

def checkManifest = { String artifactId, Manifest manifest ->
println "Verifying correct Manifest of ${artifactId}"

def checkAttributes = { expected ->
expected.each { key, value ->
assert manifest.mainAttributes.getValue(key) == value
}
}
checkAttributes([
'Specification-Title' : "ArchUnit - Module '${artifactId}'",
'Specification-Version' : version,
'Specification-Vendor' : 'TNG Technology Consulting GmbH',
'Implementation-Title' : "com.tngtech.${artifactId.replace('-', '.')}",
'Implementation-Version': version,
'Implementation-Vendor' : 'TNG Technology Consulting GmbH',
'Issue-Tracker' : 'https://github.com/TNG/ArchUnit/issues',
'Documentation-URL' : 'https://github.com/TNG/ArchUnit',
'Copyright' : "${LocalDateTime.now().year} TNG Technology Consulting GmbH",
'License' : 'The Apache Software License, Version 2.0',
'Automatic-Module-Name' : "com.tngtech.${artifactId.replaceFirst('-', '.').replaceFirst('-', '.').replace('-', '')}"
])
}

def checkThirdParty = { JarFile jarFile ->
assert jarFile.getEntry('com/tngtech/archunit/thirdparty/org/objectweb/asm/ClassVisitor.class') != null: 'ASM is missing from 3rd party'
assert jarFile.getEntry('com/tngtech/archunit/thirdparty/org/objectweb/asm/asm.license') != null: 'ASM license is missing from 3rd party'
assert jarFile.getEntry('com/tngtech/archunit/thirdparty/com/google/common/collect/ImmutableSet.class') != null: 'Guava is missing from 3rd party'
}

def checkNoThirdParty = { JarFile jarFile ->
assert jarFile.getEntry('com/tngtech/archunit/thirdparty') == null: 'There exists a third party folder'
}

def checkSourcesExist = { String artifactId ->
assert getUploadedFile(artifactId, 'jar', 'sources') != null
}

def checkJavadocExists = { String artifactId ->
assert getUploadedFile(artifactId, 'jar', 'javadoc') != null
}

task checkUploadedArtifacts {
doLast {
releaseProjects.each { Project project ->
checkPom(project.name)
checkSourcesExist(project.name)
checkJavadocExists(project.name)

JarFile jarFile = new JarFile(getUploadedFile(project.name, 'jar', ''))
checkManifest(project.name, jarFile.manifest)
if (project.repackagesAsm) {
println "Artifact ${project.name} is configured to repackage 3rd party libs -> checking existence of 3rd party package..."
checkThirdParty(jarFile)
} else {
println "Artifact ${project.name} is configured to not repackage 3rd party libs -> checking absense of 3rd party package..."
checkNoThirdParty(jarFile)
}
}
}
}
48 changes: 48 additions & 0 deletions build-steps/release/expected/archunit-junit4.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit4</artifactId>
<version>${archunit.version}</version>
<name>ArchUnit</name>
<description>A Java architecture test library, to specify and assert architecture rules in plain Java - Module 'archunit-junit4'</description>
<url>https://github.com/TNG/ArchUnit</url>
<organization>
<name>TNG Technology Consulting GmbH</name>
<url>https://www.tngtech.com/</url>
</organization>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>codecholeric</id>
<name>Peter Gafert</name>
<email>peter.gafert@tngtech.com</email>
</developer>
</developers>
<scm>
<connection>scm:git@github.com:TNG/ArchUnit.git</connection>
<developerConnection>scm:git@github.com:TNG/ArchUnit.git</developerConnection>
<url>https://github.com/TNG/ArchUnit</url>
</scm>
<dependencies>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit</artifactId>
<version>${archunit.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
42 changes: 42 additions & 0 deletions build-steps/release/expected/archunit-junit5-api.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5-api</artifactId>
<version>${archunit.version}</version>
<name>ArchUnit</name>
<description>A Java architecture test library, to specify and assert architecture rules in plain Java - Module 'archunit-junit5-api'</description>
<url>https://github.com/TNG/ArchUnit</url>
<organization>
<name>TNG Technology Consulting GmbH</name>
<url>https://www.tngtech.com/</url>
</organization>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>codecholeric</id>
<name>Peter Gafert</name>
<email>peter.gafert@tngtech.com</email>
</developer>
</developers>
<scm>
<connection>scm:git@github.com:TNG/ArchUnit.git</connection>
<developerConnection>scm:git@github.com:TNG/ArchUnit.git</developerConnection>
<url>https://github.com/TNG/ArchUnit</url>
</scm>
<dependencies>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit</artifactId>
<version>${archunit.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
43 changes: 43 additions & 0 deletions build-steps/release/expected/archunit-junit5-engine-api.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5-engine-api</artifactId>
<version>${archunit.version}</version>
<name>ArchUnit</name>
<description>A Java architecture test library, to specify and assert architecture rules in plain Java - Module 'archunit-junit5-engine-api'
</description>
<url>https://github.com/TNG/ArchUnit</url>
<organization>
<name>TNG Technology Consulting GmbH</name>
<url>https://www.tngtech.com/</url>
</organization>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>codecholeric</id>
<name>Peter Gafert</name>
<email>peter.gafert@tngtech.com</email>
</developer>
</developers>
<scm>
<connection>scm:git@github.com:TNG/ArchUnit.git</connection>
<developerConnection>scm:git@github.com:TNG/ArchUnit.git</developerConnection>
<url>https://github.com/TNG/ArchUnit</url>
</scm>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<version>1.5.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
55 changes: 55 additions & 0 deletions build-steps/release/expected/archunit-junit5-engine.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5-engine</artifactId>
<version>${archunit.version}</version>
<name>ArchUnit</name>
<description>A Java architecture test library, to specify and assert architecture rules in plain Java - Module 'archunit-junit5-engine'
</description>
<url>https://github.com/TNG/ArchUnit</url>
<organization>
<name>TNG Technology Consulting GmbH</name>
<url>https://www.tngtech.com/</url>
</organization>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>codecholeric</id>
<name>Peter Gafert</name>
<email>peter.gafert@tngtech.com</email>
</developer>
</developers>
<scm>
<connection>scm:git@github.com:TNG/ArchUnit.git</connection>
<developerConnection>scm:git@github.com:TNG/ArchUnit.git</developerConnection>
<url>https://github.com/TNG/ArchUnit</url>
</scm>
<dependencies>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit</artifactId>
<version>${archunit.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5-api</artifactId>
<version>${archunit.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5-engine-api</artifactId>
<version>${archunit.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
47 changes: 47 additions & 0 deletions build-steps/release/expected/archunit.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit</artifactId>
<version>${archunit.version}</version>
<name>ArchUnit</name>
<description>A Java architecture test library, to specify and assert architecture rules in plain Java - Module 'archunit'</description>
<url>https://github.com/TNG/ArchUnit</url>
<organization>
<name>TNG Technology Consulting GmbH</name>
<url>https://www.tngtech.com/</url>
</organization>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
<license>
<name>BSD</name>
<url>http://asm.ow2.io/license.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>codecholeric</id>
<name>Peter Gafert</name>
<email>peter.gafert@tngtech.com</email>
</developer>
</developers>
<scm>
<connection>scm:git@github.com:TNG/ArchUnit.git</connection>
<developerConnection>scm:git@github.com:TNG/ArchUnit.git</developerConnection>
<url>https://github.com/TNG/ArchUnit</url>
</scm>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
File renamed without changes.

0 comments on commit 41a7b65

Please sign in to comment.