Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions .github/workflows/screenshot-test-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Screenshot Test PR Comment

# This workflow is designed to safely comment on PRs from forks
# It uses pull_request_target which has higher permissions than pull_request
# Security note: This workflow does NOT check out or execute code from the PR
# It only monitors the status of the ScreenshotTests job and posts comments
# (If this commenting was done in the main worflow it would not have the permissions
# to create a comment)

on:
pull_request_target:
types: [opened, synchronize, reopened]

jobs:
monitor-screenshot-tests:
name: Monitor Screenshot Tests and Comment
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
pull-requests: write
contents: read
steps:
- name: Wait for GitHub to register the workflow run
run: sleep 15

- name: Wait for Screenshot Tests to complete
uses: lewagon/[email protected]
with:
ref: ${{ github.event.pull_request.head.sha }}
check-name: 'Run Screenshot Tests'
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10
allowed-conclusions: success,skipped,failure
- name: Check Screenshot Tests status
id: check-status
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
const ref = '${{ github.event.pull_request.head.sha }}';

// Get workflow runs for the PR
const runs = await github.rest.actions.listWorkflowRunsForRepo({
owner,
repo,
head_sha: ref
});

// Find the ScreenshotTests job
let screenshotTestRun = null;
for (const run of runs.data.workflow_runs) {
if (run.name === 'Build jMonkeyEngine') {
const jobs = await github.rest.actions.listJobsForWorkflowRun({
owner,
repo,
run_id: run.id
});

for (const job of jobs.data.jobs) {
if (job.name === 'Run Screenshot Tests') {
screenshotTestRun = job;
break;
}
}

if (screenshotTestRun) break;
}
}

if (!screenshotTestRun) {
console.log('Screenshot test job not found');
return;
}

// Check if the job failed
if (screenshotTestRun.conclusion === 'failure') {
core.setOutput('failed', 'true');
} else {
core.setOutput('failed', 'false');
}
- name: Find Existing Comment
uses: peter-evans/find-comment@v3
id: existingCommentId
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Screenshot tests have failed.

- name: Comment on PR if tests fail
if: steps.check-status.outputs.failed == 'true'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
🖼️ **Screenshot tests have failed.**

The purpose of these tests is to ensure that changes introduced in this PR don't break visual features. They are visual unit tests.

📄 **Where to find the report:**
- Go to the (failed run) > Summary > Artifacts > screenshot-test-report
- Download the zip and open jme3-screenshot-tests/build/reports/ScreenshotDiffReport.html

⚠️ **If you didn't expect to change anything visual:**
Fix your changes so the screenshot tests pass.

✅ **If you did mean to change things:**
Review the replacement images in jme3-screenshot-tests/build/changed-images to make sure they really are improvements and then replace and commit the replacement images at jme3-screenshot-tests/src/test/resources.

✨ **If you are creating entirely new tests:**
Find the new images in jme3-screenshot-tests/build/changed-images and commit the new images at jme3-screenshot-tests/src/test/resources.

**Note;** it is very important that the committed reference images are created on the build pipeline, locally created images are not reliable. Similarly tests will fail locally but you can look at the report to check they are "visually similar".

See https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-screenshot-tests/README.md for more information
edit-mode: replace
comment-id: ${{ steps.existingCommentId.outputs.comment-id }}
5 changes: 3 additions & 2 deletions jme3-screenshot-tests/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# jme3-screenshot-tests

This module contains tests that compare screenshots of the JME3 test applications to reference images. The tests are run using
the following command:
This module contains tests that compare screenshots of the JME3 test applications to reference images. Think of these like visual unit tests

The tests are run using the following command:

```
./gradlew :jme3-screenshot-test:screenshotTest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright (c) 2024 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jmonkeyengine.screenshottests.animation;

import com.jme3.anim.SkinningControl;
import com.jme3.anim.util.AnimMigrationUtils;
import com.jme3.animation.SkeletonControl;
import com.jme3.app.Application;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.BaseAppState;
import com.jme3.asset.AssetManager;
import com.jme3.light.AmbientLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.scene.VertexBuffer;
import org.jmonkeyengine.screenshottests.testframework.ScreenshotTestBase;
import org.junit.jupiter.api.Test;

/**
* Screenshot test for JMonkeyEngine issue #2076: software skinning requires vertex
* normals.
*
* <p>If the issue is resolved, 2 copies of the Jaime model will be rendered in the screenshot.
*
* <p>If the issue is present, then the application will immediately crash,
* typically with a {@code NullPointerException}.
*
* @author Stephen Gold (original test)
* @author Richard Tingle (screenshot test adaptation)
*/
public class TestIssue2076 extends ScreenshotTestBase {

/**
* This test creates a scene with two Jaime models, one using the old animation system
* and one using the new animation system, both with software skinning and no vertex normals.
*/
@Test
public void testIssue2076() {
screenshotTest(new BaseAppState() {
@Override
protected void initialize(Application app) {
SimpleApplication simpleApplication = (SimpleApplication) app;
Node rootNode = simpleApplication.getRootNode();
AssetManager assetManager = simpleApplication.getAssetManager();

// Add ambient light
AmbientLight ambientLight = new AmbientLight();
ambientLight.setColor(new ColorRGBA(1f, 1f, 1f, 1f));
rootNode.addLight(ambientLight);

/*
* The original Jaime model was chosen for testing because it includes
* tangent buffers (needed to trigger issue #2076) and uses the old
* animation system (so it can be easily used to test both systems).
*/
String assetPath = "Models/Jaime/Jaime.j3o";

// Test old animation system
Node oldJaime = (Node) assetManager.loadModel(assetPath);
rootNode.attachChild(oldJaime);
oldJaime.setLocalTranslation(-1f, 0f, 0f);

// Enable software skinning
SkeletonControl skeletonControl = oldJaime.getControl(SkeletonControl.class);
skeletonControl.setHardwareSkinningPreferred(false);

// Remove its vertex normals
Geometry oldGeometry = (Geometry) oldJaime.getChild(0);
Mesh oldMesh = oldGeometry.getMesh();
oldMesh.clearBuffer(VertexBuffer.Type.Normal);
oldMesh.clearBuffer(VertexBuffer.Type.BindPoseNormal);

// Test new animation system
Node newJaime = (Node) assetManager.loadModel(assetPath);
AnimMigrationUtils.migrate(newJaime);
rootNode.attachChild(newJaime);
newJaime.setLocalTranslation(1f, 0f, 0f);

// Enable software skinning
SkinningControl skinningControl = newJaime.getControl(SkinningControl.class);
skinningControl.setHardwareSkinningPreferred(false);

// Remove its vertex normals
Geometry newGeometry = (Geometry) newJaime.getChild(0);
Mesh newMesh = newGeometry.getMesh();
newMesh.clearBuffer(VertexBuffer.Type.Normal);
newMesh.clearBuffer(VertexBuffer.Type.BindPoseNormal);

// Position the camera to see both models
simpleApplication.getCamera().setLocation(new Vector3f(0f, 0f, 5f));
}

@Override
protected void cleanup(Application app) {
}

@Override
protected void onEnable() {
}

@Override
protected void onDisable() {
}

@Override
public void update(float tpf) {
super.update(tpf);
}
}).run();
}
}
Loading