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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ yarn-error.log*

secrets.json

cypress/screenshots
app/frontend/cypress/downloads
app/frontend/cypress/screenshots
app/frontend/cypress/videos

.nx/
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ inputs:
required: true
commit-hash:
description: 'The commit hash'
required: true
required: false
diff-id:
description: 'Alternative to commit-hash as a unique identifier for visual tests. GitHub integration will be disabled if diff-id is used.'
required: false
screenshots-directory:
description: 'The directory where your visual tests expect screenshots to be'
required: false
Expand Down
33 changes: 22 additions & 11 deletions action/dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29440,21 +29440,20 @@ var downloadBaseImages = async () => {
`aws s3 cp s3://${bucketName}/${BASE_IMAGES_DIRECTORY} ${screenshotsDirectory} --recursive`
);
};
var uploadAllImages = async () => {
var uploadAllImages = async (hash) => {
const bucketName = (0, import_core.getInput)("bucket-name", { required: true });
const screenshotsDirectory = (0, import_core.getInput)("screenshots-directory");
const commitHash = (0, import_core.getInput)("commit-hash", { required: true });
const packagePaths = (0, import_core.getInput)("package-paths")?.split(",");
if (packagePaths) {
return (0, import_bluebird.map)(
packagePaths,
(packagePath) => (0, import_exec.exec)(
`aws s3 cp ${screenshotsDirectory}/${packagePath} s3://${bucketName}/${NEW_IMAGES_DIRECTORY}/${commitHash}/${packagePath} --recursive`
`aws s3 cp ${screenshotsDirectory}/${packagePath} s3://${bucketName}/${NEW_IMAGES_DIRECTORY}/${hash}/${packagePath} --recursive`
)
);
}
return (0, import_exec.exec)(
`aws s3 cp ${screenshotsDirectory} s3://${bucketName}/${NEW_IMAGES_DIRECTORY}/${commitHash} --recursive`
`aws s3 cp ${screenshotsDirectory} s3://${bucketName}/${NEW_IMAGES_DIRECTORY}/${hash} --recursive`
);
};
var uploadBaseImages = async (newFilePaths) => {
Expand Down Expand Up @@ -35868,10 +35867,12 @@ var import_core3 = __toESM(require_core());
var import_github2 = __toESM(require_github());
var buildComparadiseUrl = () => {
const bucketName = (0, import_core3.getInput)("bucket-name", { required: true });
const commitHash = (0, import_core3.getInput)("commit-hash", { required: true });
const comparadiseHost = (0, import_core3.getInput)("comparadise-host");
const commitHash = (0, import_core3.getInput)("commit-hash");
const diffId = (0, import_core3.getInput)("diff-id");
const hashParam = commitHash ? `commitHash=${commitHash}` : `diffId=${diffId}`;
const { owner, repo } = import_github2.context.repo;
return `${comparadiseHost}/?hash=${commitHash}&owner=${owner}&repo=${repo}&bucket=${bucketName}`;
return `${comparadiseHost}/?${hashParam}&owner=${owner}&repo=${repo}&bucket=${bucketName}`;
};

// src/comment.ts
Expand Down Expand Up @@ -35917,7 +35918,7 @@ var getLatestVisualRegressionStatus = async (commitHash) => {
return data.find((status) => status.context === VISUAL_REGRESSION_CONTEXT);
};

// src/disableAutoMerge.ts
// src/disable-auto-merge.ts
var import_core5 = __toESM(require_core());
var import_github5 = __toESM(require_github());
var disableAutoMerge = async (commitHash) => {
Expand Down Expand Up @@ -35955,7 +35956,13 @@ var run = async () => {
const visualTestCommands = (0, import_core6.getMultilineInput)("visual-test-command", {
required: true
});
const commitHash = (0, import_core6.getInput)("commit-hash", { required: true });
const commitHash = (0, import_core6.getInput)("commit-hash");
const diffId = (0, import_core6.getInput)("diff-id");
if (!commitHash && !diffId) {
(0, import_core6.setFailed)("Please provide either a commit-hash or a diff-id.");
return;
}
const hash = commitHash || diffId;
const screenshotsDirectory = (0, import_core6.getInput)("screenshots-directory");
await downloadBaseImages();
const visualTestExitCode = await Promise.all(
Expand All @@ -35964,7 +35971,6 @@ var run = async () => {
const numVisualTestFailures = visualTestExitCode.filter(
(code) => code !== 0
).length;
const latestVisualRegressionStatus = await getLatestVisualRegressionStatus(commitHash);
const screenshotsPath = path3.join(process.cwd(), screenshotsDirectory);
const filesInScreenshotDirectory = sync(`${screenshotsPath}/**`, { absolute: false }) || [];
const diffFilePaths = filesInScreenshotDirectory.filter(
Expand All @@ -35987,6 +35993,7 @@ var run = async () => {
(0, import_core6.setFailed)(
"Visual tests failed to execute successfully. Perhaps one failed to take a screenshot?"
);
if (!commitHash) return;
return octokit.rest.repos.createCommitStatus({
sha: commitHash,
context: VISUAL_REGRESSION_CONTEXT,
Expand All @@ -35995,8 +36002,10 @@ var run = async () => {
...import_github6.context.repo
});
}
const latestVisualRegressionStatus = commitHash ? await getLatestVisualRegressionStatus(commitHash) : null;
if (diffFileCount === 0 && newFileCount === 0) {
(0, import_core6.info)("All visual tests passed, and no diffs found!");
if (!commitHash) return;
if (isRetry) {
(0, import_core6.warning)(
"Disabling auto merge because this is a retry attempt. This is to avoid auto merging prematurely."
Expand All @@ -36016,7 +36025,7 @@ var run = async () => {
...import_github6.context.repo
});
}
if (latestVisualRegressionStatus?.state === "failure" && latestVisualRegressionStatus?.description === VISUAL_TESTS_FAILED_TO_EXECUTE && !isRetry) {
if (commitHash && latestVisualRegressionStatus?.state === "failure" && latestVisualRegressionStatus?.description === VISUAL_TESTS_FAILED_TO_EXECUTE && !isRetry) {
(0, import_core6.warning)(
"Some other Visual Regression tests failed to execute successfully, so skipping status update and comment."
);
Expand All @@ -36030,6 +36039,7 @@ var run = async () => {
`New visual tests found! ${newFileCount} images will be uploaded as new base images.`
);
await uploadBaseImages(newFilePaths);
if (!commitHash) return;
return octokit.rest.repos.createCommitStatus({
sha: commitHash,
context: VISUAL_REGRESSION_CONTEXT,
Expand All @@ -36038,7 +36048,8 @@ var run = async () => {
...import_github6.context.repo
});
}
await uploadAllImages();
await uploadAllImages(hash);
if (!commitHash) return;
await octokit.rest.repos.createCommitStatus({
sha: commitHash,
context: VISUAL_REGRESSION_CONTEXT,
Expand Down
2 changes: 1 addition & 1 deletion action/dist/main.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions action/src/build-comparadise-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { context } from '@actions/github';

export const buildComparadiseUrl = () => {
const bucketName = getInput('bucket-name', { required: true });
const commitHash = getInput('commit-hash', { required: true });
const comparadiseHost = getInput('comparadise-host');
const commitHash = getInput('commit-hash');
const diffId = getInput('diff-id');
const hashParam = commitHash
? `commitHash=${commitHash}`
: `diffId=${diffId}`;
const { owner, repo } = context.repo;

return `${comparadiseHost}/?hash=${commitHash}&owner=${owner}&repo=${repo}&bucket=${bucketName}`;
return `${comparadiseHost}/?${hashParam}&owner=${owner}&repo=${repo}&bucket=${bucketName}`;
};
File renamed without changes.
26 changes: 21 additions & 5 deletions action/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@ import {
VISUAL_TESTS_FAILED_TO_EXECUTE
} from 'shared';
import { buildComparadiseUrl } from './build-comparadise-url';
import { disableAutoMerge } from './disableAutoMerge';
import { disableAutoMerge } from './disable-auto-merge';

export const run = async () => {
const runAttempt = Number(process.env.GITHUB_RUN_ATTEMPT);
const isRetry = runAttempt > 1;
const visualTestCommands = getMultilineInput('visual-test-command', {
required: true
});
const commitHash = getInput('commit-hash', { required: true });
const commitHash = getInput('commit-hash');
const diffId = getInput('diff-id');

if (!commitHash && !diffId) {
setFailed('Please provide either a commit-hash or a diff-id.');
return;
}

const hash = commitHash || diffId;

const screenshotsDirectory = getInput('screenshots-directory');

await downloadBaseImages();
Expand All @@ -42,8 +51,6 @@ export const run = async () => {
code => code !== 0
).length;

const latestVisualRegressionStatus =
await getLatestVisualRegressionStatus(commitHash);
const screenshotsPath = path.join(process.cwd(), screenshotsDirectory);
const filesInScreenshotDirectory =
sync(`${screenshotsPath}/**`, { absolute: false }) || [];
Expand All @@ -70,6 +77,7 @@ export const run = async () => {
setFailed(
'Visual tests failed to execute successfully. Perhaps one failed to take a screenshot?'
);
if (!commitHash) return;
return octokit.rest.repos.createCommitStatus({
sha: commitHash,
context: VISUAL_REGRESSION_CONTEXT,
Expand All @@ -79,9 +87,14 @@ export const run = async () => {
});
}

const latestVisualRegressionStatus = commitHash
? await getLatestVisualRegressionStatus(commitHash)
: null;

if (diffFileCount === 0 && newFileCount === 0) {
info('All visual tests passed, and no diffs found!');

if (!commitHash) return;
if (isRetry) {
warning(
'Disabling auto merge because this is a retry attempt. This is to avoid auto merging prematurely.'
Expand All @@ -104,6 +117,7 @@ export const run = async () => {
}

if (
commitHash &&
latestVisualRegressionStatus?.state === 'failure' &&
latestVisualRegressionStatus?.description ===
VISUAL_TESTS_FAILED_TO_EXECUTE &&
Expand All @@ -124,6 +138,7 @@ export const run = async () => {
`New visual tests found! ${newFileCount} images will be uploaded as new base images.`
);
await uploadBaseImages(newFilePaths);
if (!commitHash) return;
return octokit.rest.repos.createCommitStatus({
sha: commitHash,
context: VISUAL_REGRESSION_CONTEXT,
Expand All @@ -133,7 +148,8 @@ export const run = async () => {
});
}

await uploadAllImages();
await uploadAllImages(hash);
if (!commitHash) return;
await octokit.rest.repos.createCommitStatus({
sha: commitHash,
context: VISUAL_REGRESSION_CONTEXT,
Expand Down
7 changes: 3 additions & 4 deletions action/src/s3-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,20 @@ export const downloadBaseImages = async () => {
);
};

export const uploadAllImages = async () => {
export const uploadAllImages = async (hash: string) => {
const bucketName = getInput('bucket-name', { required: true });
const screenshotsDirectory = getInput('screenshots-directory');
const commitHash = getInput('commit-hash', { required: true });
const packagePaths = getInput('package-paths')?.split(',');
if (packagePaths) {
return map(packagePaths, packagePath =>
exec(
`aws s3 cp ${screenshotsDirectory}/${packagePath} s3://${bucketName}/${NEW_IMAGES_DIRECTORY}/${commitHash}/${packagePath} --recursive`
`aws s3 cp ${screenshotsDirectory}/${packagePath} s3://${bucketName}/${NEW_IMAGES_DIRECTORY}/${hash}/${packagePath} --recursive`
)
);
}

return exec(
`aws s3 cp ${screenshotsDirectory} s3://${bucketName}/${NEW_IMAGES_DIRECTORY}/${commitHash} --recursive`
`aws s3 cp ${screenshotsDirectory} s3://${bucketName}/${NEW_IMAGES_DIRECTORY}/${hash} --recursive`
);
};

Expand Down
Loading
Loading