@@ -29440,21 +29440,20 @@ var downloadBaseImages = async () => {
2944029440 `aws s3 cp s3://${bucketName}/${BASE_IMAGES_DIRECTORY} ${screenshotsDirectory} --recursive`
2944129441 );
2944229442};
29443- var uploadAllImages = async () => {
29443+ var uploadAllImages = async (hash ) => {
2944429444 const bucketName = (0, import_core.getInput)("bucket-name", { required: true });
2944529445 const screenshotsDirectory = (0, import_core.getInput)("screenshots-directory");
29446- const commitHash = (0, import_core.getInput)("commit-hash", { required: true });
2944729446 const packagePaths = (0, import_core.getInput)("package-paths")?.split(",");
2944829447 if (packagePaths) {
2944929448 return (0, import_bluebird.map)(
2945029449 packagePaths,
2945129450 (packagePath) => (0, import_exec.exec)(
29452- `aws s3 cp ${screenshotsDirectory}/${packagePath} s3://${bucketName}/${NEW_IMAGES_DIRECTORY}/${commitHash }/${packagePath} --recursive`
29451+ `aws s3 cp ${screenshotsDirectory}/${packagePath} s3://${bucketName}/${NEW_IMAGES_DIRECTORY}/${hash }/${packagePath} --recursive`
2945329452 )
2945429453 );
2945529454 }
2945629455 return (0, import_exec.exec)(
29457- `aws s3 cp ${screenshotsDirectory} s3://${bucketName}/${NEW_IMAGES_DIRECTORY}/${commitHash } --recursive`
29456+ `aws s3 cp ${screenshotsDirectory} s3://${bucketName}/${NEW_IMAGES_DIRECTORY}/${hash } --recursive`
2945829457 );
2945929458};
2946029459var uploadBaseImages = async (newFilePaths) => {
@@ -35866,19 +35865,18 @@ var import_core4 = __toESM(require_core());
3586635865// src/build-comparadise-url.ts
3586735866var import_core3 = __toESM(require_core());
3586835867var import_github2 = __toESM(require_github());
35869- var buildComparadiseUrl = () => {
35868+ var buildComparadiseUrl = (hash ) => {
3587035869 const bucketName = (0, import_core3.getInput)("bucket-name", { required: true });
35871- const commitHash = (0, import_core3.getInput)("commit-hash", { required: true });
3587235870 const comparadiseHost = (0, import_core3.getInput)("comparadise-host");
3587335871 const { owner, repo } = import_github2.context.repo;
35874- return `${comparadiseHost}/?hash=${commitHash }&owner=${owner}&repo=${repo}&bucket=${bucketName}`;
35872+ return `${comparadiseHost}/?hash=${hash }&owner=${owner}&repo=${repo}&bucket=${bucketName}`;
3587535873};
3587635874
3587735875// src/comment.ts
3587835876var createGithubComment = async () => {
3587935877 const commitHash = (0, import_core4.getInput)("commit-hash", { required: true });
3588035878 const comparadiseHost = (0, import_core4.getInput)("comparadise-host");
35881- const comparadiseUrl = buildComparadiseUrl();
35879+ const comparadiseUrl = buildComparadiseUrl(commitHash );
3588235880 const comparadiseLink = comparadiseHost ? `[Comparadise](${comparadiseUrl})` : "Comparadise";
3588335881 const comparadiseBaseComment = `**Visual tests failed!**
3588435882Check out the diffs on ${comparadiseLink}! :palm_tree:`;
@@ -35949,13 +35947,24 @@ var disableAutoMerge = async (commitHash) => {
3594935947};
3595035948
3595135949// src/run.ts
35950+ var VISUAL_TEST_EXECUTION_FAILURE = "Visual tests failed to execute successfully. Perhaps one failed to take a screenshot?";
35951+ var VISUAL_TESTS_PASSED = "All visual tests passed, and no diffs found!";
3595235952var run = async () => {
3595335953 const runAttempt = Number(process.env.GITHUB_RUN_ATTEMPT);
3595435954 const isRetry = runAttempt > 1;
3595535955 const visualTestCommands = (0, import_core6.getMultilineInput)("visual-test-command", {
3595635956 required: true
3595735957 });
35958- const commitHash = (0, import_core6.getInput)("commit-hash", { required: true });
35958+ const commitHash = (0, import_core6.getInput)("commit-hash");
35959+ const diffId = (0, import_core6.getInput)("diff-id");
35960+ if (!commitHash && !diffId) {
35961+ (0, import_core6.setFailed)("You must provide either commit-hash or diff-id.");
35962+ return;
35963+ }
35964+ if (commitHash && diffId) {
35965+ (0, import_core6.setFailed)("You cannot provide both commit-hash and diff-id. Choose one.");
35966+ return;
35967+ }
3595935968 const screenshotsDirectory = (0, import_core6.getInput)("screenshots-directory");
3596035969 await downloadBaseImages();
3596135970 const visualTestExitCode = await Promise.all(
@@ -35964,7 +35973,6 @@ var run = async () => {
3596435973 const numVisualTestFailures = visualTestExitCode.filter(
3596535974 (code) => code !== 0
3596635975 ).length;
35967- const latestVisualRegressionStatus = await getLatestVisualRegressionStatus(commitHash);
3596835976 const screenshotsPath = path3.join(process.cwd(), screenshotsDirectory);
3596935977 const filesInScreenshotDirectory = sync(`${screenshotsPath}/**`, { absolute: false }) || [];
3597035978 const diffFilePaths = filesInScreenshotDirectory.filter(
@@ -35983,6 +35991,29 @@ var run = async () => {
3598335991 return count;
3598435992 }, 0);
3598535993 const newFileCount = newFilePaths.length;
35994+ if (diffId) {
35995+ if (numVisualTestFailures > diffFileCount) {
35996+ (0, import_core6.setFailed)(VISUAL_TEST_EXECUTION_FAILURE);
35997+ return;
35998+ }
35999+ if (diffFileCount === 0) {
36000+ if (newFileCount === 0) {
36001+ (0, import_core6.info)(VISUAL_TESTS_PASSED);
36002+ return;
36003+ } else if (newFileCount > 0) {
36004+ (0, import_core6.info)(
36005+ `New visual tests found! ${newFileCount} images will be uploaded as new base images.`
36006+ );
36007+ await uploadBaseImages(newFilePaths);
36008+ return;
36009+ }
36010+ }
36011+ (0, import_core6.info)(
36012+ `A visual regression was detected. ${diffFileCount} visual differences found`
36013+ );
36014+ await uploadAllImages(diffId);
36015+ return;
36016+ }
3598636017 if (numVisualTestFailures > diffFileCount) {
3598736018 (0, import_core6.setFailed)(
3598836019 "Visual tests failed to execute successfully. Perhaps one failed to take a screenshot?"
@@ -35995,6 +36026,7 @@ var run = async () => {
3599536026 ...import_github6.context.repo
3599636027 });
3599736028 }
36029+ const latestVisualRegressionStatus = await getLatestVisualRegressionStatus(commitHash);
3599836030 if (diffFileCount === 0 && newFileCount === 0) {
3599936031 (0, import_core6.info)("All visual tests passed, and no diffs found!");
3600036032 if (isRetry) {
@@ -36038,13 +36070,13 @@ var run = async () => {
3603836070 ...import_github6.context.repo
3603936071 });
3604036072 }
36041- await uploadAllImages();
36073+ await uploadAllImages(commitHash );
3604236074 await octokit.rest.repos.createCommitStatus({
3604336075 sha: commitHash,
3604436076 context: VISUAL_REGRESSION_CONTEXT,
3604536077 state: "failure",
3604636078 description: "A visual regression was detected. Check Comparadise!",
36047- target_url: buildComparadiseUrl(),
36079+ target_url: buildComparadiseUrl(commitHash ),
3604836080 ...import_github6.context.repo
3604936081 });
3605036082 await createGithubComment();
0 commit comments