Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/generatePossibleParentsPackages.test.ts
Original file line number Diff line number Diff line change
@@ -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']);
});
})
});
20 changes: 20 additions & 0 deletions src/generatePossiblesParentsPackages.ts
Original file line number Diff line number Diff line change
@@ -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())
}