Skip to content

Commit 273cd1d

Browse files
lantolioarbusi
andauthored
chore: Detects if L1 constructs are not up-to-date (#335)
Co-authored-by: Oriol Arbusi <[email protected]>
1 parent 1707268 commit 273cd1d

File tree

40 files changed

+597
-642
lines changed

40 files changed

+597
-642
lines changed

.github/workflows/code-health.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,38 @@ jobs:
5050
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
5151
- name: Run ShellCheck
5252
uses: bewuethr/shellcheck-action@d01912909579c4b1a335828b8fca197fbb8e0aa4
53+
check-l1-updated:
54+
runs-on: ubuntu-latest
55+
permissions:
56+
contents: write
57+
steps:
58+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
59+
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
60+
with:
61+
node-version: 18.x
62+
- run: yarn install --check-files
63+
- run: npm install -g cdk-import
64+
- run: ./scripts/cdk-all.sh
65+
- run: npx projen build
66+
- name: Find mutations
67+
id: self_mutation
68+
run: |-
69+
git add .
70+
git diff --staged --patch --exit-code > .repo.patch || echo "self_mutation_happened=true" >> "${GITHUB_OUTPUT}"
71+
- name: Upload patch
72+
if: steps.self_mutation.outputs.self_mutation_happened
73+
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
74+
with:
75+
name: .repo.patch
76+
path: .repo.patch
77+
- name: Fail build on mutation
78+
if: steps.self_mutation.outputs.self_mutation_happened
79+
run: |-
80+
echo "::error::Files were changed during build (see build log). If this was triggered from a fork, you will need to update your branch."
81+
cat .repo.patch
82+
exit 1
5383
call-package-workflow:
54-
needs: [compile, lint, shellcheck]
84+
needs: [compile, lint, shellcheck, check-l1-updated]
5585
secrets: inherit
5686
permissions:
5787
contents: write

.github/workflows/package.yml

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ on:
55
jobs:
66
build:
77
runs-on: ubuntu-latest
8-
permissions:
9-
contents: write
10-
outputs:
11-
self_mutation_happened: ${{ steps.self_mutation.outputs.self_mutation_happened }}
12-
env:
13-
CI: "true"
8+
permissions: {}
149
steps:
1510
- name: Checkout
1611
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
@@ -25,23 +20,6 @@ jobs:
2520
run: yarn install --check-files
2621
- name: build
2722
run: npx projen build
28-
- name: Find mutations
29-
id: self_mutation
30-
run: |-
31-
git add .
32-
git diff --staged --patch --exit-code > .repo.patch || echo "self_mutation_happened=true" >> "${GITHUB_OUTPUT}"
33-
- name: Upload patch
34-
if: steps.self_mutation.outputs.self_mutation_happened
35-
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
36-
with:
37-
name: .repo.patch
38-
path: .repo.patch
39-
- name: Fail build on mutation
40-
if: steps.self_mutation.outputs.self_mutation_happened
41-
run: |-
42-
echo "::error::Files were changed during build (see build log). If this was triggered from a fork, you will need to update your branch."
43-
cat .repo.patch
44-
exit 1
4523
- name: Backup artifact permissions
4624
run: cd dist && getfacl -R . > permissions-backup.acl
4725
continue-on-error: true
@@ -54,7 +32,6 @@ jobs:
5432
needs: build
5533
runs-on: ubuntu-latest
5634
permissions: {}
57-
if: "! needs.build.outputs.self_mutation_happened"
5835
steps:
5936
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
6037
with:
@@ -77,7 +54,6 @@ jobs:
7754
needs: build
7855
runs-on: ubuntu-latest
7956
permissions: {}
80-
if: "! needs.build.outputs.self_mutation_happened"
8157
steps:
8258
- uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9
8359
with:
@@ -104,7 +80,6 @@ jobs:
10480
needs: build
10581
runs-on: ubuntu-latest
10682
permissions: {}
107-
if: "! needs.build.outputs.self_mutation_happened"
10883
steps:
10984
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
11085
with:
@@ -130,7 +105,6 @@ jobs:
130105
needs: build
131106
runs-on: ubuntu-latest
132107
permissions: {}
133-
if: "! needs.build.outputs.self_mutation_happened"
134108
steps:
135109
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
136110
with:
@@ -156,7 +130,6 @@ jobs:
156130
needs: build
157131
runs-on: ubuntu-latest
158132
permissions: {}
159-
if: "! needs.build.outputs.self_mutation_happened"
160133
steps:
161134
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
162135
with:

API.md

Lines changed: 348 additions & 332 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/l1-resources/encryption-at-rest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export class CdkTestingStack extends cdk.Stack {
1717
const atlasProps = this.getContextProps();
1818
const encryptionAtRest = new CfnEncryptionAtRest(this, 'EncryptionAtRest', {
1919
projectId: atlasProps.projId,
20-
profile: atlasProps.profile,
21-
awsKms: {
20+
profile: atlasProps.profile,
21+
awsKmsConfig: {
2222
enabled: true,
2323
region: atlasProps.region,
2424
customerMasterKeyId: atlasProps.customerMasterKeyId
@@ -29,7 +29,7 @@ export class CdkTestingStack extends cdk.Stack {
2929

3030
getContextProps(): AtlasStackProps {
3131
const projId = this.node.tryGetContext('projId');
32-
if (!projId){
32+
if (!projId) {
3333
throw "No context value specified for projId. Please specify via the cdk context."
3434
}
3535

examples/l1-resources/federation-query-limit.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as cdk from 'aws-cdk-lib';
22
import { Construct } from 'constructs';
3-
import { CfnFederatedQueryLimit, CfnFederatedQueryLimitPropsLimitName} from 'awscdk-resources-mongodbatlas';
3+
import { CfnFederatedQueryLimit, CfnFederatedQueryLimitPropsLimitName } from 'awscdk-resources-mongodbatlas';
44

55
interface AtlasStackProps {
66
readonly projectId: string;
@@ -20,22 +20,22 @@ export class CdkTestingStack extends cdk.Stack {
2020
profile: atlasProps.profile,
2121
projectId: atlasProps.projectId,
2222
tenantName: atlasProps.tenantName,
23-
limitName : atlasProps.limitName,
23+
limitName: atlasProps.limitName,
2424
value: atlasProps.value
2525
});
2626
}
2727

2828
getContextProps(): AtlasStackProps {
2929
const projectId = this.node.tryGetContext('projId');
30-
if (!projectId){
30+
if (!projectId) {
3131
throw "No context value specified for projId. Please specify via the cdk context."
3232
}
3333

3434
const profile = this.node.tryGetContext('profile') ?? 'default';
3535
const role = this.node.tryGetContext('role');
3636
const tenantName = this.node.tryGetContext('tenantName');
37-
const limitName= this.node.tryGetContext('limitName') ?? CfnFederatedQueryLimitPropsLimitName.BYTES_PROCESSED_QUERY;
38-
const value= this.node.tryGetContext("value") ?? "2000000000"
37+
const limitName = this.node.tryGetContext('limitName') ?? CfnFederatedQueryLimitPropsLimitName.BYTES_PROCESSED_QUERY;
38+
const value = this.node.tryGetContext("value") ?? "2000000000"
3939
return {
4040
projectId,
4141
profile,

scripts/cdk-all.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Copyright 2024 MongoDB Inc
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This shell script can be use to generate all L1 CDK Constructs.
18+
# The script calls cdk.sh for each resource.
19+
#
20+
# How to use it: ./scripts/cdk-all.sh
21+
22+
set -euo pipefail
23+
24+
dir="src/l1-resources"
25+
26+
for subdir in "${dir}"/*/; do
27+
if [ -d "${subdir}" ]; then
28+
resource=$(basename "${subdir}")
29+
./scripts/cdk.sh "${resource}"
30+
fi
31+
done

scripts/cdk.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Copyright 2023 MongoDB Inc
3+
# Copyright 2024 MongoDB Inc
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -17,18 +17,17 @@
1717
# This shell script can be use to generate one L1 CDK Construct.
1818
# The script uses the CFN template to generate the CDK resource.
1919
#
20-
# How to use it:
21-
# 1. CDK L1: ./cdk.sh "<RESOURCE NAME>" l1
20+
# How to use it: ./scripts/cdk.sh "<RESOURCE NAME>"
2221

2322
set -euo pipefail
2423

2524
_print_usage() {
2625
echo
2726
echo 'Usage:'
28-
echo './script/cdk.sh "<RESOURCE NAME>"'
27+
echo './scripts/cdk.sh "<RESOURCE NAME>"'
2928
echo
3029
echo 'Example:'
31-
echo './script/cdk.sh database-user'
30+
echo './scripts/cdk.sh database-user'
3231
echo
3332
}
3433

@@ -54,7 +53,12 @@ cdk-import cfn -l typescript -s "${resourceTemp}" -o "src/l1-resources/${resourc
5453
# Rename resource file to index.ts file
5554
dest="src/l1-resources/${resource}/index.ts"
5655
mv "src/l1-resources/${resource}/${mainFileRoot}.ts" "${dest}"
57-
python "./scripts/rename_in_file.py" "${dest}"
56+
57+
# Remove UNDERSCORE_, HYPHEN_, PERIOD_ and VALUE_ strings from the generated file
58+
sed -e 's/UNDERSCORE_//g' -e 's/HYPHEN_//g' -e 's/PERIOD_//g' -e 's/VALUE_//g' "${dest}" > "${dest}.tmp" && mv "${dest}.tmp" "${dest}"
59+
60+
# Fix @typescript-eslint/no-shadow es-linter error in file federated-database-instance/index.ts
61+
sed -e 's/map(y => toJson_TagSet(y))/map(x => toJson_TagSet(x))/g' "${dest}" > "${dest}.tmp" && mv "${dest}.tmp" "${dest}"
5862

5963
echo
6064
echo "L1 CDK resource generated succesfully: ${resource}, CFN type: ${resourceType}"

scripts/rename_in_file.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

scripts/rename_in_file_test.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export { CfnAuditing, CfnAuditingProps } from "./l1-resources/auditing";
4949
export {
5050
CfnCloudBackUpRestoreJobs,
5151
CfnCloudBackUpRestoreJobsProps,
52+
CfnCloudBackUpRestoreJobsPropsLinks,
5253
CfnCloudBackUpRestoreJobsPropsDeliveryType,
5354
CfnCloudBackUpRestoreJobsPropsInstanceType,
5455
SynchronousCreationOptions,
@@ -164,7 +165,7 @@ export {
164165
} from "./l1-resources/datalakes";
165166

166167
export {
167-
AwsKmsConfiguration,
168+
AwsKmsConfig,
168169
CfnEncryptionAtRest,
169170
CfnEncryptionAtRestProps,
170171
} from "./l1-resources/encryption-at-rest";
@@ -314,6 +315,7 @@ export {
314315
} from "./l1-resources/search-deployment";
315316

316317
export {
318+
ApiAtlasFtsAnalyzersTokenizer,
317319
ApiAtlasFtsAnalyzersViewManual,
318320
ApiAtlasFtsMappingsViewManual,
319321
ApiAtlasFtsSynonymMappingDefinitionView,
@@ -336,7 +338,6 @@ export {
336338
export {
337339
CfnServerlessPrivateEndpointProps,
338340
CfnServerlessPrivateEndpoint,
339-
ServerlessPrivateEndpoint,
340341
AwsPrivateEndpointConfig,
341342
} from "./l1-resources/serverless-private-endpoint";
342343

0 commit comments

Comments
 (0)