Skip to content

Commit 76c73d9

Browse files
authored
chore(projen): enable backport and remove custom logic (#1203) (#1206)
A while back we added the [backport](cdk8s-team/cdk8s-projen-common#275) component to our common library, but didn't actually update the projects to use it. Do it now. We still need to do the same for the cli and cdk8s-plus. (cherry picked from commit 0afbe3a) Signed-off-by: Eli Polonsky <[email protected]> # Conflicts: # .projenrc.js
1 parent afc0b58 commit 76c73d9

File tree

6 files changed

+572
-146
lines changed

6 files changed

+572
-146
lines changed

.backportrc.json

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gitignore

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/tasks.json

+2-44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.js

+2-82
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const project = new Cdk8sTeamJsiiProject({
4040
},
4141
},
4242
golangBranch: '1.x',
43+
backport: true,
44+
backportBranches: ['1.x'],
4345
});
4446

4547
// _loadurl.js is written in javascript so we need to commit it and also copy it
@@ -63,88 +65,6 @@ docgenTask.exec('jsii-docgen -l typescript -o docs/typescript.md');
6365
docgenTask.exec('jsii-docgen -l python -o docs/python.md');
6466
docgenTask.exec('jsii-docgen -l java -o docs/java.md');
6567

66-
// run backport in clean directories every time.
67-
const backportHome = '/tmp/.backport/';
68-
const backportDir = `${backportHome}/repositories/cdk8s-team/cdk8s-core`;
69-
const backportConfig = new JsonFile(project, '.backportrc.json', {
70-
// see https://github.com/sqren/backport/blob/main/docs/config-file-options.md
71-
obj: {
72-
repoOwner: 'cdk8s-team',
73-
repoName: 'cdk8s-core',
74-
signoff: true,
75-
branchLabelMapping: {
76-
'^backport-to-(.+)$': '$1',
77-
},
78-
prTitle: '{commitMessages}',
79-
fork: false,
80-
publishStatusCommentOnFailure: true,
81-
publishStatusCommentOnSuccess: true,
82-
publishStatusCommentOnAbort: true,
83-
targetPRLabels: [project.autoApprove.label],
84-
dir: backportDir,
85-
},
86-
});
87-
88-
// backport task to branches based on pr labels
89-
const backportTask = createBackportTask();
90-
91-
// backport tasks to the explicit release branches
92-
for (const branch of project.release.branches) {
93-
createBackportTask(branch);
94-
}
95-
96-
const backportWorkflow = project.github.addWorkflow('backport');
97-
backportWorkflow.on({ pullRequestTarget: { types: ['closed'] } });
98-
backportWorkflow.addJob('backport', {
99-
runsOn: ['ubuntu-latest'],
100-
permissions: {
101-
contents: github.workflows.JobPermission.WRITE,
102-
},
103-
steps: [
104-
// needed in order to run the projen task as well
105-
// as use the backport configuration in the repo.
106-
{
107-
name: 'checkout',
108-
uses: 'actions/checkout@v3',
109-
with: {
110-
// required because we need the full history
111-
// for proper backports.
112-
'fetch-depth': 0,
113-
},
114-
},
115-
{
116-
name: 'Set Git Identity',
117-
run: 'git config --global user.name "github-actions" && git config --global user.email "[email protected]"',
118-
},
119-
{
120-
name: 'backport',
121-
if: 'github.event.pull_request.merged == true',
122-
run: `npx projen ${backportTask.name}`,
123-
env: {
124-
GITHUB_TOKEN: '${{ secrets.PROJEN_GITHUB_TOKEN }}',
125-
BACKPORT_PR_NUMBER: '${{ github.event.pull_request.number }}',
126-
},
127-
},
128-
],
129-
});
130-
131-
function createBackportTask(branch) {
132-
const name = branch ? `backport:${branch}` : 'backport';
133-
const task = project.addTask(name, { requiredEnv: ['BACKPORT_PR_NUMBER', 'GITHUB_TOKEN'] });
134-
task.exec(`rm -rf ${backportHome}`);
135-
task.exec(`mkdir -p ${backportHome}`);
136-
task.exec(`cp ${backportConfig.path} ${backportHome}`);
137-
138-
const command = ['npx', 'backport', '--accesstoken', '${GITHUB_TOKEN}', '--pr', '${BACKPORT_PR_NUMBER}'];
139-
if (branch) {
140-
command.push(...['--branch', branch]);
141-
} else {
142-
command.push('--non-interactive');
143-
}
144-
task.exec(command.join(' '), { cwd: backportHome });
145-
return task;
146-
}
147-
14868
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/64924
14969
project.package.addPackageResolutions('@types/[email protected]');
15070

package.json

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)