Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support tag based policies #25333

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/short-flowers-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend-module-github': minor
---

Adds support for custom tag policies when creating GitHub environments.
1 change: 1 addition & 0 deletions plugins/scaffolder-backend-module-github/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function createGithubEnvironmentAction(options: {
}
| undefined;
customBranchPolicyNames?: string[] | undefined;
customTagPolicyNames?: string[] | undefined;
environmentVariables?:
| {
[key: string]: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ describe('github:environment:create examples', () => {
repo: 'repository',
environment_name: 'envname',
name: 'main',
type: 'branch',
});

expect(
Expand All @@ -180,6 +181,7 @@ describe('github:environment:create examples', () => {
repo: 'repository',
environment_name: 'envname',
name: '*.*.*',
type: 'branch',
});

expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('github:environment:create', () => {
},
});
});

it('should work specify deploymentBranchPolicy custom', async () => {
await action.handler({
...mockContext,
Expand Down Expand Up @@ -153,6 +154,52 @@ describe('github:environment:create', () => {
repo: 'repository',
environment_name: 'envname',
name: 'main',
type: 'branch',
});
expect(
mockOctokit.rest.repos.createDeploymentBranchPolicy,
).toHaveBeenCalledWith({
owner: 'owner',
repo: 'repository',
environment_name: 'envname',
name: '*.*.*',
type: 'branch',
});
});

it('should work specify deploymentTagPolicy custom', async () => {
await action.handler({
...mockContext,
input: {
...mockContext.input,
deploymentBranchPolicy: {
protected_branches: false,
custom_branch_policies: true,
},
customTagPolicyNames: ['main', '*.*.*'],
},
});

expect(
mockOctokit.rest.repos.createOrUpdateEnvironment,
).toHaveBeenCalledWith({
owner: 'owner',
repo: 'repository',
environment_name: 'envname',
deployment_branch_policy: {
protected_branches: false,
custom_branch_policies: true,
},
});

expect(
mockOctokit.rest.repos.createDeploymentBranchPolicy,
).toHaveBeenCalledWith({
owner: 'owner',
repo: 'repository',
environment_name: 'envname',
name: 'main',
type: 'tag',
});
expect(
mockOctokit.rest.repos.createDeploymentBranchPolicy,
Expand All @@ -161,6 +208,7 @@ describe('github:environment:create', () => {
repo: 'repository',
environment_name: 'envname',
name: '*.*.*',
type: 'tag',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function createGithubEnvironmentAction(options: {
custom_branch_policies: boolean;
};
customBranchPolicyNames?: string[];
customTagPolicyNames?: string[];
environmentVariables?: { [key: string]: string };
secrets?: { [key: string]: string };
token?: string;
Expand Down Expand Up @@ -94,6 +95,16 @@ export function createGithubEnvironmentAction(options: {
type: 'string',
},
},
customTagPolicyNames: {
title: 'Custom Tag Policy Name',
description: `The name pattern that tags must match in order to deploy to the environment.

Wildcard characters will not match /. For example, to match tags that begin with release/ and contain an additional single slash, use release/*/*. For more information about pattern matching syntax, see the Ruby File.fnmatch documentation.`,
type: 'array',
items: {
type: 'string',
},
},
environmentVariables: {
title: 'Environment Variables',
description: `Environment variables attached to the deployment environment`,
Expand All @@ -118,6 +129,7 @@ export function createGithubEnvironmentAction(options: {
name,
deploymentBranchPolicy,
customBranchPolicyNames,
customTagPolicyNames,
environmentVariables,
secrets,
token: providedToken,
Expand Down Expand Up @@ -153,6 +165,19 @@ export function createGithubEnvironmentAction(options: {
await client.rest.repos.createDeploymentBranchPolicy({
owner: owner,
repo: repo,
type: 'branch',
environment_name: name,
name: item,
});
}
}

if (customTagPolicyNames) {
for (const item of customTagPolicyNames) {
await client.rest.repos.createDeploymentBranchPolicy({
owner: owner,
repo: repo,
type: 'tag',
environment_name: name,
name: item,
});
Expand Down
Loading