Skip to content

Commit

Permalink
chore: pretty-print JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman committed Oct 17, 2023
1 parent 4d48438 commit 9d421e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions actions/merge/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2879,7 +2879,7 @@ async function run() {
const hashFile = core.getInput('hash_file');
const images = core.getInput('images');
const newHashes = buildHashes(images.split('\n'), hash);
core.info(`Merging new hashes: ${JSON.stringify(newHashes)}`);
core.info(`Merging new hashes: ${JSON.stringify(newHashes, null, 2)}`);
const hashFileContent = await external_fs_.promises.readFile(hashFile, 'utf8');
const hashFileHashes = JSON.parse(hashFileContent);
const mergedHashes = { ...hashFileHashes, ...newHashes };
Expand All @@ -2889,8 +2889,8 @@ async function run() {
result[key] = mergedHashes[key];
return result;
}, {});
core.info(`Merged hashes: ${JSON.stringify(sortedHashes)}`);
await external_fs_.promises.writeFile(hashFile, JSON.stringify(sortedHashes));
core.info(`Merged hashes: ${JSON.stringify(sortedHashes, null, 2)}`);
await external_fs_.promises.writeFile(hashFile, JSON.stringify(sortedHashes, null, 2));
core.info(`Wrote merged hashes to ${hashFile}`);
}
catch (error) {
Expand Down
16 changes: 10 additions & 6 deletions actions/merge/src/merge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ describe('Merge Action', () => {
expect(writeFileMock).toHaveBeenCalledTimes(1)
expect(writeFileMock).toHaveBeenCalledWith(
'hash_file',
JSON.stringify({
image1: 'hash',
image2: 'hash',
image3: 'hash',
image4: 'old_hash'
})
JSON.stringify(
{
image1: 'hash',
image2: 'hash',
image3: 'hash',
image4: 'old_hash'
},
null,
2
)
)
})
})
Expand Down
6 changes: 3 additions & 3 deletions actions/merge/src/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function run(): Promise<void> {
const images = core.getInput('images')

const newHashes = buildHashes(images.split('\n'), hash)
core.info(`Merging new hashes: ${JSON.stringify(newHashes)}`)
core.info(`Merging new hashes: ${JSON.stringify(newHashes, null, 2)}`)

const hashFileContent = await fs.promises.readFile(hashFile, 'utf8')
const hashFileHashes = JSON.parse(hashFileContent) as Hashes
Expand All @@ -22,9 +22,9 @@ export async function run(): Promise<void> {
result[key] = mergedHashes[key]
return result
}, {} as Hashes)
core.info(`Merged hashes: ${JSON.stringify(sortedHashes)}`)
core.info(`Merged hashes: ${JSON.stringify(sortedHashes, null, 2)}`)

await fs.promises.writeFile(hashFile, JSON.stringify(sortedHashes))
await fs.promises.writeFile(hashFile, JSON.stringify(sortedHashes, null, 2))
core.info(`Wrote merged hashes to ${hashFile}`)
} catch (error) {
if (error instanceof Error) {
Expand Down

0 comments on commit 9d421e3

Please sign in to comment.