From 331542f3d268eb5169408c547c2336881bd7f2e7 Mon Sep 17 00:00:00 2001 From: "Gabriel R. Antunes" Date: Thu, 8 May 2025 16:58:28 -0400 Subject: [PATCH 1/2] feat: generatePossiblesParentsPackages --- .../generatePossibleParentsPackages.test.ts | 20 +++++++++++++++++++ src/generatePossiblesParentsPackages.ts | 20 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/__tests__/generatePossibleParentsPackages.test.ts create mode 100644 src/generatePossiblesParentsPackages.ts diff --git a/src/__tests__/generatePossibleParentsPackages.test.ts b/src/__tests__/generatePossibleParentsPackages.test.ts new file mode 100644 index 00000000..04520b33 --- /dev/null +++ b/src/__tests__/generatePossibleParentsPackages.test.ts @@ -0,0 +1,20 @@ +import { describe, expect, it } from '@jest/globals'; +import { generatePossiblesParentsPackages } from '../generatePossiblesParentsPackages.js'; + +describe('generatePossiblesParentsPackages', () => { + describe('paths with package.json', () => { + it('will return an 1 length array with the provided path', () => { + expect(generatePossiblesParentsPackages("package.json")).toEqual(['package.json']); + expect(generatePossiblesParentsPackages("example/package.json")).toEqual(['example/package.json']); + expect(generatePossiblesParentsPackages("example/foo/package.json")).toEqual(['example/foo/package.json']); + }); + }) + + describe('paths without package.json', () => { + it('will return an dynamic length array with the provided path', () => { + expect(generatePossiblesParentsPackages("dotnet.csproj")).toEqual(['package.json']); + expect(generatePossiblesParentsPackages("example/dotnet.csproj")).toEqual(['example/package.json', 'package.json']); + expect(generatePossiblesParentsPackages("example/foo/dotnet.csproj")).toEqual(['example/foo/package.json', 'example/package.json', 'package.json']); + }); + }) +}); diff --git a/src/generatePossiblesParentsPackages.ts b/src/generatePossiblesParentsPackages.ts new file mode 100644 index 00000000..3a68e8ce --- /dev/null +++ b/src/generatePossiblesParentsPackages.ts @@ -0,0 +1,20 @@ +import * as path from "path" + +export const generatePossiblesParentsPackages = function(patchFilename: string) { + const generator = function*() { + if(patchFilename === 'package.json' || patchFilename.endsWith('/package.json')) { + yield patchFilename; + return; + }; + + let cursor = patchFilename; + + do { + cursor = path.dirname(cursor); + const packageJson = path.join(cursor, "package.json"); + yield packageJson; + } while(path.dirname(cursor) !== cursor); + } + + return Array.from(generator()) +} From 92fa26f46bf70fcc3b76ddef3b3537ade9a82588 Mon Sep 17 00:00:00 2001 From: "Gabriel R. Antunes" Date: Thu, 8 May 2025 17:25:52 -0400 Subject: [PATCH 2/2] chore(action): add `input.packages-detection-strategy` option --- action.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/action.yml b/action.yml index 8d9b60dc..2ab9f5e3 100644 --- a/action.yml +++ b/action.yml @@ -36,6 +36,12 @@ inputs: description: 'Generate signed commits. This uses a different Github API which conflicts with custom author information.' required: false default: 'false' + packages-detection-strategy: + description: | + The detection strategy for the affected packages, since this action only relies on affected files diff. + Possible values: `diff-only` (default) and `recursive-discovery` + required: true + default: diff-only # Define your outputs here. outputs: