From 9f68be011c8951cc68eca4f437e2df77184c99f7 Mon Sep 17 00:00:00 2001 From: Lucas Yarid Date: Fri, 17 May 2024 11:21:10 +0200 Subject: [PATCH] filter out shared from yaml anchor output --- __tests__/filter.test.ts | 13 +++++++++++++ src/main.ts | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/__tests__/filter.test.ts b/__tests__/filter.test.ts index 7d7da947..6f5a9b4d 100644 --- a/__tests__/filter.test.ts +++ b/__tests__/filter.test.ts @@ -1,5 +1,15 @@ +import * as core from '@actions/core' import {Filter, FilterConfig, PredicateQuantifier} from '../src/filter' import {File, ChangeStatus} from '../src/file' +import {exportResults} from '../src/main' + +jest.mock('@actions/core', () => ({ + info: jest.fn(), + setFailed: jest.fn(), + startGroup: jest.fn(), + setOutput: jest.fn(), + endGroup: jest.fn() +})) describe('yaml filter parsing tests', () => { test('throws if yaml is not a dictionary', () => { @@ -160,6 +170,9 @@ describe('matching tests', () => { const filter = new Filter(yaml) const files = modified(['config/settings.yml']) const match = filter.match(files) + exportResults(match, 'none') + + expect(core.setOutput).toHaveBeenCalledWith('changes', '["src"]') expect(match.src).toEqual(files) }) }) diff --git a/src/main.ts b/src/main.ts index 8320287c..e78b3b23 100644 --- a/src/main.ts +++ b/src/main.ts @@ -228,7 +228,7 @@ async function getChangedFilesFromApi(token: string, pullRequest: PullRequestEve } } -function exportResults(results: FilterResults, format: ExportFormat): void { +export function exportResults(results: FilterResults, format: ExportFormat): void { core.info('Results:') const changes = [] for (const [key, files] of Object.entries(results)) { @@ -254,7 +254,8 @@ function exportResults(results: FilterResults, format: ExportFormat): void { } if (results['changes'] === undefined) { - const changesJson = JSON.stringify(changes) + const filteredShared = changes.filter(change => change !== 'shared') + const changesJson = JSON.stringify(filteredShared) core.info(`Changes output set to ${changesJson}`) core.setOutput('changes', changesJson) } else {