Merge pull request #25764 from Teo-ShaoWei/shaowei/fix-scaffolder-catalog-write

fix: scaffolder action catalog:write not working in nested folders
This commit is contained in:
Ben Lambert
2024-07-29 10:21:07 +02:00
committed by GitHub
4 changed files with 14 additions and 9 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': patch
---
Fix scaffolder action `catalog:write` to write to directories that don't already exist
@@ -55,8 +55,8 @@ describe('catalog:write', () => {
input: yaml.parse(examples[0].example).steps[0].input,
});
expect(fsMock.writeFile).toHaveBeenCalledTimes(1);
expect(fsMock.writeFile).toHaveBeenCalledWith(
expect(fsMock.outputFile).toHaveBeenCalledTimes(1);
expect(fsMock.outputFile).toHaveBeenCalledWith(
resolvePath(mockContext.workspacePath, 'catalog-info.yaml'),
yaml.stringify(entity),
);
@@ -59,8 +59,8 @@ describe('catalog:write', () => {
},
});
expect(fsMock.writeFile).toHaveBeenCalledTimes(1);
expect(fsMock.writeFile).toHaveBeenCalledWith(
expect(fsMock.outputFile).toHaveBeenCalledTimes(1);
expect(fsMock.outputFile).toHaveBeenCalledWith(
resolvePath(mockContext.workspacePath, 'catalog-info.yaml'),
yaml.stringify(entity),
);
@@ -88,8 +88,8 @@ describe('catalog:write', () => {
},
});
expect(fsMock.writeFile).toHaveBeenCalledTimes(1);
expect(fsMock.writeFile).toHaveBeenCalledWith(
expect(fsMock.outputFile).toHaveBeenCalledTimes(1);
expect(fsMock.outputFile).toHaveBeenCalledWith(
resolvePath(mockContext.workspacePath, 'some-dir/entity-info.yaml'),
yaml.stringify(entity),
);
@@ -118,8 +118,8 @@ describe('catalog:write', () => {
'backstage.io/source-template': 'template:default/test-skeleton',
};
expect(fsMock.writeFile).toHaveBeenCalledTimes(1);
expect(fsMock.writeFile).toHaveBeenCalledWith(
expect(fsMock.outputFile).toHaveBeenCalledTimes(1);
expect(fsMock.outputFile).toHaveBeenCalledWith(
resolvePath(mockContext.workspacePath, 'catalog-info.yaml'),
yaml.stringify(expectedEntity),
);
@@ -54,7 +54,7 @@ export function createCatalogWriteAction() {
const path = filePath ?? 'catalog-info.yaml';
ctx.logger.info(`Writing ${path}`);
await fs.writeFile(
await fs.outputFile(
resolveSafeChildPath(ctx.workspacePath, path),
yaml.stringify({
...entity,