diff --git a/.changeset/smooth-moons-bake.md b/.changeset/smooth-moons-bake.md new file mode 100644 index 0000000000..e9c0cf7ba7 --- /dev/null +++ b/.changeset/smooth-moons-bake.md @@ -0,0 +1,21 @@ +--- +'@backstage/plugin-scaffolder-backend-module-github': minor +'@backstage/create-app': patch +--- + +**BREAKING** The `publish:github` scaffolder action now defaults to initializing with a branch named "main" instead of "master" when creating new repositories. + +If you or your organization have relied on all new github repositories having a default branch name of "master" you **must** set the `defaultBranch: 'master'` in your existing templates that feature the `publish:github` scaffolder action. + +To keep using the name "master" for your new github repos, these are the **required** changes: + +```diff + - id: publish + name: Publish + action: publish:github + input: + allowedHosts: ['github.com'] + description: This is ${{ parameters.name }} + repoUrl: ${{ parameters.repoUrl }} ++ defaultBranch: 'master' +``` diff --git a/docs/features/software-templates/adding-templates.md b/docs/features/software-templates/adding-templates.md index 083516192c..674ee8788b 100644 --- a/docs/features/software-templates/adding-templates.md +++ b/docs/features/software-templates/adding-templates.md @@ -71,6 +71,7 @@ spec: allowedHosts: ['github.com'] description: This is ${{ parameters.name }} repoUrl: ${{ parameters.repoUrl }} + defaultBranch: 'main' - id: register name: Register diff --git a/docs/features/software-templates/writing-templates.md b/docs/features/software-templates/writing-templates.md index bc2847a81b..4abe8f1eb0 100644 --- a/docs/features/software-templates/writing-templates.md +++ b/docs/features/software-templates/writing-templates.md @@ -83,6 +83,7 @@ spec: allowedHosts: ['github.com'] description: This is ${{ parameters.name }} repoUrl: ${{ parameters.repoUrl }} + defaultBranch: 'main' - id: register name: Register diff --git a/packages/create-app/templates/default-app/examples/template/template.yaml b/packages/create-app/templates/default-app/examples/template/template.yaml index 33f262b49c..cfba98e878 100644 --- a/packages/create-app/templates/default-app/examples/template/template.yaml +++ b/packages/create-app/templates/default-app/examples/template/template.yaml @@ -48,6 +48,8 @@ spec: name: ${{ parameters.name }} # This step publishes the contents of the working directory to GitHub. + # If you or your organization prefer another default branch name over 'main' + # you can change that here. - id: publish name: Publish action: publish:github @@ -55,6 +57,7 @@ spec: allowedHosts: ['github.com'] description: This is ${{ parameters.name }} repoUrl: ${{ parameters.repoUrl }} + defaultBranch: 'main' # The final step is to register our new component in the catalog. - id: register diff --git a/plugins/scaffolder-backend-module-github/src/actions/github.examples.test.ts b/plugins/scaffolder-backend-module-github/src/actions/github.examples.test.ts index 6a6c6daf13..3c7f27f572 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/github.examples.test.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/github.examples.test.ts @@ -155,7 +155,7 @@ describe('publish:github', () => { expect(initRepoAndPush).toHaveBeenCalledWith({ dir: mockContext.workspacePath, remoteUrl: 'https://github.com/clone/url.git', - defaultBranch: 'master', + defaultBranch: 'main', auth: { username: 'x-access-token', password: 'tokenlols' }, logger: mockContext.logger, commitMessage: 'initial commit', diff --git a/plugins/scaffolder-backend-module-github/src/actions/github.test.ts b/plugins/scaffolder-backend-module-github/src/actions/github.test.ts index 30945d92f2..d7e74f1b9c 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/github.test.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/github.test.ts @@ -534,7 +534,7 @@ describe('publish:github', () => { expect(initRepoAndPush).toHaveBeenCalledWith({ dir: mockContext.workspacePath, remoteUrl: 'https://github.com/clone/url.git', - defaultBranch: 'master', + defaultBranch: 'main', auth: { username: 'x-access-token', password: 'tokenlols' }, logger: mockContext.logger, commitMessage: 'initial commit', @@ -613,7 +613,7 @@ describe('publish:github', () => { expect(initRepoAndPush).toHaveBeenCalledWith({ dir: mockContext.workspacePath, remoteUrl: 'https://github.com/clone/url.git', - defaultBranch: 'master', + defaultBranch: 'main', auth: { username: 'x-access-token', password: 'tokenlols' }, logger: mockContext.logger, commitMessage: 'initial commit', @@ -658,7 +658,7 @@ describe('publish:github', () => { expect(initRepoAndPush).toHaveBeenCalledWith({ dir: mockContext.workspacePath, remoteUrl: 'https://github.com/clone/url.git', - defaultBranch: 'master', + defaultBranch: 'main', auth: { username: 'x-access-token', password: 'tokenlols' }, logger: mockContext.logger, commitMessage: 'Test commit message', @@ -1079,7 +1079,7 @@ describe('publish:github', () => { ); expect(mockContext.output).toHaveBeenCalledWith( 'repoContentsUrl', - 'https://github.com/html/url/blob/master', + 'https://github.com/html/url/blob/main', ); }); @@ -1131,7 +1131,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: undefined, requiredApprovingReviewCount: 1, @@ -1161,7 +1161,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: undefined, requiredApprovingReviewCount: 1, @@ -1190,7 +1190,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: undefined, requiredApprovingReviewCount: 1, @@ -1218,7 +1218,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: undefined, requiredApprovingReviewCount: 1, @@ -1307,7 +1307,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: undefined, requiredApprovingReviewCount: 1, @@ -1338,7 +1338,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: undefined, requiredApprovingReviewCount: 1, @@ -1372,7 +1372,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: undefined, requiredApprovingReviewCount: 1, @@ -1407,7 +1407,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: undefined, requiredApprovingReviewCount: 1, @@ -1443,7 +1443,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: undefined, requiredApprovingReviewCount: 1, @@ -1479,7 +1479,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: undefined, requiredApprovingReviewCount: 1, @@ -1516,7 +1516,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: undefined, requiredApprovingReviewCount: 1, @@ -1546,7 +1546,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: { users: ['user'], @@ -1578,7 +1578,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: { teams: ['team'], @@ -1610,7 +1610,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: { apps: ['app'], @@ -1644,7 +1644,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: { users: ['user'], @@ -1680,7 +1680,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: { users: ['user1', 'user2'], @@ -1767,7 +1767,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: undefined, requiredApprovingReviewCount: 1, @@ -1796,7 +1796,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: undefined, requiredApprovingReviewCount: 1, @@ -1825,7 +1825,7 @@ describe('publish:github', () => { client: mockOctokit, repoName: 'repo', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, bypassPullRequestAllowances: undefined, requiredApprovingReviewCount: 1, diff --git a/plugins/scaffolder-backend-module-github/src/actions/github.ts b/plugins/scaffolder-backend-module-github/src/actions/github.ts index fd858f0830..fefa2ea780 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/github.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/github.ts @@ -199,7 +199,7 @@ export function createPublishGithubAction(options: { requiredConversationResolution = false, requireLastPushApproval = false, repoVisibility = 'private', - defaultBranch = 'master', + defaultBranch = 'main', protectDefaultBranch = true, protectEnforceAdmins = true, deleteBranchOnMerge = false, diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.examples.test.ts b/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.examples.test.ts index e9cc9d95de..6570ce8f4b 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.examples.test.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.examples.test.ts @@ -114,7 +114,7 @@ describe('github:repo:push examples', () => { expect(initRepoAndPush).toHaveBeenCalledWith({ dir: mockContext.workspacePath, remoteUrl: 'https://github.com/clone/url.git', - defaultBranch: 'master', + defaultBranch: 'main', auth: { username: 'x-access-token', password: 'tokenlols' }, logger: mockContext.logger, commitMessage: 'initial commit', diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.test.ts b/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.test.ts index 7fdf2e1af6..a3b2478ce6 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.test.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.test.ts @@ -117,7 +117,7 @@ describe('github:repo:push', () => { expect(initRepoAndPush).toHaveBeenCalledWith({ dir: mockContext.workspacePath, remoteUrl: 'https://github.com/clone/url.git', - defaultBranch: 'master', + defaultBranch: 'main', auth: { username: 'x-access-token', password: 'tokenlols' }, logger: mockContext.logger, commitMessage: 'initial commit', @@ -188,7 +188,7 @@ describe('github:repo:push', () => { expect(initRepoAndPush).toHaveBeenCalledWith({ dir: mockContext.workspacePath, remoteUrl: 'https://github.com/clone/url.git', - defaultBranch: 'master', + defaultBranch: 'main', auth: { username: 'x-access-token', password: 'tokenlols' }, logger: mockContext.logger, commitMessage: 'initial commit', @@ -229,7 +229,7 @@ describe('github:repo:push', () => { expect(initRepoAndPush).toHaveBeenCalledWith({ dir: mockContext.workspacePath, remoteUrl: 'https://github.com/clone/url.git', - defaultBranch: 'master', + defaultBranch: 'main', auth: { username: 'x-access-token', password: 'tokenlols' }, logger: mockContext.logger, commitMessage: 'initial commit', @@ -253,7 +253,7 @@ describe('github:repo:push', () => { ); expect(mockContext.output).toHaveBeenCalledWith( 'repoContentsUrl', - 'https://github.com/html/url/blob/master', + 'https://github.com/html/url/blob/main', ); }); @@ -298,7 +298,7 @@ describe('github:repo:push', () => { client: mockOctokit, repoName: 'repository', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, requiredStatusCheckContexts: [], requireBranchesToBeUpToDate: true, @@ -327,7 +327,7 @@ describe('github:repo:push', () => { client: mockOctokit, repoName: 'repository', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, requiredStatusCheckContexts: ['statusCheck'], requireBranchesToBeUpToDate: true, @@ -356,7 +356,7 @@ describe('github:repo:push', () => { client: mockOctokit, repoName: 'repository', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, requiredStatusCheckContexts: ['statusCheck'], requireBranchesToBeUpToDate: false, @@ -385,7 +385,7 @@ describe('github:repo:push', () => { client: mockOctokit, repoName: 'repository', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, requiredStatusCheckContexts: [], requireBranchesToBeUpToDate: true, @@ -484,7 +484,7 @@ describe('github:repo:push', () => { client: mockOctokit, repoName: 'repository', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, requiredStatusCheckContexts: [], requireBranchesToBeUpToDate: true, @@ -513,7 +513,7 @@ describe('github:repo:push', () => { client: mockOctokit, repoName: 'repository', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, requiredStatusCheckContexts: [], requireBranchesToBeUpToDate: true, @@ -542,7 +542,7 @@ describe('github:repo:push', () => { client: mockOctokit, repoName: 'repository', logger: mockContext.logger, - defaultBranch: 'master', + defaultBranch: 'main', requireCodeOwnerReviews: false, requiredStatusCheckContexts: [], requireBranchesToBeUpToDate: true, diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.ts b/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.ts index 1923a0bd35..f74ce33865 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.ts @@ -123,7 +123,7 @@ export function createGithubRepoPushAction(options: { async handler(ctx) { const { repoUrl, - defaultBranch = 'master', + defaultBranch = 'main', protectDefaultBranch = true, protectEnforceAdmins = true, gitCommitMessage = 'initial commit',