Skip to content

Commit eefc0a2

Browse files
committed
feat: add json output counterparts for existing filename outputs
1 parent 6dafa7f commit eefc0a2

6 files changed

Lines changed: 21 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ any-matches:
6666

6767
# one set of outputs for each entry in change-map
6868
<change-map.0.0>: '<file_changed1> <file_changed2> ...'
69+
# Returns a json array of the changes that can be used with fromJSON in the workflow
70+
<change-map.0.0>-json: '["<file_changed1>", "<file_changed2>", ...]'
6971
# Value set to make boolean checks simpler - 'true' or 'false'
7072
# 'false' if there were no changes found
7173
any-<change-map.0.0>: 'true'
7274
# If separate deletes key is true
7375
deleted-<change-map.0.0>: '<file_deleted1> <file_deleted2> ...'
76+
deleted-<change-map.0.0>-json: '<file_deleted1> <file_deleted2> ...'
7477
```
7578
7679
eg. Referring back to the inputs example of a Python project.

__tests__/main.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import process from 'node:process';
55
import tmp from 'tmp';
66
import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest';
77

8+
function escapeRegex(string: string): string {
9+
return string.replaceAll(/[/\-\\^$*+?.()|[\]{}]/g, String.raw`\$&`);
10+
}
11+
812
function regexOutput(fieldName: string, value: string): RegExp {
9-
return new RegExp(`${fieldName}<<(?<delim>ghadelimiter_.+)\\n${value}\\n\\k<delim>`);
13+
return new RegExp(`${fieldName}<<(?<delim>ghadelimiter_.+)\\n${escapeRegex(value)}\\n\\k<delim>`);
1014
}
1115

1216
describe('main action', () => {
@@ -70,18 +74,23 @@ describe('main action', () => {
7074

7175
const expectedPngOutput = [
7276
regexOutput('deleted-png', ''),
77+
regexOutput('deleted-png-json', JSON.stringify([])),
7378
regexOutput('png', 'added_img.png changed_img.png'),
79+
regexOutput('png-json', JSON.stringify(['added_img.png', 'changed_img.png'])),
7480
regexOutput('any-png', 'true'),
7581
];
7682

7783
const expectedTxtOutput = [
7884
regexOutput('deleted-txt', 'deleted_text.txt'),
85+
regexOutput('deleted-txt-json', JSON.stringify(['deleted_text.txt'])),
7986
regexOutput('txt', 'added_text.txt changed_text.txt'),
87+
regexOutput('txt-json', JSON.stringify(['added_text.txt', 'changed_text.txt'])),
8088
regexOutput('any-txt', 'true'),
8189
];
8290

8391
const expectedMissingOutput = [
8492
regexOutput('missing', ''),
93+
regexOutput('missing-json', JSON.stringify([])),
8594
regexOutput('any-missing', 'false'),
8695
regexOutput('any-matches', 'true'),
8796
];

dist/index.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "file-changes",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"private": true,
55
"description": "A customisable filter that uses git to get changed files based on rules and sets them to outputs",
66
"keywords": [

src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export async function run(): Promise<void> {
4848
if (separateDeleted) {
4949
// If we must separate deleted, we do
5050
core.setOutput(`deleted-${label}`, deletedFiles.join(' '));
51+
core.setOutput(`deleted-${label}-json`, deletedFiles);
5152
} else {
5253
// If we don't need to separate deleted we add them to
5354
// the existing group of ADDED & CHANGED
@@ -56,6 +57,8 @@ export async function run(): Promise<void> {
5657

5758
// Set the plain output
5859
core.setOutput(label, existingFileChanges.join(' '));
60+
// Set the JSON output - this should result in a JSON array
61+
core.setOutput(`${label}-json`, existingFileChanges);
5962
// Set the boolean flag to indicate any changes were found for this label
6063
core.setOutput(`any-${label}`, globChanges);
6164
}

0 commit comments

Comments
 (0)