Merge pull request #7051 from twonds/fix/backstage-scaffolder-backend/fetch-template-file-permissions
fix: scaffolder backend fetch:template preserves file permissions when templating
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': patch
|
||||
---
|
||||
|
||||
Fix issue #7021 scaffolder action fetch:template preserves templates file permissions
|
||||
@@ -146,6 +146,10 @@ describe('fetch:template', () => {
|
||||
mockFetchContents.mockImplementation(({ outputPath }) => {
|
||||
mockFs({
|
||||
[outputPath]: {
|
||||
'an-executable.sh': mockFs.file({
|
||||
content: '#!/usr/bin/env bash',
|
||||
mode: parseInt('100755', 8),
|
||||
}),
|
||||
'empty-dir-${{ values.count }}': {},
|
||||
'static.txt': 'static content',
|
||||
'${{ values.name }}.txt': 'static content',
|
||||
@@ -211,6 +215,13 @@ describe('fetch:template', () => {
|
||||
fs.readFile(`${workspacePath}/target/a-binary-file.png`),
|
||||
).resolves.toEqual(aBinaryFile);
|
||||
});
|
||||
it('copies files and maintains the original file permissions', async () => {
|
||||
await expect(
|
||||
fs
|
||||
.stat(`${workspacePath}/target/an-executable.sh`)
|
||||
.then(fObj => fObj.mode),
|
||||
).resolves.toEqual(parseInt('100755', 8));
|
||||
});
|
||||
});
|
||||
|
||||
describe('copyWithoutRender', () => {
|
||||
|
||||
@@ -262,8 +262,9 @@ export function createFetchTemplateAction(options: {
|
||||
);
|
||||
await fs.copy(inputFilePath, outputPath);
|
||||
} else {
|
||||
const statsObj = await fs.stat(inputFilePath);
|
||||
ctx.logger.info(
|
||||
`Writing file ${location} to template output path.`,
|
||||
`Writing file ${location} to template output path with mode ${statsObj.mode}.`,
|
||||
);
|
||||
const inputFileContents = await fs.readFile(inputFilePath, 'utf-8');
|
||||
await fs.outputFile(
|
||||
@@ -271,6 +272,7 @@ export function createFetchTemplateAction(options: {
|
||||
renderContents
|
||||
? templater.renderString(inputFileContents, context)
|
||||
: inputFileContents,
|
||||
{ mode: statsObj.mode },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user