diff --git a/README.md b/README.md index 236bf5b..c2dfb40 100644 --- a/README.md +++ b/README.md @@ -74,12 +74,12 @@ jobs: name: Lint flutter code steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Flutter - uses: subosito/flutter-action@v1 + uses: subosito/flutter-action@v2 - run: flutter pub get - name: Analyze Flutter - uses: ValentinVignal/action-dart-analyze@v0.13 + uses: ValentinVignal/action-dart-analyze@v0.14 with: fail-on: 'warning' ``` diff --git a/dist/index.js b/dist/index.js index 3056846..eff50b5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -16551,7 +16551,6 @@ function format(params) { const lines = output.trim().split(/\r?\n/); const errLines = errOutputs.trim().split(/\r?\n/); const fileNotFormatted = new Set(); - const currentWorkingDirectory = process.cwd(); for (const line of [...lines, ...errLines]) { if (!line.startsWith('Changed')) { continue; @@ -16562,7 +16561,7 @@ function format(params) { if (params.ignoredFiles.has(file)) { continue; } - if (params.modifiedFiles.has(path.join(currentWorkingDirectory, ActionOptions_1.actionOptions.workingDirectory, file))) { + if (params.modifiedFiles.has(path.join(ActionOptions_1.actionOptions.workingDirectory, file))) { fileNotFormatted.add(file); console.log(`::warning file=${file}:: ${file} is not formatted`); } @@ -17175,7 +17174,7 @@ const utils_1 = __nccwpck_require__(3030); const path_1 = __importDefault(__nccwpck_require__(5622)); const ActionOptions_1 = __nccwpck_require__(3615); /** - * Modified lines chunk of a file + * Modified lines chunk of a file. */ class FileLines { constructor(params) { @@ -17315,6 +17314,8 @@ class ModifiedFiles { const files = yield this.getGithubFiles(); for (const file of files) { this.files.set(path_1.default.join(process.env.GITHUB_WORKSPACE, file.filename), new ModifiedFile(file)); + const modifiedFile = new ModifiedFile(file); + this.files.set(modifiedFile.name, modifiedFile); } this._resolveInit(true); }); @@ -17360,10 +17361,12 @@ class ModifiedFiles { }); } /** - * Check whether a file is modified + * Check whether a file is modified. + * + * This needs to be the absolute path of the file (`'/home/runner/work/...'`). * * @param fileName - * @returns true if fileName is a modified file + * @returns `true` if {@link fileName} is a modified file. */ has(fileName) { return this.files.has(fileName); diff --git a/src/format/Format.test.ts b/src/format/Format.test.ts index c58ff21..0b52b97 100644 --- a/src/format/Format.test.ts +++ b/src/format/Format.test.ts @@ -1,9 +1,3 @@ -const mockPath = { - join: jest.fn(), -}; - -jest.mock('path', () => mockPath); - const mockActionOptions = { actionOptions: {} as ActionOptions, }; @@ -31,7 +25,7 @@ describe('Format', () => { it('should concatenate the cwd to files from the format command to compare them with the modified files', async () => { mockActionOptions.actionOptions = { format: true, - workingDirectory: 'actionOptionWorkingDirectory', + workingDirectory: 'cwd/actionOptionWorkingDirectory', failOn: FailOnEnum.Format, } as ActionOptions; const ignoredFiles: Partial = { @@ -55,8 +49,6 @@ describe('Format', () => { return ['cwd/actionOptionWorkingDirectory/lib/file_0.dart', 'cwd/actionOptionWorkingDirectory/lib/file_1.dart'].includes(file); }); - jest.spyOn(process, 'cwd').mockReturnValue('cwd'); - mockPath.join.mockImplementation((...args: string[]) => args.join('/')); const result = await format({ modifiedFiles: modifiedFiles as ModifiedFiles, diff --git a/src/format/Format.ts b/src/format/Format.ts index bb882b6..427815f 100644 --- a/src/format/Format.ts +++ b/src/format/Format.ts @@ -40,7 +40,6 @@ export async function format(params: { modifiedFiles: ModifiedFiles, ignoredFile const lines = output.trim().split(/\r?\n/); const errLines = errOutputs.trim().split(/\r?\n/); const fileNotFormatted = new Set(); - const currentWorkingDirectory = process.cwd(); for (const line of [...lines, ...errLines]) { if (!line.startsWith('Changed')) { @@ -53,7 +52,7 @@ export async function format(params: { modifiedFiles: ModifiedFiles, ignoredFile if (params.ignoredFiles.has(file)) { continue; } - if (params.modifiedFiles.has(path.join(currentWorkingDirectory, actionOptions.workingDirectory, file))) { + if (params.modifiedFiles.has(path.join(actionOptions.workingDirectory, file))) { fileNotFormatted.add(file); console.log(`::warning file=${file}:: ${file} is not formatted`); } diff --git a/src/utils/ModifiedFiles.ts b/src/utils/ModifiedFiles.ts index 68e4194..2e3e043 100644 --- a/src/utils/ModifiedFiles.ts +++ b/src/utils/ModifiedFiles.ts @@ -11,7 +11,7 @@ interface FileLinesInterface { } /** - * Modified lines chunk of a file + * Modified lines chunk of a file. */ class FileLines { readonly start: number; @@ -37,6 +37,9 @@ export interface ModifiedFileInterface { * A modified file */ class ModifiedFile { + /** + * The file name from the root directory (`'lib/src/...'`). + */ readonly name: string; readonly deletions: FileLines[]; readonly additions: FileLines[]; @@ -182,6 +185,8 @@ export class ModifiedFiles { const files = await this.getGithubFiles(); for (const file of files) { this.files.set(path.join(process.env.GITHUB_WORKSPACE!, file.filename), new ModifiedFile(file)); + const modifiedFile = new ModifiedFile(file); + this.files.set(modifiedFile.name, modifiedFile); } this._resolveInit(true); } @@ -234,10 +239,12 @@ export class ModifiedFiles { } /** - * Check whether a file is modified - * + * Check whether a file is modified. + * + * This needs to be the absolute path of the file (`'/home/runner/work/...'`). + * * @param fileName - * @returns true if fileName is a modified file + * @returns `true` if {@link fileName} is a modified file. */ public has(fileName: string): boolean { return this.files.has(fileName);