-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.projenrc.js
More file actions
414 lines (344 loc) · 14.3 KB
/
Copy path.projenrc.js
File metadata and controls
414 lines (344 loc) · 14.3 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/**
* Copyright (c) Suresh Veeragoni
* SPDX-License-Identifier: Apache-2.0
*/
const { CdktfProviderProject } = require("@cdktf/provider-project");
const project = new CdktfProviderProject({
author: 'Suresh Veeragoni',
authorAddress: 'github@veeragoni.com',
authorOrganization: false,
defaultReleaseBranch: 'main',
name: 'cdktf-provider-oci',
repositoryUrl: 'https://github.com/veeragoni/cdktf-provider-oci.git',
description: 'Prebuilt Oracle Cloud Infrastructure (OCI) Provider for Terraform CDK (cdktf)',
terraformProvider: 'oracle/oci@~> 7.19.0',
cdktfVersion: '^0.21.0',
constructsVersion: '^10.4.2',
minNodeVersion: '20.9.0',
typescriptVersion: '~5.8.0',
jsiiVersion: '~5.8.0',
// Only enable specific publishing targets
releaseToNpm: true,
publishToPypi: {
distName: 'cdktf-provider-oci',
module: 'cdktf_provider_oci',
},
// Explicitly disable unwanted targets
publishToMaven: false,
publishToNuget: false,
publishToGo: false,
keywords: [
'oci',
'oracle',
'oracle-cloud',
'oracle-cloud-infrastructure',
'cdk',
'cdktf',
'terraform',
'provider'
],
devDeps: [
'@cdktf/provider-project@^0.7.0',
'cdktf-cli@^0.21.0',
'dot-prop@^5.2.0',
],
isDeprecated: false,
// Configure release workflow to only build and publish Python and TypeScript
releaseToNpm: true,
workflowNodeVersion: '20.9.0',
// Environment variables for publishing
npmDistTag: 'latest',
npmRegistry: 'https://registry.npmjs.org/',
});
// Override compile script to increase memory limit for large provider
project.tasks.tryFind('compile').reset();
project.tasks.tryFind('compile').exec('node --max-old-space-size=8192 ./node_modules/.bin/jsii --silence-warnings=reserved-word');
// Mark generated src files as linguist-generated
project.gitattributes.addAttributes('/src/**', 'linguist-generated');
// Clean configuration for Python and TypeScript only
// Fix package.json and workflows after synthesis
project.postSynthesize = () => {
const fs = require('fs');
const { execSync } = require('child_process');
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
// Update author information
packageJson.author = {
name: 'Suresh Veeragoni',
email: 'github@veeragoni.com',
organization: false
};
// Update package name and repository
packageJson.name = 'cdktf-provider-oci';
packageJson.repository.url = 'https://github.com/veeragoni/cdktf-provider-oci.git';
// Only keep Python target in jsii (JavaScript is default)
packageJson.jsii.targets = {
python: packageJson.jsii.targets.python
};
// Remove unwanted package scripts
const unwantedScripts = ['package:dotnet', 'package:go', 'package:java'];
unwantedScripts.forEach(script => {
if (packageJson.scripts[script]) {
delete packageJson.scripts[script];
}
});
// Override compile script with increased memory limit
packageJson.scripts.compile = 'node --max-old-space-size=8192 ./node_modules/.bin/jsii --silence-warnings=reserved-word';
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2) + '\n');
// Copy custom README if it exists
const customReadmePath = 'README-CUSTOM.md';
const readmePath = 'README.md';
if (fs.existsSync(customReadmePath)) {
try {
fs.chmodSync(readmePath, 0o644);
} catch {}
const customContent = fs.readFileSync(customReadmePath, 'utf8');
fs.writeFileSync(readmePath, customContent);
} else if (fs.existsSync(readmePath)) {
try {
fs.chmodSync(readmePath, 0o600);
} catch {}
let readme = fs.readFileSync(readmePath, 'utf8');
// Add Usage examples after the PyPI section
const usageSection = `
## Usage
### TypeScript
\`\`\`ts
import { App, TerraformStack } from 'cdktf';
import { Construct } from 'constructs';
import { OciProvider } from 'cdktf-provider-oci/lib/provider';
import { CoreInstance } from 'cdktf-provider-oci/lib/core-instance';
class MyStack extends TerraformStack {
constructor(scope: Construct, id: string) {
super(scope, id);
new OciProvider(this, 'oci', {
region: 'us-ashburn-1',
});
new CoreInstance(this, 'example', {
compartmentId: 'ocid1.compartment.oc1..exampleuniqueID',
availabilityDomain: 'kIdk:US-ASHBURN-AD-1',
shape: 'VM.Standard.E4.Flex',
sourceDetails: {
sourceType: 'image',
imageId: 'ocid1.image.oc1..exampleuniqueID',
},
createVnicDetails: {
subnetId: 'ocid1.subnet.oc1..exampleuniqueID',
},
});
}
}
const app = new App();
new MyStack(app, 'oci-example');
app.synth();
\`\`\`
Install dependencies with \`npm install cdktf cdktf-provider-oci constructs\` before synthesizing.
### Python
\`\`\`python
from constructs import Construct
from cdktf import App, TerraformStack
from cdktf_provider_oci.provider import OciProvider
from cdktf_provider_oci.core_instance import CoreInstance
class MyStack(TerraformStack):
def __init__(self, scope: Construct, construct_id: str) -> None:
super().__init__(scope, construct_id)
OciProvider(self, "oci", region="us-ashburn-1")
CoreInstance(self, "example",
compartment_id="ocid1.compartment.oc1..exampleuniqueID",
availability_domain="kIdk:US-ASHBURN-AD-1",
shape="VM.Standard.E4.Flex",
source_details={
"source_type": "image",
"image_id": "ocid1.image.oc1..exampleuniqueID",
},
create_vnic_details={
"subnet_id": "ocid1.subnet.oc1..exampleuniqueID",
},
)
app = App()
MyStack(app, "oci-example")
app.synth()
\`\`\`
Install dependencies with \`pip install cdktf cdktf-provider-oci constructs\` before synthesizing.
`;
// Only insert Usage section if it doesn't already exist
if (readme.indexOf('## Usage') === -1 && readme.indexOf('## Configuration') === -1) {
const docsIndex = readme.indexOf('## Docs');
if (docsIndex !== -1) {
readme = readme.slice(0, docsIndex) + usageSection + '\n' + readme.slice(docsIndex);
}
}
fs.writeFileSync(readmePath, readme);
}
const issueConfigPath = '.github/ISSUE_TEMPLATE/config.yml';
if (fs.existsSync(issueConfigPath)) {
try {
fs.chmodSync(issueConfigPath, 0o600);
} catch {}
let issueConfig = fs.readFileSync(issueConfigPath, 'utf8');
issueConfig = issueConfig.replace(
/(url:\s*")[^"]+("?)/,
`$1https://github.com/veeragoni/cdktf-provider-oci/issues/new/choose$2`
);
issueConfig = issueConfig.replace(
/Please file issues with pre-built providers in our main repository\./,
'Report problems or request features for this provider directly in this repository.'
);
fs.writeFileSync(issueConfigPath, issueConfig);
}
const codeownersPath = '.github/CODEOWNERS';
if (fs.existsSync(codeownersPath)) {
try {
fs.chmodSync(codeownersPath, 0o600);
} catch {}
let codeowners = fs.readFileSync(codeownersPath, 'utf8');
codeowners = codeowners.replace(/\*\s+@.+/, '* @veeragoni');
fs.writeFileSync(codeownersPath, codeowners);
}
const shouldReleasePath = 'scripts/should-release.js';
if (fs.existsSync(shouldReleasePath)) {
try {
fs.chmodSync(shouldReleasePath, 0o600);
} catch {}
let shouldRelease = fs.readFileSync(shouldReleasePath, 'utf8');
let updated = false;
const originalBlock = /const thingsToDiff = \[\s*{\s*name: "Terraform provider version",\s*previous: prevPackageJson\.cdktf\.provider\.version,\s*current: currPackageJson\.cdktf\.provider\.version,\s*},\s*{\s*name: "cdktf peer dependency",\s*previous: prevPackageJson\.peerDependencies\.cdktf,\s*current: currPackageJson\.peerDependencies\.cdktf,\s*},\s*\];/s;
if (originalBlock.test(shouldRelease)) {
shouldRelease = shouldRelease.replace(
originalBlock,
`const prevProviderVersion =\n prevPackageJson?.cdktf?.provider?.version ?? "<missing>";\n const currProviderVersion =\n currPackageJson?.cdktf?.provider?.version ?? "<missing>";\n\n const prevPeerCdktf =\n prevPackageJson?.peerDependencies?.cdktf ?? "<missing>";\n const currPeerCdktf =\n currPackageJson?.peerDependencies?.cdktf ?? "<missing>";\n\n const thingsToDiff = [\n {\n name: "Terraform provider version",\n previous: prevProviderVersion,\n current: currProviderVersion,\n },\n {\n name: "cdktf peer dependency",\n previous: prevPeerCdktf,\n current: currPeerCdktf,\n },\n ];`
);
updated = true;
}
if (!shouldRelease.includes('FORCE_RELEASE flag detected; bypassing change detection.')) {
shouldRelease = shouldRelease.replace(
' // inspired by https://github.com/projen/projen/blob/08378c40d1453288053abcddce82475329b4506e/src/release/bump-version.ts#L281\n',
" const forceRelease = String(process.env.FORCE_RELEASE || '').toLowerCase();\n if (forceRelease === '1' || forceRelease === 'true') {\n console.log('FORCE_RELEASE flag detected; bypassing change detection.');\n return;\n }\n\n // inspired by https://github.com/projen/projen/blob/08378c40d1453288053abcddce82475329b4506e/src/release/bump-version.ts#L281\n"
);
updated = true;
}
if (updated) {
fs.writeFileSync(shouldReleasePath, shouldRelease);
}
}
// Fix the release workflow to remove unwanted jobs
const releaseWorkflowPath = '.github/workflows/release.yml';
if (fs.existsSync(releaseWorkflowPath)) {
// Make the file writable first
try {
execSync(`chmod +w "${releaseWorkflowPath}"`, { stdio: 'ignore' });
} catch {}
let releaseContent = fs.readFileSync(releaseWorkflowPath, 'utf8');
// Fix the deprecate job to use correct package name
releaseContent = releaseContent.replace(
'@cdktf/provider-oci',
'cdktf-provider-oci'
);
// Ensure npm publish jobs use a valid registry URL
releaseContent = releaseContent.replace(
/https\/\/https\/\/registry\.npmjs\.org\//g,
'https://registry.npmjs.org/'
);
releaseContent = releaseContent.replace(
/https\/\/registry\.npmjs\.org\//g,
'https://registry.npmjs.org/'
);
releaseContent = releaseContent.replace(
/NPM_REGISTRY: https:\/\/registry\.npmjs\.org\//g,
'NPM_REGISTRY: registry.npmjs.org'
);
releaseContent = releaseContent.replace(
'npm set "//$NPM_REGISTRY/:_authToken=$NPM_TOKEN"',
'REGISTRY_HOST=${NPM_REGISTRY#https://}\n REGISTRY_HOST=${REGISTRY_HOST#http://}\n REGISTRY_HOST=${REGISTRY_HOST%/}\n npm set "//$REGISTRY_HOST/:_authToken=$NPM_TOKEN"'
);
// Add a manual force release input and propagate environment variable
releaseContent = releaseContent.replace(
' workflow_dispatch: {}\n',
' workflow_dispatch:\n inputs:\n force:\n description: Force release even if versions unchanged\n required: false\n default: "false"\n'
);
releaseContent = releaseContent.replace(
' env:\n CI: "true"\n',
" env:\n CI: \"true\"\n FORCE_RELEASE: ${{ github.event.inputs.force || 'false' }}\n"
);
// Remove unwanted release jobs by finding their sections and removing them
const jobsToRemove = ['release_maven', 'release_nuget', 'release_golang'];
jobsToRemove.forEach(jobName => {
// Find the job section and remove everything until the next job or end of file
const jobRegex = new RegExp(` ${jobName}:[\\s\\S]*?(?=\\n [a-z_]+:|$)`, 'g');
releaseContent = releaseContent.replace(jobRegex, '');
});
// Also remove these jobs from the deprecate job dependencies
releaseContent = releaseContent.replace(
/needs:\s*\[\s*-\s*release\s*-\s*release_npm\s*\]/,
'needs:\n - release\n - release_npm'
);
fs.writeFileSync(releaseWorkflowPath, releaseContent);
}
// Remove unused workflows
const unusedWorkflows = [
'alert-open-prs.yml',
'auto-close-community-issues.yml',
'auto-close-community-prs.yml',
'fix-jest.sh',
'force-release.yml',
'lock.yml',
'stale.yml'
];
unusedWorkflows.forEach(workflow => {
const workflowPath = `.github/workflows/${workflow}`;
if (fs.existsSync(workflowPath)) {
fs.unlinkSync(workflowPath);
}
});
try {
execSync('node scripts/generate-index.cjs', { stdio: 'inherit' });
} catch (error) {
console.warn('Warning: failed to regenerate src/index.ts during post-synthesize.', error);
}
};
project.addScripts({
'check-if-new-provider-version': 'node scripts/check-for-upgrades.js',
'fetch': 'npx projen fetch',
'commit': 'git add -A && git commit -am "Update provider" || echo "No changes to commit"',
'should-release': 'node scripts/should-release.js',
'prebump': 'yarn fetch && yarn compile && yarn run commit && yarn run should-release',
'build-provider': 'yarn fetch && yarn compile && yarn docgen',
'generate:index': 'node scripts/generate-index.cjs',
});
const generateIndexTask = project.addTask('generate-index', {
exec: 'node scripts/generate-index.cjs',
});
const fetchTask = project.tasks.tryFind('fetch');
fetchTask?.exec('node scripts/generate-index.cjs');
const preCompileTask = project.tasks.tryFind('pre-compile');
preCompileTask?.prependExec('node scripts/generate-index.cjs');
const docgenTask = project.tasks.tryFind('docgen');
if (!docgenTask) {
console.warn('Warning: docgen task not found; docs languages not adjusted.');
} else {
docgenTask.reset();
docgenTask.exec('node scripts/generate-docs.cjs');
console.log('Customized docgen task to generate TypeScript/Python docs only.');
}
const packageAllTask = project.tasks.tryFind('package-all');
if (!packageAllTask) {
console.warn('Warning: package-all task not found; skipping language pruning.');
} else {
packageAllTask.reset();
const packageJsTask = project.tasks.tryFind('package:js');
if (packageJsTask) {
packageAllTask.spawn(packageJsTask);
}
const packagePythonTask = project.tasks.tryFind('package:python');
if (packagePythonTask) {
packageAllTask.spawn(packagePythonTask);
}
console.log('Restricted package-all task to js/python targets.');
}
['package:java', 'package:dotnet', 'package:go'].forEach(taskName => {
const removed = project.removeTask(taskName);
if (removed) {
console.log(`Removed task: ${taskName}`);
}
});
// CdktfProviderProject already includes the necessary workflows
project.synth();