Skip to content

Commit b99303a

Browse files
committed
Use writeAsync
1 parent fd8cb31 commit b99303a

File tree

4 files changed

+36
-37
lines changed

4 files changed

+36
-37
lines changed

action/dist/index.js

+18-15
Original file line numberDiff line numberDiff line change
@@ -86105,27 +86105,29 @@ const runImageDiffPlugin = (taskId, taskConfig, { ghToken, ghRepository: { repo,
8610586105
const filename = (0,external_path_.basename)(taskConfig.image).split('.')[0];
8610686106
const imagePath = `${currentDirectory}/${uuid}-image-${filename}.png`;
8610786107
core.info(`[${taskId}] Converting image ${taskConfig.image} to ${imagePath}...`);
86108-
yield dist_default().read(external_fs_default().readFileSync(taskConfig.image), (error, image) => {
86109-
if (error) {
86110-
core.error(`[${taskId}] Error reading image: ${error}`);
86111-
throw error;
86112-
}
86113-
image.write(imagePath);
86114-
});
86108+
try {
86109+
const imageFile = yield dist_default().read(taskConfig.image);
86110+
yield imageFile.writeAsync(imagePath);
86111+
}
86112+
catch (error) {
86113+
core.error(`[${taskId}] Failed to read image ${taskConfig.image}: ${error}`);
86114+
return;
86115+
}
8611586116
core.info(`[${taskId}] Converted image ${taskConfig.image} to ${imagePath}`);
8611686117
const imagePng = png/* PNG.sync.read */.y.sync.read(external_fs_default().readFileSync(imagePath));
8611786118
const { width, height } = imagePng;
8611886119
core.info(`Image size: ${width} x ${height}`);
8611986120
// read baseline and resize
8612086121
const baselinePath = `${currentDirectory}/${uuid}-baseline.png`;
8612186122
core.info(`[${taskId}] Converting baseline ${taskConfig.baseline} to ${baselinePath}...`);
86122-
yield dist_default().read(external_fs_default().readFileSync(taskConfig.baseline), (error, image) => {
86123-
if (error) {
86124-
core.error(`[${taskId}] Error reading baseline: ${error}`);
86125-
throw error;
86126-
}
86127-
image.resize(width, height).write(baselinePath);
86128-
});
86123+
try {
86124+
const baselineFile = yield dist_default().read(taskConfig.baseline);
86125+
yield baselineFile.resize(width, height).writeAsync(baselinePath);
86126+
}
86127+
catch (error) {
86128+
core.error(`[${taskId}] Failed to read baseline ${taskConfig.baseline}: ${error}`);
86129+
return;
86130+
}
8612986131
core.info(`[${taskId}] Converted baseline ${taskConfig.baseline} to ${baselinePath}`);
8613086132
const baselinePng = png/* PNG.sync.read */.y.sync.read(external_fs_default().readFileSync(baselinePath));
8613186133
// create diff
@@ -86585,8 +86587,9 @@ function run(stoatConfig) {
8658586587
else {
8658686588
core.info(`Detected pull request number: ${pullRequestNumber}`);
8658786589
}
86588-
core.info(`Fetching repo's SHA (not the build's merge commit SHA)...`);
86590+
// this is not the build's merge commit SHA
8658986591
const repoSha = core.getInput('actual_sha');
86592+
core.info(`Repo SHA: ${repoSha}`);
8659086593
const ghBranch = core.getInput('pr_branch_name');
8659186594
yield waitForStoatDevServer(github.context.repo, ghBranch, repoSha);
8659286595
core.info('Checking if prior steps succeeded...');

action/dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action/scripts/testJimp.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import Jimp from 'jimp';
22

33
(async () => {
4-
await Jimp.read('../docs/build/img/logo-128.png', (error, image) => {
5-
if (error) {
6-
console.error(`Error reading image: ${error}`);
7-
throw error;
8-
}
9-
image.resize(32, 32).write('resize-logo-32.png');
10-
});
4+
const file = await Jimp.read('../docs/build/img/logo-128.png');
5+
await file.writeAsync('resized.png');
6+
console.log(`Image size: ${file.getWidth()} x ${file.getHeight()}`);
117
})();

action/src/plugins/imageDiff/plugin.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ const runImageDiffPlugin = async (
3535
const filename = basename(taskConfig.image).split('.')[0];
3636
const imagePath = `${currentDirectory}/${uuid}-image-${filename}.png`;
3737
core.info(`[${taskId}] Converting image ${taskConfig.image} to ${imagePath}...`);
38-
await Jimp.read(fs.readFileSync(taskConfig.image), (error, image) => {
39-
if (error) {
40-
core.error(`[${taskId}] Error reading image: ${error}`);
41-
throw error;
42-
}
43-
image.write(imagePath);
44-
});
38+
try {
39+
const imageFile = await Jimp.read(taskConfig.image);
40+
await imageFile.writeAsync(imagePath);
41+
} catch (error) {
42+
core.error(`[${taskId}] Failed to read image ${taskConfig.image}: ${error}`);
43+
return;
44+
}
4545
core.info(`[${taskId}] Converted image ${taskConfig.image} to ${imagePath}`);
4646
const imagePng = PNG.sync.read(fs.readFileSync(imagePath));
4747
const { width, height } = imagePng;
@@ -50,13 +50,13 @@ const runImageDiffPlugin = async (
5050
// read baseline and resize
5151
const baselinePath = `${currentDirectory}/${uuid}-baseline.png`;
5252
core.info(`[${taskId}] Converting baseline ${taskConfig.baseline} to ${baselinePath}...`);
53-
await Jimp.read(fs.readFileSync(taskConfig.baseline), (error, image) => {
54-
if (error) {
55-
core.error(`[${taskId}] Error reading baseline: ${error}`);
56-
throw error;
57-
}
58-
image.resize(width, height).write(baselinePath);
59-
});
53+
try {
54+
const baselineFile = await Jimp.read(taskConfig.baseline);
55+
await baselineFile.resize(width, height).writeAsync(baselinePath);
56+
} catch (error) {
57+
core.error(`[${taskId}] Failed to read baseline ${taskConfig.baseline}: ${error}`);
58+
return;
59+
}
6060
core.info(`[${taskId}] Converted baseline ${taskConfig.baseline} to ${baselinePath}`);
6161
const baselinePng = PNG.sync.read(fs.readFileSync(baselinePath));
6262

0 commit comments

Comments
 (0)