forked from cdk8s-team/cdk8s-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.projenrc.ts
176 lines (157 loc) · 4.71 KB
/
.projenrc.ts
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { Cdk8sTeamTypeScriptProject } from '@cdk8s/projen-common';
import { github, JsonFile, DependencyType } from 'projen';
import { addIntegTests } from './projenrc/integ';
const project = new Cdk8sTeamTypeScriptProject({
projenrcTs: true,
release: true,
name: 'cdk8s-cli',
description: 'This is the command line tool for Cloud Development Kit (CDK) for Kubernetes (cdk8s).',
// no need, we are configuring explicit exports.
entrypoint: '',
keywords: [
'k8s',
'cdk8s',
'kubernetes',
'cli',
'tools',
'automation',
'containers',
],
workflowBootstrapSteps: [{ run: 'pip3 install pipenv' }],
defaultReleaseBranch: '2.x',
majorVersion: 2,
releaseBranches: {
'1.x': {
majorVersion: 1,
npmDistTag: 'latest-1',
},
},
bin: {
cdk8s: 'bin/cdk8s',
},
deps: [
'cdk8s',
'cdk8s-plus-25',
'codemaker',
'constructs',
'fs-extra@^8',
'jsii-srcmak',
'jsii-pacmak',
'sscaff',
'yaml',
'yargs@^15',
'json2jsii',
'colors',
'ajv',
'table',
'semver',
],
devDeps: [
'@cdk8s/projen-common',
'@types/fs-extra@^8',
'@types/json-schema',
'@types/semver',
'glob',
'@types/glob',
'typescript-json-schema',
],
});
project.tsconfig?.addInclude('src/schemas/*.json');
project.tsconfigDev.addInclude('src/schemas/*.json');
//
// see https://nodejs.org/api/packages.html#exports
project.addFields({
exports: {
'./plugins': './lib/plugins/index.js',
'./package.json': './package.json',
},
});
// ignore integration tests since they need to executed after packaging
// and are defined in a separate tasks.
project.jest?.addIgnorePattern('/test/integ/');
project.gitignore.exclude('.vscode/');
// add @types/node as a regular dependency since it's needed to during "import"
// to compile the generated jsii code.
project.deps.removeDependency('@types/node', DependencyType.BUILD);
project.deps.addDependency('@types/node@^14', DependencyType.RUNTIME);
const schemas = project.addTask('schemas');
schemas.exec('ts-node scripts/crd.schema.ts');
project.compileTask.spawn(schemas);
// run backport in clean directories every time.
const backportHome = '/tmp/.backport/';
const backportDir = `${backportHome}/repositories/cdk8s-team/cdk8s-cli`;
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-cli',
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-18.04'],
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 "github-actions@github.com"',
},
{
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?: string) {
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;
}
addIntegTests(project);
project.synth();