Skip to content

Commit 8d3677e

Browse files
committed
export to json
1 parent 9b49e87 commit 8d3677e

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

src/main.ts

+26-7
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,29 @@ async function run(): Promise<void> {
3838
const topMode = core.getInput('top-mode', {required: false})
3939
const topGlob = core.getInput('top-glob', {required: false})
4040

41-
let filtersYaml = ''
4241
if (topMode === 'true') {
4342
// split at first /; sort by first item; group by first item
4443
const groupedFiles = files.map(f => f.filename.split('/', 2)).sort((a, b) => a[0].localeCompare(b[0]))
4544
// find unique first items
4645
const topFolders = [...new Set(groupedFiles.map(f => f[0]))]
47-
// generate the YAML
48-
filtersYaml = jsyaml.dump(topFolders.map(f => ({[f]: `${f}/${topGlob}`})))
46+
let matchedFolders = []
47+
for (const folder of topFolders) {
48+
// generate the YAML
49+
const filtersYaml = jsyaml.dump({[folder]: `${folder}/${topGlob}`})
50+
const filter = new Filter(filtersYaml)
51+
const results = filter.match(files)
52+
if (results[folder].length > 0) {
53+
matchedFolders.push(folder)
54+
}
55+
exportTopModeResults(matchedFolders)
56+
}
4957
} else {
5058
const filtersInput = core.getInput('filters', {required: false})
51-
filtersYaml = isPathInput(filtersInput) ? getConfigFileContent(filtersInput) : filtersInput
59+
const filtersYaml = isPathInput(filtersInput) ? getConfigFileContent(filtersInput) : filtersInput
60+
const filter = new Filter(filtersYaml)
61+
const results = filter.match(files)
62+
exportResults(results, listFiles)
5263
}
53-
const filter = new Filter(filtersYaml)
54-
const results = filter.match(files)
55-
exportResults(results, listFiles)
5664
} catch (error: any) {
5765
core.setFailed(error.message)
5866
}
@@ -229,6 +237,17 @@ async function getChangedFilesFromApi(
229237
}
230238
}
231239

240+
function exportTopModeResults(changedFolders: string[]): void {
241+
core.info('Matching folders:')
242+
for (const folder of changedFolders) {
243+
core.info(folder)
244+
}
245+
246+
const changesJson = JSON.stringify(changedFolders)
247+
core.info(`Changes output set to ${changesJson}`)
248+
core.setOutput('changes', changesJson)
249+
}
250+
232251
function exportResults(results: FilterResults, format: ExportFormat): void {
233252
core.info('Results:')
234253
const changes = []

0 commit comments

Comments
 (0)