Merge pull request #5013 from backjo/feat/CustomRepoDir
feat: allow custom directory to be specified for github publish action
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': patch
|
||||
---
|
||||
|
||||
Allow custom directory to be specified for GitHub publish action
|
||||
@@ -19,7 +19,7 @@ import { ScmIntegrationRegistry } from '@backstage/integration';
|
||||
import { initRepoAndPush } from '../../../stages/publish/helpers';
|
||||
import { GitRepositoryCreateOptions } from 'azure-devops-node-api/interfaces/GitInterfaces';
|
||||
import { getPersonalAccessTokenHandler, WebApi } from 'azure-devops-node-api';
|
||||
import { parseRepoUrl } from './util';
|
||||
import { getRepoSourceDirectory, parseRepoUrl } from './util';
|
||||
import { createTemplateAction } from '../../createTemplateAction';
|
||||
|
||||
export function createPublishAzureAction(options: {
|
||||
@@ -30,6 +30,7 @@ export function createPublishAzureAction(options: {
|
||||
return createTemplateAction<{
|
||||
repoUrl: string;
|
||||
description?: string;
|
||||
sourcePath?: string;
|
||||
}>({
|
||||
id: 'publish:azure',
|
||||
description:
|
||||
@@ -47,6 +48,11 @@ export function createPublishAzureAction(options: {
|
||||
title: 'Repository Description',
|
||||
type: 'string',
|
||||
},
|
||||
sourcePath: {
|
||||
title:
|
||||
'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the respository.',
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
output: {
|
||||
@@ -112,7 +118,7 @@ export function createPublishAzureAction(options: {
|
||||
const repoContentsUrl = remoteUrl;
|
||||
|
||||
await initRepoAndPush({
|
||||
dir: ctx.workspacePath,
|
||||
dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
|
||||
remoteUrl,
|
||||
auth: {
|
||||
username: 'notempty',
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
ScmIntegrationRegistry,
|
||||
} from '@backstage/integration';
|
||||
import { initRepoAndPush } from '../../../stages/publish/helpers';
|
||||
import { parseRepoUrl } from './util';
|
||||
import { getRepoSourceDirectory, parseRepoUrl } from './util';
|
||||
import fetch from 'cross-fetch';
|
||||
import { createTemplateAction } from '../../createTemplateAction';
|
||||
|
||||
@@ -165,6 +165,7 @@ export function createPublishBitbucketAction(options: {
|
||||
repoUrl: string;
|
||||
description: string;
|
||||
repoVisibility: 'private' | 'public';
|
||||
sourcePath?: string;
|
||||
}>({
|
||||
id: 'publish:bitbucket',
|
||||
description:
|
||||
@@ -187,6 +188,11 @@ export function createPublishBitbucketAction(options: {
|
||||
type: 'string',
|
||||
enum: ['private', 'public'],
|
||||
},
|
||||
sourcePath: {
|
||||
title:
|
||||
'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the respository.',
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
output: {
|
||||
@@ -233,7 +239,7 @@ export function createPublishBitbucketAction(options: {
|
||||
});
|
||||
|
||||
await initRepoAndPush({
|
||||
dir: ctx.workspacePath,
|
||||
dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
|
||||
remoteUrl,
|
||||
auth: {
|
||||
username: integrationConfig.config.username
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { InputError } from '@backstage/errors';
|
||||
import {
|
||||
GithubCredentialsProvider,
|
||||
@@ -21,7 +20,7 @@ import {
|
||||
} from '@backstage/integration';
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { initRepoAndPush } from '../../../stages/publish/helpers';
|
||||
import { parseRepoUrl } from './util';
|
||||
import { getRepoSourceDirectory, parseRepoUrl } from './util';
|
||||
import { createTemplateAction } from '../../createTemplateAction';
|
||||
|
||||
export function createPublishGithubAction(options: {
|
||||
@@ -40,6 +39,7 @@ export function createPublishGithubAction(options: {
|
||||
repoUrl: string;
|
||||
description?: string;
|
||||
access?: string;
|
||||
sourcePath?: string;
|
||||
repoVisibility: 'private' | 'internal' | 'public';
|
||||
}>({
|
||||
id: 'publish:github',
|
||||
@@ -67,6 +67,11 @@ export function createPublishGithubAction(options: {
|
||||
type: 'string',
|
||||
enum: ['private', 'public', 'internal'],
|
||||
},
|
||||
sourcePath: {
|
||||
title:
|
||||
'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the respository.',
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
output: {
|
||||
@@ -164,7 +169,7 @@ export function createPublishGithubAction(options: {
|
||||
const repoContentsUrl = `${data.html_url}/blob/master`;
|
||||
|
||||
await initRepoAndPush({
|
||||
dir: ctx.workspacePath,
|
||||
dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
|
||||
remoteUrl,
|
||||
auth: {
|
||||
username: 'x-access-token',
|
||||
|
||||
@@ -18,7 +18,7 @@ import { InputError } from '@backstage/errors';
|
||||
import { ScmIntegrationRegistry } from '@backstage/integration';
|
||||
import { Gitlab } from '@gitbeaker/node';
|
||||
import { initRepoAndPush } from '../../../stages/publish/helpers';
|
||||
import { parseRepoUrl } from './util';
|
||||
import { getRepoSourceDirectory, parseRepoUrl } from './util';
|
||||
import { createTemplateAction } from '../../createTemplateAction';
|
||||
|
||||
export function createPublishGitlabAction(options: {
|
||||
@@ -29,6 +29,7 @@ export function createPublishGitlabAction(options: {
|
||||
return createTemplateAction<{
|
||||
repoUrl: string;
|
||||
repoVisibility: 'private' | 'internal' | 'public';
|
||||
sourcePath?: string;
|
||||
}>({
|
||||
id: 'publish:gitlab',
|
||||
description:
|
||||
@@ -47,6 +48,11 @@ export function createPublishGitlabAction(options: {
|
||||
type: 'string',
|
||||
enum: ['private', 'public', 'internal'],
|
||||
},
|
||||
sourcePath: {
|
||||
title:
|
||||
'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the respository.',
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
output: {
|
||||
@@ -106,7 +112,7 @@ export function createPublishGitlabAction(options: {
|
||||
const repoContentsUrl = `${remoteUrl}/-/blob/master`;
|
||||
|
||||
await initRepoAndPush({
|
||||
dir: ctx.workspacePath,
|
||||
dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
|
||||
remoteUrl: http_url_to_repo as string,
|
||||
auth: {
|
||||
username: 'oauth2',
|
||||
|
||||
@@ -15,6 +15,21 @@
|
||||
*/
|
||||
|
||||
import { InputError } from '@backstage/errors';
|
||||
import { join as joinPath, normalize as normalizePath } from 'path';
|
||||
|
||||
export const getRepoSourceDirectory = (
|
||||
workspacePath: string,
|
||||
sourcePath: string | undefined,
|
||||
) => {
|
||||
if (sourcePath) {
|
||||
const safeSuffix = normalizePath(sourcePath).replace(
|
||||
/^(\.\.(\/|\\|$))+/,
|
||||
'',
|
||||
);
|
||||
return joinPath(workspacePath, safeSuffix);
|
||||
}
|
||||
return workspacePath;
|
||||
};
|
||||
|
||||
export const parseRepoUrl = (repoUrl: string) => {
|
||||
let parsed;
|
||||
|
||||
Reference in New Issue
Block a user