From cfc939402ce151dd53bae990427fa6be927204b9 Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Wed, 17 Aug 2022 22:26:12 +0200 Subject: [PATCH 01/19] Introduce MegaLinter --- .github/workflows/mega-linter.yml | 79 +++++++++++++++++++++++++++++++ .gitignore | 2 + .mega-linter.yml | 27 +++++++++++ .yamllint => .yamllint.yml | 1 - Makefile | 2 +- 5 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/mega-linter.yml create mode 100644 .mega-linter.yml rename .yamllint => .yamllint.yml (98%) diff --git a/.github/workflows/mega-linter.yml b/.github/workflows/mega-linter.yml new file mode 100644 index 000000000..2c74691bd --- /dev/null +++ b/.github/workflows/mega-linter.yml @@ -0,0 +1,79 @@ +--- +# MegaLinter GitHub Action configuration file +# More info at https://oxsecurity.github.io/megalinter +name: MegaLinter + +on: [push, pull_request] + +env: + # Apply linter fixes configuration + APPLY_FIXES: none + APPLY_FIXES_EVENT: pull_request + APPLY_FIXES_MODE: pull_request + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + build: + name: MegaLinter + runs-on: ubuntu-latest + steps: + # Git Checkout + - name: Checkout Code + uses: actions/checkout@v3 + with: + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} + fetch-depth: 0 + + # MegaLinter + - name: MegaLinter + id: ml + # You can override MegaLinter flavor used to have faster performances + # More info at https://oxsecurity.github.io/megalinter/flavors/ + uses: oxsecurity/megalinter@v6 + env: + # All available variables are described in documentation + # https://oxsecurity.github.io/megalinter/configuration/ + # Set ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} to validate only diff with main branch + VALIDATE_ALL_CODEBASE: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY + + # Upload MegaLinter artifacts + - name: Archive production artifacts + if: ${{ success() }} || ${{ failure() }} + uses: actions/upload-artifact@v2 + with: + name: MegaLinter reports + path: | + megalinter-reports + mega-linter.log + + # Create pull request if applicable (for now works only on PR from same repository, not from forks) + - name: Create Pull Request with applied fixes + id: cpr + if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix') + uses: peter-evans/create-pull-request@v4 + with: + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} + commit-message: "[MegaLinter] Apply linters automatic fixes" + title: "[MegaLinter] Apply linters automatic fixes" + labels: bot + - name: Create PR output + if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix') + run: | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" + echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" + + # Push new commit if applicable (for now works only on PR from same repository, not from forks) + - name: Prepare commit + if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix') + run: sudo chown -Rc $UID .git/ + - name: Commit and push applied linter fixes + if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix') + uses: stefanzweifel/git-auto-commit-action@v4 + with: + branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }} + commit_message: "[MegaLinter] Apply linters fixes" diff --git a/.gitignore b/.gitignore index 16165b2e2..2debaecf8 100644 --- a/.gitignore +++ b/.gitignore @@ -137,3 +137,5 @@ dmypy.json # Pyre type checker .pyre/ + +megalinter-reports/ diff --git a/.mega-linter.yml b/.mega-linter.yml new file mode 100644 index 000000000..0d5c3a133 --- /dev/null +++ b/.mega-linter.yml @@ -0,0 +1,27 @@ +# Configuration file for MegaLinter +# See all available variables at https://oxsecurity.github.io/megalinter/configuration/ and in linters documentation + +# all, none, or list of linter keys +APPLY_FIXES: none + +# If you use ENABLE variable, all other languages/formats/tooling-formats will be disabled by default +# ENABLE: + +# If you use ENABLE_LINTERS variable, all other linters will be disabled by default +ENABLE_LINTERS: + - CLOUDFORMATION_CFN_LINT + #- DOCKERFILE_HADOLINT + - JSON_JSONLINT + #- JSON_PRETTIER + - JSON_V8R + #- JAVASCRIPT_STANDARD + #- SPELL_MISSPELL + #- TERRAFORM_TFLINT + #- YAML_YAMLLINT + +# DISABLE: +# - COPYPASTE # Comment to enable checks of excessive copy-pastes +# - SPELL # Comment to enable checks of spelling mistakes +SHOW_ELAPSED_TIME: true +FILEIO_REPORTER: false +# DISABLE_ERRORS: true # Uncomment if you want MegaLinter to detect errors but not block CI to pass diff --git a/.yamllint b/.yamllint.yml similarity index 98% rename from .yamllint rename to .yamllint.yml index 332b7476b..08e0cbe06 100644 --- a/.yamllint +++ b/.yamllint.yml @@ -2,7 +2,6 @@ yaml-files: - '*.yaml' - '*.yml' - - '.yamllint' rules: braces: diff --git a/Makefile b/Makefile index a21a95798..304594de2 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ test: lint: # Linter performs static analysis to catch latent bugs find src/ -iname "*.py" -not -path "src/.aws-sam/*" | xargs pylint --rcfile .pylintrc - find src -iname "*.yml" -o -iname "*.yaml" -not -path "src/.aws-sam/*" | xargs yamllint -c .yamllint + find src -iname "*.yml" -o -iname "*.yaml" -not -path "src/.aws-sam/*" | xargs yamllint -c .yamllint.yml cfn-lint build: From 46e67abb1fae65c1e61e3f9bc82f185e19a3af55 Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Wed, 17 Aug 2022 22:33:20 +0200 Subject: [PATCH 02/19] Enable: DOCKERFILE_HADOLINT --- .mega-linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mega-linter.yml b/.mega-linter.yml index 0d5c3a133..f74df0f33 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -10,7 +10,7 @@ APPLY_FIXES: none # If you use ENABLE_LINTERS variable, all other linters will be disabled by default ENABLE_LINTERS: - CLOUDFORMATION_CFN_LINT - #- DOCKERFILE_HADOLINT + - DOCKERFILE_HADOLINT - JSON_JSONLINT #- JSON_PRETTIER - JSON_V8R From 89cacf9103011e0c9ff98663e3f0187e69fe7db4 Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Thu, 18 Aug 2022 08:14:52 +0200 Subject: [PATCH 03/19] Fix: DOCKERFILE_HADOLINT findings --- samples/sample-fargate-node-app/Dockerfile | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/samples/sample-fargate-node-app/Dockerfile b/samples/sample-fargate-node-app/Dockerfile index 9ef7ffa6c..541f46587 100644 --- a/samples/sample-fargate-node-app/Dockerfile +++ b/samples/sample-fargate-node-app/Dockerfile @@ -1,9 +1,6 @@ -FROM node:latest - -ADD . . - +FROM node:current-alpine +WORKDIR /app +COPY . . RUN npm install - EXPOSE 3000 - -ENTRYPOINT ["npm", "start"] +ENTRYPOINT ["npm", "start"] \ No newline at end of file From b012523727d46083a2e3c71abab57acf5b3ab3c2 Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Thu, 18 Aug 2022 08:20:48 +0200 Subject: [PATCH 04/19] Enable: JSON_PRETTIER and Fix findings --- .mega-linter.yml | 2 +- samples/sample-cdk-app/tsconfig.json | 5 ++--- .../adf-bootstrap/example-scp.json | 12 ++++-------- .../adf-bootstrap/example-tagging-policy.json | 11 +++-------- .../shared/tests/stubs/stub_cfn_global.json | 6 +++--- 5 files changed, 13 insertions(+), 23 deletions(-) diff --git a/.mega-linter.yml b/.mega-linter.yml index f74df0f33..3c605b51f 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -12,7 +12,7 @@ ENABLE_LINTERS: - CLOUDFORMATION_CFN_LINT - DOCKERFILE_HADOLINT - JSON_JSONLINT - #- JSON_PRETTIER + - JSON_PRETTIER - JSON_V8R #- JAVASCRIPT_STANDARD #- SPELL_MISSPELL diff --git a/samples/sample-cdk-app/tsconfig.json b/samples/sample-cdk-app/tsconfig.json index f2e82ef87..7ddc145cd 100644 --- a/samples/sample-cdk-app/tsconfig.json +++ b/samples/sample-cdk-app/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target":"ES2018", + "target": "ES2018", "module": "commonjs", "lib": ["es2016", "es2017.object", "es2017.string"], "strict": true, @@ -15,7 +15,6 @@ "inlineSourceMap": true, "inlineSources": true, "experimentalDecorators": true, - "strictPropertyInitialization":false + "strictPropertyInitialization": false } } - diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-scp.json b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-scp.json index 59287370c..fcfac8b92 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-scp.json +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-scp.json @@ -1,6 +1,7 @@ { "Version": "2012-10-17", - "Statement": [{ + "Statement": [ + { "Effect": "Deny", "Action": "cloudtrail:Stop*", "Resource": "*" @@ -12,13 +13,8 @@ }, { "Effect": "Deny", - "Action": [ - "config:DeleteConfigRule", - "config:DeleteConfigurationRecorder", - "config:DeleteDeliveryChannel", - "config:Stop*" - ], + "Action": ["config:DeleteConfigRule", "config:DeleteConfigurationRecorder", "config:DeleteDeliveryChannel", "config:Stop*"], "Resource": "*" } ] -} \ No newline at end of file +} diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-tagging-policy.json b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-tagging-policy.json index 4cb134f53..8fd67d31d 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-tagging-policy.json +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-tagging-policy.json @@ -5,16 +5,11 @@ "@@assign": "my_key" }, "tag_value": { - "@@assign": [ - "value1", - "value2" - ] + "@@assign": ["value1", "value2"] }, "enforced_for": { - "@@assign": [ - "s3:bucket" - ] + "@@assign": ["s3:bucket"] } } } -} \ No newline at end of file +} diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/tests/stubs/stub_cfn_global.json b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/tests/stubs/stub_cfn_global.json index 921d0a29c..5157a0170 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/tests/stubs/stub_cfn_global.json +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/tests/stubs/stub_cfn_global.json @@ -4,8 +4,8 @@ "Environment": "testing", "MySpecialValue": "resolve:/values/some_value" }, - "Tags" : { - "TagKey" : "123", - "MyKey" : "new_value" + "Tags": { + "TagKey": "123", + "MyKey": "new_value" } } From 675e81a5d4a7e98bcef144e51230f9626ec5afdb Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Thu, 18 Aug 2022 08:21:32 +0200 Subject: [PATCH 05/19] Enable: SPELL_MISSPELL --- .mega-linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mega-linter.yml b/.mega-linter.yml index 3c605b51f..6b5e7ae2c 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -15,7 +15,7 @@ ENABLE_LINTERS: - JSON_PRETTIER - JSON_V8R #- JAVASCRIPT_STANDARD - #- SPELL_MISSPELL + - SPELL_MISSPELL #- TERRAFORM_TFLINT #- YAML_YAMLLINT From 5f8a0c1a2c1504859506758653610563f749e67a Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Thu, 18 Aug 2022 08:22:21 +0200 Subject: [PATCH 06/19] Fix: SPELL_MISSPELL --- src/account_processing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/account_processing.yml b/src/account_processing.yml index a16f8d8e8..4ae6bcd36 100644 --- a/src/account_processing.yml +++ b/src/account_processing.yml @@ -1,6 +1,6 @@ AWSTemplateFormatVersion: '2010-09-09' Transform: 'AWS::Serverless-2016-10-31' -Description: ADF CloudFormation Stack pertaing to account processing / OU management. +Description: ADF CloudFormation Stack pertaining to account processing / OU management. Parameters: OrganizationID: From 9a8a8e1d664d002be58bcb1fd281a746109e41ff Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Thu, 18 Aug 2022 08:22:50 +0200 Subject: [PATCH 07/19] Enable: TERRAFORM_TFLINT --- .mega-linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mega-linter.yml b/.mega-linter.yml index 6b5e7ae2c..af24663f3 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -16,7 +16,7 @@ ENABLE_LINTERS: - JSON_V8R #- JAVASCRIPT_STANDARD - SPELL_MISSPELL - #- TERRAFORM_TFLINT + - TERRAFORM_TFLINT #- YAML_YAMLLINT # DISABLE: From 0d938dff9521f9f3d5dd10a435ab5c2656a55e01 Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Thu, 18 Aug 2022 08:24:10 +0200 Subject: [PATCH 08/19] Fix: TERRAFORM_TFLINT https://github.com/terraform-linters/tflint/blob/v0.35.0/docs/rules/terraform_deprecated_interpolation.md --- samples/sample-terraform/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/sample-terraform/main.tf b/samples/sample-terraform/main.tf index 2cd9d4b34..61d2b061b 100644 --- a/samples/sample-terraform/main.tf +++ b/samples/sample-terraform/main.tf @@ -6,7 +6,7 @@ provider "aws" { } resource "aws_s3_bucket" "b" { - bucket = "${var.my_bucket_name}" + bucket = var.my_bucket_name acl = "private" tags = { From 1d29ed82261f4d9bc1a4f76206433f19e255cd99 Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Thu, 18 Aug 2022 08:25:26 +0200 Subject: [PATCH 09/19] Enable: YAML_YAMLLINT --- .mega-linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mega-linter.yml b/.mega-linter.yml index af24663f3..5eb23e69a 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -17,7 +17,7 @@ ENABLE_LINTERS: #- JAVASCRIPT_STANDARD - SPELL_MISSPELL - TERRAFORM_TFLINT - #- YAML_YAMLLINT + - YAML_YAMLLINT # DISABLE: # - COPYPASTE # Comment to enable checks of excessive copy-pastes From 4f391cf835f6cf2d2cb635080f5041fe2bdf6d6e Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Thu, 18 Aug 2022 08:34:48 +0200 Subject: [PATCH 10/19] Fix: YAML_YAMLLINT - VPC fix as per https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getavailabilityzones.html\#w2ab1c31c28c36c19 --- .github/workflows/adf.yml | 2 +- .mega-linter.yml | 2 +- .yamllint.yml | 2 +- samples/sample-serverless-app/template.yml | 2 +- samples/sample-vpc/template.yml | 42 ++++++++++------------ 5 files changed, 22 insertions(+), 28 deletions(-) diff --git a/.github/workflows/adf.yml b/.github/workflows/adf.yml index 3da236166..962e2c829 100644 --- a/.github/workflows/adf.yml +++ b/.github/workflows/adf.yml @@ -17,7 +17,7 @@ jobs: with: python-version: ${{ matrix.python-version }} - name: Set the correct Node version using nvm - shell: bash -l {0} + shell: bash -l {0} run: nvm install - name: Install dependencies run: make init diff --git a/.mega-linter.yml b/.mega-linter.yml index 5eb23e69a..712dc999e 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -14,7 +14,7 @@ ENABLE_LINTERS: - JSON_JSONLINT - JSON_PRETTIER - JSON_V8R - #- JAVASCRIPT_STANDARD + # - JAVASCRIPT_STANDARD - SPELL_MISSPELL - TERRAFORM_TFLINT - YAML_YAMLLINT diff --git a/.yamllint.yml b/.yamllint.yml index 08e0cbe06..0e2498813 100644 --- a/.yamllint.yml +++ b/.yamllint.yml @@ -19,7 +19,6 @@ rules: document-start: disable empty-lines: enable empty-values: disable - empty-values: disable float-values: forbid-inf: true forbid-nan: true @@ -37,3 +36,4 @@ rules: trailing-spaces: enable truthy: level: error + check-keys: false diff --git a/samples/sample-serverless-app/template.yml b/samples/sample-serverless-app/template.yml index 0b7065f7c..96d25f947 100644 --- a/samples/sample-serverless-app/template.yml +++ b/samples/sample-serverless-app/template.yml @@ -10,7 +10,7 @@ Metadata: config: ignore_checks: # https://github.com/aws/serverless-application-model/issues/1590 - - I3042 + - I3042 Resources: ExampleServerlessApp: Type: 'AWS::Serverless::Function' diff --git a/samples/sample-vpc/template.yml b/samples/sample-vpc/template.yml index d311078c1..d343a316a 100644 --- a/samples/sample-vpc/template.yml +++ b/samples/sample-vpc/template.yml @@ -198,10 +198,9 @@ Resources: PrivateSubnet1a: Type: AWS::EC2::Subnet Properties: - AvailabilityZone: - Fn::Select: - - 0 - - Fn::GetAZs: {Ref: 'AWS::Region'} + AvailabilityZone: !Select + - 0 + - Fn::GetAZs: !Ref 'AWS::Region' VpcId: !Ref 'VPC' CidrBlock: !FindInMap ['SubnetConfig', 'PrivateOne', 'CIDR'] Tags: @@ -224,10 +223,9 @@ Resources: PrivateSubnet1b: Type: AWS::EC2::Subnet Properties: - AvailabilityZone: - Fn::Select: - - 1 - - Fn::GetAZs: {Ref: 'AWS::Region'} + AvailabilityZone: !Select + - 1 + - Fn::GetAZs: !Ref 'AWS::Region' VpcId: !Ref 'VPC' CidrBlock: !FindInMap ['SubnetConfig', 'PrivateTwo', 'CIDR'] Tags: @@ -250,10 +248,9 @@ Resources: PrivateSubnet1c: Type: AWS::EC2::Subnet Properties: - AvailabilityZone: - Fn::Select: - - 2 - - Fn::GetAZs: {Ref: 'AWS::Region'} + AvailabilityZone: !Select + - 2 + - Fn::GetAZs: !Ref 'AWS::Region' VpcId: !Ref 'VPC' CidrBlock: !FindInMap ['SubnetConfig', 'PrivateThree', 'CIDR'] Tags: @@ -300,10 +297,9 @@ Resources: PublicSubnet1a: Type: AWS::EC2::Subnet Properties: - AvailabilityZone: - Fn::Select: - - 0 - - Fn::GetAZs: {Ref: 'AWS::Region'} + AvailabilityZone: !Select + - 0 + - Fn::GetAZs: !Ref 'AWS::Region' VpcId: !Ref 'VPC' CidrBlock: !FindInMap ['SubnetConfig', 'PublicOne', 'CIDR'] MapPublicIpOnLaunch: true @@ -327,10 +323,9 @@ Resources: PublicSubnet1b: Type: AWS::EC2::Subnet Properties: - AvailabilityZone: - Fn::Select: - - 1 - - Fn::GetAZs: {Ref: 'AWS::Region'} + AvailabilityZone: !Select + - 1 + - Fn::GetAZs: !Ref 'AWS::Region' VpcId: !Ref 'VPC' CidrBlock: !FindInMap ['SubnetConfig', 'PublicTwo', 'CIDR'] Tags: @@ -353,10 +348,9 @@ Resources: PublicSubnet1c: Type: AWS::EC2::Subnet Properties: - AvailabilityZone: - Fn::Select: - - 2 - - Fn::GetAZs: {Ref: 'AWS::Region'} + AvailabilityZone: !Select + - 2 + - Fn::GetAZs: !Ref 'AWS::Region' VpcId: !Ref 'VPC' CidrBlock: !FindInMap ['SubnetConfig', 'PublicThree', 'CIDR'] Tags: From 5c727d7675f75bc599efe8ebf4da14885b6f2143 Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Thu, 18 Aug 2022 08:36:58 +0200 Subject: [PATCH 11/19] Enable: JAVASCRIPT_STANDARD --- .mega-linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mega-linter.yml b/.mega-linter.yml index 712dc999e..ffa567306 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -14,7 +14,7 @@ ENABLE_LINTERS: - JSON_JSONLINT - JSON_PRETTIER - JSON_V8R - # - JAVASCRIPT_STANDARD + - JAVASCRIPT_STANDARD - SPELL_MISSPELL - TERRAFORM_TFLINT - YAML_YAMLLINT From 55379751ae9fd8d185571f220d432777df80b43b Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Thu, 18 Aug 2022 08:37:58 +0200 Subject: [PATCH 12/19] Fix: JAVASCRIPT_STANDARD --- samples/sample-fargate-node-app/index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/samples/sample-fargate-node-app/index.js b/samples/sample-fargate-node-app/index.js index e5d439249..53f7ada70 100644 --- a/samples/sample-fargate-node-app/index.js +++ b/samples/sample-fargate-node-app/index.js @@ -1,21 +1,21 @@ -const express = require('express'); +const express = require('express') const app = express() -app.set('view engine', 'ejs'); +app.set('view engine', 'ejs') app.use(express.static('public')) app.get('/', (req, res) => { - res.render('index', { - region: process.env.REGION, - environment: process.env.ENVIRONMENT - }) + res.render('index', { + region: process.env.REGION, + environment: process.env.ENVIRONMENT + }) }) app.get('/version', (req, res) => { - res.json({"version": "0.0.1"}) + res.json({ version: '0.0.1' }) }) app.listen(3000, () => { - console.log('Listening on 3000') -}) \ No newline at end of file + console.log('Listening on 3000') +}) From 801c8a8f353dfc196c246e30b7034d48fc733eee Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Thu, 18 Aug 2022 15:34:05 +0200 Subject: [PATCH 13/19] change the linter config to prefer lists on new lines per items --- .mega-linter.yml | 4 ++++ samples/sample-cdk-app/tsconfig.json | 6 +++++- .../bootstrap_repository/adf-bootstrap/example-scp.json | 7 ++++++- .../adf-bootstrap/example-tagging-policy.json | 5 ++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.mega-linter.yml b/.mega-linter.yml index ffa567306..628b567b6 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -25,3 +25,7 @@ ENABLE_LINTERS: SHOW_ELAPSED_TIME: true FILEIO_REPORTER: false # DISABLE_ERRORS: true # Uncomment if you want MegaLinter to detect errors but not block CI to pass + +JSON_PRETTIER_PRE_COMMANDS: + - command: npm install prettier-plugin-multiline-arrays@1.1.0 + cwd: "workspace" \ No newline at end of file diff --git a/samples/sample-cdk-app/tsconfig.json b/samples/sample-cdk-app/tsconfig.json index 7ddc145cd..d050bcc50 100644 --- a/samples/sample-cdk-app/tsconfig.json +++ b/samples/sample-cdk-app/tsconfig.json @@ -2,7 +2,11 @@ "compilerOptions": { "target": "ES2018", "module": "commonjs", - "lib": ["es2016", "es2017.object", "es2017.string"], + "lib": [ + "es2016", + "es2017.object", + "es2017.string" + ], "strict": true, "noImplicitAny": true, "strictNullChecks": true, diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-scp.json b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-scp.json index fcfac8b92..e0922fcbb 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-scp.json +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-scp.json @@ -13,7 +13,12 @@ }, { "Effect": "Deny", - "Action": ["config:DeleteConfigRule", "config:DeleteConfigurationRecorder", "config:DeleteDeliveryChannel", "config:Stop*"], + "Action": [ + "config:DeleteConfigRule", + "config:DeleteConfigurationRecorder", + "config:DeleteDeliveryChannel", + "config:Stop*" + ], "Resource": "*" } ] diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-tagging-policy.json b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-tagging-policy.json index 8fd67d31d..4c73dacdc 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-tagging-policy.json +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/example-tagging-policy.json @@ -5,7 +5,10 @@ "@@assign": "my_key" }, "tag_value": { - "@@assign": ["value1", "value2"] + "@@assign": [ + "value1", + "value2" + ] }, "enforced_for": { "@@assign": ["s3:bucket"] From d2482d7038ad9eb0a92137453d67a9310c367289 Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Thu, 18 Aug 2022 15:40:11 +0200 Subject: [PATCH 14/19] Adding new line as per code review --- .mega-linter.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.mega-linter.yml b/.mega-linter.yml index 628b567b6..b3aa98d29 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -22,6 +22,7 @@ ENABLE_LINTERS: # DISABLE: # - COPYPASTE # Comment to enable checks of excessive copy-pastes # - SPELL # Comment to enable checks of spelling mistakes + SHOW_ELAPSED_TIME: true FILEIO_REPORTER: false # DISABLE_ERRORS: true # Uncomment if you want MegaLinter to detect errors but not block CI to pass From 7bd5b793baeea50fb1bf96a66aa2b0fdf3ac7491 Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Thu, 18 Aug 2022 16:22:58 +0200 Subject: [PATCH 15/19] Solving merge conflicts --- samples/sample-fargate-node-app/index.js | 20 ++++++++++---------- samples/sample-serverless-app/template.yml | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/samples/sample-fargate-node-app/index.js b/samples/sample-fargate-node-app/index.js index 53f7ada70..0768bfeac 100644 --- a/samples/sample-fargate-node-app/index.js +++ b/samples/sample-fargate-node-app/index.js @@ -1,21 +1,21 @@ -const express = require('express') +const express = require('express'); -const app = express() +const app = express(); -app.set('view engine', 'ejs') -app.use(express.static('public')) +app.set('view engine', 'ejs'); +app.use(express.static('public')); app.get('/', (req, res) => { res.render('index', { region: process.env.REGION, environment: process.env.ENVIRONMENT - }) -}) + }); +}); app.get('/version', (req, res) => { - res.json({ version: '0.0.1' }) -}) + res.json({"version": "0.0.1"}); +}); app.listen(3000, () => { - console.log('Listening on 3000') -}) + console.log('Listening on 3000'); +}); diff --git a/samples/sample-serverless-app/template.yml b/samples/sample-serverless-app/template.yml index 96d25f947..b2f646238 100644 --- a/samples/sample-serverless-app/template.yml +++ b/samples/sample-serverless-app/template.yml @@ -11,6 +11,7 @@ Metadata: ignore_checks: # https://github.com/aws/serverless-application-model/issues/1590 - I3042 + Resources: ExampleServerlessApp: Type: 'AWS::Serverless::Function' From 93419bd887040347e73f7565bd5598fad3b30657 Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Thu, 18 Aug 2022 16:34:01 +0200 Subject: [PATCH 16/19] adding .prettierrc.js, it takes settings from editorconf unless overridden --- .prettierrc.js | 8 ++++++++ samples/sample-fargate-node-app/index.js | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 .prettierrc.js diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 000000000..519d6676c --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,8 @@ +module.exports = { + plugins: [ + '/node-deps/node_modules/prettier-plugin-multiline-arrays' + ], + trailingComma: 'es5', + semi: false, + singleQuote: true +} diff --git a/samples/sample-fargate-node-app/index.js b/samples/sample-fargate-node-app/index.js index 0768bfeac..53f7ada70 100644 --- a/samples/sample-fargate-node-app/index.js +++ b/samples/sample-fargate-node-app/index.js @@ -1,21 +1,21 @@ -const express = require('express'); +const express = require('express') -const app = express(); +const app = express() -app.set('view engine', 'ejs'); -app.use(express.static('public')); +app.set('view engine', 'ejs') +app.use(express.static('public')) app.get('/', (req, res) => { res.render('index', { region: process.env.REGION, environment: process.env.ENVIRONMENT - }); -}); + }) +}) app.get('/version', (req, res) => { - res.json({"version": "0.0.1"}); -}); + res.json({ version: '0.0.1' }) +}) app.listen(3000, () => { - console.log('Listening on 3000'); -}); + console.log('Listening on 3000') +}) From a3b574804487471eef141e141c1f93d499638f01 Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Fri, 19 Aug 2022 12:23:36 +0200 Subject: [PATCH 17/19] Addressing review comment on mega-linter gh workflow --- .github/workflows/mega-linter.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/mega-linter.yml b/.github/workflows/mega-linter.yml index 2c74691bd..de54d5bbc 100644 --- a/.github/workflows/mega-linter.yml +++ b/.github/workflows/mega-linter.yml @@ -6,7 +6,6 @@ name: MegaLinter on: [push, pull_request] env: - # Apply linter fixes configuration APPLY_FIXES: none APPLY_FIXES_EVENT: pull_request APPLY_FIXES_MODE: pull_request @@ -20,28 +19,21 @@ jobs: name: MegaLinter runs-on: ubuntu-latest steps: - # Git Checkout - name: Checkout Code uses: actions/checkout@v3 with: token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} fetch-depth: 0 - # MegaLinter - name: MegaLinter id: ml - # You can override MegaLinter flavor used to have faster performances - # More info at https://oxsecurity.github.io/megalinter/flavors/ uses: oxsecurity/megalinter@v6 env: # All available variables are described in documentation # https://oxsecurity.github.io/megalinter/configuration/ - # Set ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} to validate only diff with main branch VALIDATE_ALL_CODEBASE: true GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY - # Upload MegaLinter artifacts - name: Archive production artifacts if: ${{ success() }} || ${{ failure() }} uses: actions/upload-artifact@v2 @@ -51,7 +43,7 @@ jobs: megalinter-reports mega-linter.log - # Create pull request if applicable (for now works only on PR from same repository, not from forks) + # Create pull request if applicable (this only works on PRs from the same repository, not from forks) - name: Create Pull Request with applied fixes id: cpr if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix') @@ -67,7 +59,7 @@ jobs: echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" - # Push new commit if applicable (for now works only on PR from same repository, not from forks) + # Push new commit if applicable (this only works on PRs from the same repository, not from forks) - name: Prepare commit if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix') run: sudo chown -Rc $UID .git/ From 44ed3b065ecc975f6d6ce93e2cf738308d5b2d6c Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Fri, 19 Aug 2022 12:27:54 +0200 Subject: [PATCH 18/19] Updating build badges --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ac482d000..5be9ea72b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # AWS Deployment Framework -[![Build Status](https://travis-ci.org/awslabs/aws-deployment-framework.svg?branch=master)](https://travis-ci.org/awslabs/aws-deployment-framework) +[![Build Status](https://github.com/awslabs/aws-deployment-framework/workflows/ADF%20CI/badge.svg?branch=master)](https://github.com/awslabs/aws-deployment-framework/actions?query=workflow%3AADF%20CI+branch%3Amaster) + +[![MegaLinter](https://github.com/awslabs/aws-deployment-framework/workflows/MegaLinter/badge.svg?branch=master)](https://github.com/awslabs/aws-deployment-framework/actions?query=workflow%3AMegaLinter+branch%3Amaster) The AWS Deployment Framework *(ADF)* is an extensive and flexible framework to manage and deploy resources across multiple AWS accounts and regions within an From 6797cbcf828d8b36b0843af9431b1c927457af83 Mon Sep 17 00:00:00 2001 From: Javy de Koning Date: Fri, 19 Aug 2022 12:35:30 +0200 Subject: [PATCH 19/19] Updating CONTRIBUTING.md with editorconf and megalinter instructions --- CONTRIBUTING.md | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8fe7aa34d..2d5853c28 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,6 +36,24 @@ In order to run the tests locally you need a virtual environment that is used by 3. Install dependencies: `make init` 4. To run the tests, execute: `tox` + +## Running linters locally + +You need to have NodeJS and Docker installed on your computer to run MegaLinter locally with MegaLinter Runner. + +You can run mega-linter-runner without installation by using `npx` (Run from the root of the repository!). + +```sh +npx mega-linter-runner +``` + +Some linters can automatically fix findings by running the command below. + +```sh +npx mega-linter-runner --fix +``` + + ## Contributing via Pull Requests Contributions via pull requests are much appreciated. @@ -53,11 +71,13 @@ To send us a pull request, please: 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. -3. Ensure local tests pass. -4. Commit to your fork using clear commit messages. -5. Send us a pull request, answering any default questions in the pull request +3. Make sure your editor is configured to use [editorconfig](https://editorconfig.org/), + this helps maintain consistent coding styles and prevents linter findings later. +4. Ensure local tests and linters pass. +5. Commit to your fork using clear commit messages. +6. Send us a pull request, answering any default questions in the pull request interface. -6. Pay attention to any automated CI failures reported in the pull request, +7. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. GitHub provides additional document on