From 423a514c3b230fcdb7c68d4985fd2a5bc27ba217 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 13 Apr 2021 13:29:46 +0200 Subject: [PATCH] scaffolder-backend: fix GitHub Pull Request preparer on windows Signed-off-by: Patrik Oldsberg --- .changeset/thick-frogs-hang.md | 5 +++++ .../builtin/publish/githubPullRequest.test.ts | 17 ++++++++++------- .../builtin/publish/githubPullRequest.ts | 16 ++++++++++------ 3 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 .changeset/thick-frogs-hang.md diff --git a/.changeset/thick-frogs-hang.md b/.changeset/thick-frogs-hang.md new file mode 100644 index 0000000000..44add55206 --- /dev/null +++ b/.changeset/thick-frogs-hang.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': patch +--- + +Fix execution of the GitHub Pull Request publish action on Windows. diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.test.ts index fb9d3aeaa6..3b17f46bb3 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.test.ts @@ -16,6 +16,8 @@ import mockFs from 'mock-fs'; import { Writable } from 'stream'; +import os from 'os'; +import { resolve as resolvePath } from 'path'; import { PullRequestCreator, GithubPullRequestActionInput, @@ -28,7 +30,8 @@ import { getRootLogger } from '@backstage/backend-common'; import { ScmIntegrations } from '@backstage/integration'; import { ConfigReader } from '@backstage/config'; -const id = 'createPublishGithubPullRequestAction'; +const root = os.platform() === 'win32' ? 'C:\\root' : '/root'; +const workspacePath = resolvePath(root, 'my-workspace'); describe('createPublishGithubPullRequestAction', () => { let instance: TemplateAction; @@ -72,7 +75,7 @@ describe('createPublishGithubPullRequestAction', () => { }; mockFs({ - [id]: { 'file.txt': 'Hello there!' }, + [workspacePath]: { 'file.txt': 'Hello there!' }, }); ctx = { @@ -81,7 +84,7 @@ describe('createPublishGithubPullRequestAction', () => { logger: getRootLogger(), logStream: new Writable(), input, - workspacePath: id, + workspacePath, }; }); it('creates a pull request', async () => { @@ -133,7 +136,7 @@ describe('createPublishGithubPullRequestAction', () => { }; mockFs({ - [id]: { + [workspacePath]: { source: { 'foo.txt': 'Hello there!' }, irrelevant: { 'bar.txt': 'Nothing to see here' }, }, @@ -145,7 +148,7 @@ describe('createPublishGithubPullRequestAction', () => { logger: getRootLogger(), logStream: new Writable(), input, - workspacePath: id, + workspacePath, }; }); @@ -188,7 +191,7 @@ describe('createPublishGithubPullRequestAction', () => { }; mockFs({ - [id]: { 'file.txt': 'Hello there!' }, + [workspacePath]: { 'file.txt': 'Hello there!' }, }); ctx = { @@ -197,7 +200,7 @@ describe('createPublishGithubPullRequestAction', () => { logger: getRootLogger(), logStream: new Writable(), input, - workspacePath: id, + workspacePath, }; }); it('creates a pull request', async () => { diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts index 3a00610a92..e2e4f17efb 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts @@ -197,17 +197,21 @@ export const createPublishGithubPullRequestAction = ({ const client = await clientFactory({ integrations, host, owner, repo }); const fileRoot = sourcePath - ? path.join(ctx.workspacePath, sourcePath) + ? path.resolve(ctx.workspacePath, sourcePath) : ctx.workspacePath; - const localFilePaths = await globby(`${fileRoot}/**/*.*`); + + const localFilePaths = await globby(['./**', './**/.*', '!.git'], { + cwd: fileRoot, + gitignore: true, + dot: true, + }); const fileContents = await Promise.all( - localFilePaths.map(p => readFile(p)), + localFilePaths.map(p => readFile(path.resolve(fileRoot, p))), ); - const repoFilePaths = localFilePaths.map(p => { - const relativePath = path.relative(fileRoot, p); - return targetPath ? `${targetPath}/${relativePath}` : relativePath; + const repoFilePaths = localFilePaths.map(repoFilePath => { + return targetPath ? `${targetPath}/${repoFilePath}` : repoFilePath; }); const changes = [