forked from cdk8s-team/cdk8s-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.projenrc.js
153 lines (136 loc) · 4.46 KB
/
.projenrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const { Cdk8sTeamJsiiProject } = require('@cdk8s/projen-common');
const { JsonFile, github } = require('projen');
const project = new Cdk8sTeamJsiiProject({
name: 'cdk8s',
repoName: 'cdk8s-core',
description: 'This is the core library of Cloud Development Kit (CDK) for Kubernetes (cdk8s). cdk8s apps synthesize into standard Kubernetes manifests which can be applied to any Kubernetes cluster.',
projenUpgradeSecret: 'PROJEN_GITHUB_TOKEN',
peerDeps: [
'constructs@^10',
],
bundledDeps: [
'follow-redirects',
'fast-json-patch',
],
devDeps: [
'constructs',
'@types/follow-redirects',
'json-schema-to-typescript',
'@cdk8s/projen-common',
],
keywords: [
'cdk',
'kubernetes',
'k8s',
'constructs',
'containers',
'configuration',
'microservices',
],
defaultReleaseBranch: '2.x',
majorVersion: 2,
releaseBranches: {
'1.x': {
majorVersion: 1,
npmDistTag: 'latest-1',
},
},
golangBranch: '2.x',
depsUpgradeOptions: {
exclude: ['yaml'],
},
});
// _loadurl.js is written in javascript so we need to commit it and also copy it
// after compilation to the `lib/` directory.
project.gitignore.include('/src/_loadurl.js');
project.compileTask.exec('cp src/_loadurl.js lib/');
const installHelm = project.addTask('install-helm', {
exec: 'curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash',
description: 'Install helm3',
// will exit with non-zero if helm is not installed or has the wrong version
condition: '! (helm version | grep "v3.")',
});
project.testTask.prependSpawn(installHelm);
const docgenTask = project.tasks.tryFind('docgen');
docgenTask.reset();
docgenTask.exec('jsii-docgen -l typescript -o docs/typescript.md');
docgenTask.exec('jsii-docgen -l python -o docs/python.md');
docgenTask.exec('jsii-docgen -l java -o docs/java.md');
// run backport in clean directories every time.
const backportHome = '/tmp/.backport/';
const backportDir = `${backportHome}/repositories/cdk8s-team/cdk8s-core`;
const backportConfig = new JsonFile(project, '.backportrc.json', {
// see https://github.com/sqren/backport/blob/main/docs/config-file-options.md
obj: {
repoOwner: 'cdk8s-team',
repoName: 'cdk8s-core',
signoff: true,
branchLabelMapping: {
'^backport-to-(.+)$': '$1',
},
prTitle: '{commitMessages}',
fork: false,
publishStatusCommentOnFailure: true,
publishStatusCommentOnSuccess: true,
publishStatusCommentOnAbort: true,
targetPRLabels: [project.autoApprove.label],
dir: backportDir,
},
});
// backport task to branches based on pr labels
const backportTask = createBackportTask();
// backport tasks to the explicit release branches
for (const branch of project.release.branches) {
createBackportTask(branch);
}
const backportWorkflow = project.github.addWorkflow('backport');
backportWorkflow.on({ pullRequestTarget: { types: ['closed'] } });
backportWorkflow.addJob('backport', {
runsOn: ['ubuntu-latest'],
permissions: {
contents: github.workflows.JobPermission.WRITE,
},
steps: [
// needed in order to run the projen task as well
// as use the backport configuration in the repo.
{
name: 'checkout',
uses: 'actions/checkout@v3',
with: {
// required because we need the full history
// for proper backports.
'fetch-depth': 0,
},
},
{
name: 'Set Git Identity',
run: 'git config --global user.name "github-actions" && git config --global user.email "[email protected]"',
},
{
name: 'backport',
if: 'github.event.pull_request.merged == true',
run: `npx projen ${backportTask.name}`,
env: {
GITHUB_TOKEN: '${{ secrets.PROJEN_GITHUB_TOKEN }}',
BACKPORT_PR_NUMBER: '${{ github.event.pull_request.number }}',
},
},
],
});
function createBackportTask(branch) {
const name = branch ? `backport:${branch}` : 'backport';
const task = project.addTask(name, { requiredEnv: ['BACKPORT_PR_NUMBER', 'GITHUB_TOKEN'] });
task.exec(`rm -rf ${backportHome}`);
task.exec(`mkdir -p ${backportHome}`);
task.exec(`cp ${backportConfig.path} ${backportHome}`);
const command = ['npx', 'backport', '--accesstoken', '${GITHUB_TOKEN}', '--pr', '${BACKPORT_PR_NUMBER}'];
if (branch) {
command.push(...['--branch', branch]);
} else {
command.push('--non-interactive');
}
task.exec(command.join(' '), { cwd: backportHome });
return task;
}
project.synth();