Skip to content

Commit

Permalink
chore: Detects if L1 constructs are not up-to-date (#335)
Browse files Browse the repository at this point in the history
Co-authored-by: Oriol Arbusi <[email protected]>
  • Loading branch information
lantoli and oarbusi authored Jul 30, 2024
1 parent 1707268 commit 273cd1d
Show file tree
Hide file tree
Showing 40 changed files with 597 additions and 642 deletions.
32 changes: 31 additions & 1 deletion .github/workflows/code-health.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,38 @@ jobs:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- name: Run ShellCheck
uses: bewuethr/shellcheck-action@d01912909579c4b1a335828b8fca197fbb8e0aa4
check-l1-updated:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
with:
node-version: 18.x
- run: yarn install --check-files
- run: npm install -g cdk-import
- run: ./scripts/cdk-all.sh
- run: npx projen build
- name: Find mutations
id: self_mutation
run: |-
git add .
git diff --staged --patch --exit-code > .repo.patch || echo "self_mutation_happened=true" >> "${GITHUB_OUTPUT}"
- name: Upload patch
if: steps.self_mutation.outputs.self_mutation_happened
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
with:
name: .repo.patch
path: .repo.patch
- name: Fail build on mutation
if: steps.self_mutation.outputs.self_mutation_happened
run: |-
echo "::error::Files were changed during build (see build log). If this was triggered from a fork, you will need to update your branch."
cat .repo.patch
exit 1
call-package-workflow:
needs: [compile, lint, shellcheck]
needs: [compile, lint, shellcheck, check-l1-updated]
secrets: inherit
permissions:
contents: write
Expand Down
29 changes: 1 addition & 28 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
self_mutation_happened: ${{ steps.self_mutation.outputs.self_mutation_happened }}
env:
CI: "true"
permissions: {}
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
Expand All @@ -25,23 +20,6 @@ jobs:
run: yarn install --check-files
- name: build
run: npx projen build
- name: Find mutations
id: self_mutation
run: |-
git add .
git diff --staged --patch --exit-code > .repo.patch || echo "self_mutation_happened=true" >> "${GITHUB_OUTPUT}"
- name: Upload patch
if: steps.self_mutation.outputs.self_mutation_happened
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
with:
name: .repo.patch
path: .repo.patch
- name: Fail build on mutation
if: steps.self_mutation.outputs.self_mutation_happened
run: |-
echo "::error::Files were changed during build (see build log). If this was triggered from a fork, you will need to update your branch."
cat .repo.patch
exit 1
- name: Backup artifact permissions
run: cd dist && getfacl -R . > permissions-backup.acl
continue-on-error: true
Expand All @@ -54,7 +32,6 @@ jobs:
needs: build
runs-on: ubuntu-latest
permissions: {}
if: "! needs.build.outputs.self_mutation_happened"
steps:
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
with:
Expand All @@ -77,7 +54,6 @@ jobs:
needs: build
runs-on: ubuntu-latest
permissions: {}
if: "! needs.build.outputs.self_mutation_happened"
steps:
- uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9
with:
Expand All @@ -104,7 +80,6 @@ jobs:
needs: build
runs-on: ubuntu-latest
permissions: {}
if: "! needs.build.outputs.self_mutation_happened"
steps:
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
with:
Expand All @@ -130,7 +105,6 @@ jobs:
needs: build
runs-on: ubuntu-latest
permissions: {}
if: "! needs.build.outputs.self_mutation_happened"
steps:
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
with:
Expand All @@ -156,7 +130,6 @@ jobs:
needs: build
runs-on: ubuntu-latest
permissions: {}
if: "! needs.build.outputs.self_mutation_happened"
steps:
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b
with:
Expand Down
680 changes: 348 additions & 332 deletions API.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions examples/l1-resources/encryption-at-rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class CdkTestingStack extends cdk.Stack {
const atlasProps = this.getContextProps();
const encryptionAtRest = new CfnEncryptionAtRest(this, 'EncryptionAtRest', {
projectId: atlasProps.projId,
profile: atlasProps.profile,
awsKms: {
profile: atlasProps.profile,
awsKmsConfig: {
enabled: true,
region: atlasProps.region,
customerMasterKeyId: atlasProps.customerMasterKeyId
Expand All @@ -29,7 +29,7 @@ export class CdkTestingStack extends cdk.Stack {

getContextProps(): AtlasStackProps {
const projId = this.node.tryGetContext('projId');
if (!projId){
if (!projId) {
throw "No context value specified for projId. Please specify via the cdk context."
}

Expand Down
10 changes: 5 additions & 5 deletions examples/l1-resources/federation-query-limit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { CfnFederatedQueryLimit, CfnFederatedQueryLimitPropsLimitName} from 'awscdk-resources-mongodbatlas';
import { CfnFederatedQueryLimit, CfnFederatedQueryLimitPropsLimitName } from 'awscdk-resources-mongodbatlas';

interface AtlasStackProps {
readonly projectId: string;
Expand All @@ -20,22 +20,22 @@ export class CdkTestingStack extends cdk.Stack {
profile: atlasProps.profile,
projectId: atlasProps.projectId,
tenantName: atlasProps.tenantName,
limitName : atlasProps.limitName,
limitName: atlasProps.limitName,
value: atlasProps.value
});
}

getContextProps(): AtlasStackProps {
const projectId = this.node.tryGetContext('projId');
if (!projectId){
if (!projectId) {
throw "No context value specified for projId. Please specify via the cdk context."
}

const profile = this.node.tryGetContext('profile') ?? 'default';
const role = this.node.tryGetContext('role');
const tenantName = this.node.tryGetContext('tenantName');
const limitName= this.node.tryGetContext('limitName') ?? CfnFederatedQueryLimitPropsLimitName.BYTES_PROCESSED_QUERY;
const value= this.node.tryGetContext("value") ?? "2000000000"
const limitName = this.node.tryGetContext('limitName') ?? CfnFederatedQueryLimitPropsLimitName.BYTES_PROCESSED_QUERY;
const value = this.node.tryGetContext("value") ?? "2000000000"
return {
projectId,
profile,
Expand Down
31 changes: 31 additions & 0 deletions scripts/cdk-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Copyright 2024 MongoDB Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This shell script can be use to generate all L1 CDK Constructs.
# The script calls cdk.sh for each resource.
#
# How to use it: ./scripts/cdk-all.sh

set -euo pipefail

dir="src/l1-resources"

for subdir in "${dir}"/*/; do
if [ -d "${subdir}" ]; then
resource=$(basename "${subdir}")
./scripts/cdk.sh "${resource}"
fi
done
16 changes: 10 additions & 6 deletions scripts/cdk.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

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

set -euo pipefail

_print_usage() {
echo
echo 'Usage:'
echo './script/cdk.sh "<RESOURCE NAME>"'
echo './scripts/cdk.sh "<RESOURCE NAME>"'
echo
echo 'Example:'
echo './script/cdk.sh database-user'
echo './scripts/cdk.sh database-user'
echo
}

Expand All @@ -54,7 +53,12 @@ cdk-import cfn -l typescript -s "${resourceTemp}" -o "src/l1-resources/${resourc
# Rename resource file to index.ts file
dest="src/l1-resources/${resource}/index.ts"
mv "src/l1-resources/${resource}/${mainFileRoot}.ts" "${dest}"
python "./scripts/rename_in_file.py" "${dest}"

# Remove UNDERSCORE_, HYPHEN_, PERIOD_ and VALUE_ strings from the generated file
sed -e 's/UNDERSCORE_//g' -e 's/HYPHEN_//g' -e 's/PERIOD_//g' -e 's/VALUE_//g' "${dest}" > "${dest}.tmp" && mv "${dest}.tmp" "${dest}"

# Fix @typescript-eslint/no-shadow es-linter error in file federated-database-instance/index.ts
sed -e 's/map(y => toJson_TagSet(y))/map(x => toJson_TagSet(x))/g' "${dest}" > "${dest}.tmp" && mv "${dest}.tmp" "${dest}"

echo
echo "L1 CDK resource generated succesfully: ${resource}, CFN type: ${resourceType}"
30 changes: 0 additions & 30 deletions scripts/rename_in_file.py

This file was deleted.

35 changes: 0 additions & 35 deletions scripts/rename_in_file_test.py

This file was deleted.

5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export { CfnAuditing, CfnAuditingProps } from "./l1-resources/auditing";
export {
CfnCloudBackUpRestoreJobs,
CfnCloudBackUpRestoreJobsProps,
CfnCloudBackUpRestoreJobsPropsLinks,
CfnCloudBackUpRestoreJobsPropsDeliveryType,
CfnCloudBackUpRestoreJobsPropsInstanceType,
SynchronousCreationOptions,
Expand Down Expand Up @@ -164,7 +165,7 @@ export {
} from "./l1-resources/datalakes";

export {
AwsKmsConfiguration,
AwsKmsConfig,
CfnEncryptionAtRest,
CfnEncryptionAtRestProps,
} from "./l1-resources/encryption-at-rest";
Expand Down Expand Up @@ -314,6 +315,7 @@ export {
} from "./l1-resources/search-deployment";

export {
ApiAtlasFtsAnalyzersTokenizer,
ApiAtlasFtsAnalyzersViewManual,
ApiAtlasFtsMappingsViewManual,
ApiAtlasFtsSynonymMappingDefinitionView,
Expand All @@ -336,7 +338,6 @@ export {
export {
CfnServerlessPrivateEndpointProps,
CfnServerlessPrivateEndpoint,
ServerlessPrivateEndpoint,
AwsPrivateEndpointConfig,
} from "./l1-resources/serverless-private-endpoint";

Expand Down
Loading

0 comments on commit 273cd1d

Please sign in to comment.