test(packer): qualify asset contracts and improve Jenkins reporting
This commit is contained in:
Vendored
+75
-51
@@ -1,68 +1,92 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
tools {
|
||||
gradle 'gradle-9.3.1'
|
||||
}
|
||||
|
||||
environment {
|
||||
GRADLE_USER_HOME = '/var/jenkins_home/.gradle'
|
||||
GRADLE_OPTS = '-Dorg.gradle.parallel=true -Dorg.gradle.caching=true'
|
||||
JAVA_TOOL_OPTIONS = '-Djava.awt.headless=true'
|
||||
JAVA_OPTS = '-Xmx2g'
|
||||
TESTS_STARTED = 'false'
|
||||
VERIFICATION_SUCCEEDED = 'false'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Build') {
|
||||
stage('Clean') {
|
||||
steps {
|
||||
// A separate successful clean prevents publishing a previous build's reports.
|
||||
withGradle {
|
||||
sh './gradlew clean --no-daemon --console=plain'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Tests and coverage') {
|
||||
steps {
|
||||
script { env.TESTS_STARTED = 'true' }
|
||||
withChecks(name: 'Test', includeStage: true) {
|
||||
withGradle {
|
||||
sh """
|
||||
gradle \
|
||||
clean \
|
||||
test \
|
||||
jacocoTestReport \
|
||||
--parallel \
|
||||
--max-workers=2 \
|
||||
--build-cache \
|
||||
--no-daemon
|
||||
"""
|
||||
// --continue finishes independent tests/reports but retains a nonzero exit on failure.
|
||||
sh './gradlew test jacocoTestReport --continue --parallel --max-workers=2 --build-cache --no-daemon --console=plain'
|
||||
}
|
||||
junit testResults: '**/build/test-results/test/TEST-*.xml'
|
||||
}
|
||||
withChecks(name: 'JaCoCo Coverage', includeStage: false) {
|
||||
recordCoverage(tools: [[parser: 'JACOCO', pattern: "build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml"]],
|
||||
id: 'jacoco',
|
||||
name: 'JaCoCo Coverage',
|
||||
checksName: 'JaCoCo Coverage',
|
||||
sourceDirectories: [[path: 'glob:**/src/main/java']],
|
||||
sourceCodeEncoding: 'UTF-8',
|
||||
sourceCodeRetention: 'EVERY_BUILD',
|
||||
qualityGates: [
|
||||
[threshold: 50.0, metric: 'CLASS', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||
[threshold: 50.0, metric: 'METHOD', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||
[threshold: 50.0, metric: 'LINE', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||
[threshold: 50.0, metric: 'INSTRUCTION', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||
[threshold: 40.0, metric: 'BRANCH', baseline: 'PROJECT', criticality: 'UNSTABLE']])
|
||||
}
|
||||
script { env.VERIFICATION_SUCCEEDED = 'true' }
|
||||
}
|
||||
} // Test
|
||||
|
||||
stage('Reports') {
|
||||
steps {
|
||||
script {
|
||||
// archiveArtifacts artifacts: '**/coverage-sources.zip', allowEmptyArchive: false, fingerprint: false, onlyIfSuccessful: false
|
||||
publishHTML (target: [
|
||||
allowMissing: true,
|
||||
alwaysLinkToLastBuild: false,
|
||||
keepAll: true,
|
||||
reportDir: "build/reports/jacoco/jacocoTestReport/html",
|
||||
reportFiles: 'index.html',
|
||||
reportName: 'Coverage Report'
|
||||
])
|
||||
// def pmd = scanForIssues tool: [$class: 'Pmd'], pattern: 'lib/build/reports/pmd/*.xml'
|
||||
// publishIssues issues: [pmd]
|
||||
}
|
||||
}
|
||||
} // Reports
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
script {
|
||||
if (env.TESTS_STARTED == 'true') {
|
||||
// Isolate publishers so a failed publisher does not suppress the other diagnostics.
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
junit testResults: '**/build/test-results/test/TEST-*.xml',
|
||||
allowEmptyResults: env.VERIFICATION_SUCCEEDED != 'true'
|
||||
if (env.VERIFICATION_SUCCEEDED == 'true' && !fileExists('prometeu-packer/prometeu-packer-v1/build/test-results/test/TEST-p.packer.services.PackerAssetContractTest.xml')) {
|
||||
error 'Successful verification is missing the packer contract test report.'
|
||||
}
|
||||
}
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
if (fileExists('build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml')) {
|
||||
withChecks(name: 'JaCoCo Coverage', includeStage: false) {
|
||||
recordCoverage(tools: [[parser: 'JACOCO', pattern: 'build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml']],
|
||||
id: 'jacoco',
|
||||
name: 'JaCoCo Coverage',
|
||||
checksName: 'JaCoCo Coverage',
|
||||
sourceDirectories: [[path: 'glob:**/src/main/java']],
|
||||
sourceCodeEncoding: 'UTF-8',
|
||||
sourceCodeRetention: 'EVERY_BUILD',
|
||||
qualityGates: [
|
||||
[threshold: 50.0, metric: 'CLASS', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||
[threshold: 50.0, metric: 'METHOD', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||
[threshold: 50.0, metric: 'LINE', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||
[threshold: 50.0, metric: 'INSTRUCTION', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||
[threshold: 40.0, metric: 'BRANCH', baseline: 'PROJECT', criticality: 'UNSTABLE']])
|
||||
}
|
||||
} else if (env.VERIFICATION_SUCCEEDED == 'true') {
|
||||
error 'Successful verification is missing the consolidated JaCoCo XML report.'
|
||||
} else {
|
||||
echo 'Verification failed before consolidated coverage was available; preserving available test reports.'
|
||||
}
|
||||
}
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
publishHTML(target: [
|
||||
allowMissing: env.VERIFICATION_SUCCEEDED != 'true',
|
||||
alwaysLinkToLastBuild: false,
|
||||
keepAll: true,
|
||||
reportDir: 'build/reports/jacoco/jacocoTestReport/html',
|
||||
reportFiles: 'index.html',
|
||||
reportName: 'Coverage Report'
|
||||
])
|
||||
}
|
||||
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
||||
archiveArtifacts artifacts: '**/build/test-results/test/**, **/build/reports/tests/test/**, **/build/reports/jacoco/**',
|
||||
allowEmptyArchive: env.VERIFICATION_SUCCEEDED != 'true',
|
||||
onlyIfSuccessful: false
|
||||
}
|
||||
} else {
|
||||
echo 'Preparation did not complete; no current test run to publish. See the build console for diagnostics.'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
# Studio Jenkins verification
|
||||
|
||||
`Jenkinsfile` uses the checked-in Gradle wrapper (currently 9.3.1). A compatible
|
||||
Java installation must be available to launch Gradle; project conventions select
|
||||
Java 21 for compilation/tests. The pipeline retains its existing Gradle cache
|
||||
location, worker limit and installed Jenkins report plugins. It does not require
|
||||
a named Jenkins Gradle installation.
|
||||
|
||||
The build runs on a Unix agent with Java and dependency/cache access. It sets
|
||||
`JAVA_TOOL_OPTIONS=-Djava.awt.headless=true` for Gradle and test JVMs. No display,
|
||||
runtime binary, sibling runtime checkout, runtime download/build, or new Jenkins
|
||||
plugin is required by the packer contract suite.
|
||||
|
||||
## Commands
|
||||
|
||||
```sh
|
||||
export JAVA_TOOL_OPTIONS=-Djava.awt.headless=true
|
||||
./gradlew clean --no-daemon --console=plain
|
||||
./gradlew test jacocoTestReport --continue --parallel --max-workers=2 --build-cache --no-daemon --console=plain
|
||||
```
|
||||
|
||||
Clean is a separate stage: when it fails, old reports must not be published as a
|
||||
new test run. Gradle `--continue` lets independent tasks and reports finish after
|
||||
a test failure; it does not turn a failing command into success. Runtime/desktop
|
||||
opt-in test tasks are not invoked. The ordinary packer `test` task includes
|
||||
`PackerAssetContractTest` without skips or a runtime fallback.
|
||||
|
||||
## Failure reporting
|
||||
|
||||
The unconditional post block publishes available JUnit, consolidated JaCoCo XML,
|
||||
HTML and archived test/coverage reports after a failed verification command.
|
||||
Each publisher is isolated so one publisher error does not prevent the others
|
||||
from being attempted. The build console retains compilation/setup diagnostics.
|
||||
|
||||
An otherwise successful verification must produce JUnit results, the packer
|
||||
contract suite report, consolidated JaCoCo XML and HTML. Missing successful-build
|
||||
evidence fails publication. A failed compilation may have no reports: the
|
||||
original build failure remains authoritative and available diagnostics are still
|
||||
preserved. A failed clean does not publish potentially stale artifacts.
|
||||
|
||||
Coverage thresholds are unchanged: CLASS/METHOD/LINE/INSTRUCTION 50%, BRANCH
|
||||
40%, PROJECT baseline and UNSTABLE criticality. Reports from partially failed
|
||||
test runs are useful diagnostics, not a passing quality gate.
|
||||
|
||||
## Contract and manual verification boundary
|
||||
|
||||
See the packer fixture [provenance and coverage](../../prometeu-packer/prometeu-packer-v1/src/test/resources/fixtures/contracts/README.md).
|
||||
The automated suite checks producer bytes and metadata against independent
|
||||
expectations. Runtime gameplay remains manual with existing games, not a local
|
||||
or CI automated test. Record manual outcomes only after execution.
|
||||
|
||||
Local Gradle checks and Groovy parsing cannot certify controller plugin behavior.
|
||||
A Jenkins run is needed to observe actual report publication and coverage checks;
|
||||
report any unavailable controller validation explicitly.
|
||||
|
||||
Jenkins behavior references: [post conditions](https://www.jenkins.io/doc/book/pipeline/syntax/#post)
|
||||
and [catchError](https://www.jenkins.io/doc/pipeline/steps/workflow-basic-steps/#catcherror-catch-error-and-set-build-result-to-failure).
|
||||
Reference in New Issue
Block a user