Skip to content

Commit

Permalink
Include git commit ID in manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
emlun committed Oct 9, 2019
1 parent 192d97c commit db7d6fb
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 1 deletion.
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ task assembleJavadoc(type: Sync) {
destinationDir = file("${rootProject.buildDir}/javadoc")
}

String getGitCommit() {
def proc = "git rev-parse HEAD".execute(null, projectDir)
proc.waitFor()
if (proc.exitValue() != 0) {
throw new RuntimeException("Failed to get git commit ID");
}
return proc.text.trim()
}

subprojects { project ->

sourceCompatibility = 1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ public void standardImplementationPropertiesAreSet() throws IOException {
assertEquals("Yubico", lookup("Implementation-Vendor"));
}

@Test
public void customImplementationPropertiesAreSet() throws IOException {
assertTrue(lookup("Git-Commit").matches("^[a-f0-9]{40}$"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public void standardImplementationPropertiesAreSet() throws IOException {
assertEquals("Yubico", lookup("Implementation-Vendor"));
}

@Test
public void customImplementationPropertiesAreSet() throws IOException {
assertTrue(lookup("Git-Commit").matches("^[a-f0-9]{40}$"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void implementationPropertiesAreSet() {
final Implementation impl = versionInfo.getImplementation();
assertTrue(impl.getSourceCodeUrl().toExternalForm().startsWith("https://"));
assertTrue(impl.getVersion().matches("^\\d+\\.\\d+\\.\\d+(-.*)?"));
assertTrue(impl.getGitCommit().matches("^[a-f0-9]{40}$"));
}

@Test
Expand Down
1 change: 1 addition & 0 deletions webauthn-server-attestation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jar {
'Implementation-Title': project.description,
'Implementation-Version': project.version,
'Implementation-Vendor': 'Yubico',
'Git-Commit': getGitCommit(),
])
}
}
Expand Down
1 change: 1 addition & 0 deletions webauthn-server-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jar {
'Implementation-Version': project.version,
'Implementation-Vendor': 'Yubico',
'Implementation-Source-Url': 'https://github.com/Yubico/java-webauthn-server',
'Git-Commit': getGitCommit(),
])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@ public class Implementation {
@NonNull
private final URL sourceCodeUrl;

/**
* The commit ID of the source code the library was built from, if known.
*/
@NonNull
private final String gitCommit;

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public static VersionInfo getInstance() {
*/
private final Implementation implementation = new Implementation(
findValueInManifest("Implementation-Version"),
new URL(findValueInManifest("Implementation-Source-Url"))
new URL(findValueInManifest("Implementation-Source-Url")),
findValueInManifest("Git-Commit")
);

private VersionInfo() throws IOException {
Expand Down

0 comments on commit db7d6fb

Please sign in to comment.