0.0.10 • Published 1 year ago

pr_validation_codecommit v0.0.10

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

Automated Code Review with Pull requests in AWS Code Commit

Pull request validation is a part of CI pipeline that will be run whenever the PR is submitted. As a best practice, it is recommended that we run validation tests before merging the PR to the branch. A pull request validation step can run unit tests, build, code coverage etc. This will ensure that the PRs do not break the build or introduce any other issue. If the PR validation passes, then the changes are ready to be safely merged into the main branch.

Code Commit natively doesn’t support running validation tests on creation of a pull request, we can however trigger a lambda function that can run a code build project that will behave as our validation build. The pull request status can then be updated according to the validation build, we can approve and safely merge the PR if the build passed.

Install

Typescript/JavaScript:

npm i pr_validation_codecommit

How to Use

import { BuildSpec } from "aws-cdk-lib/aws-codebuild";
import { Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import * as pr from 'pr_validation_codecommit'

export class PullRequestValidationStack extends Stack {
    constructor(scope: Construct, id: string, props: StackProps) {
        super(scope, id)

        // build spec for validating angular app
        const angularValidationBuildSpec = {
            version: 0.2,
            env: {
                shell: "bash"
            },
            phases: {
                install: {
                    "runtime-versions": {
                        nodejs: 14
                    },
                    commands: [
                        "npm install",
                        "npm install -g @angular/cli"
                    ]
                },
                pre_build: {
                    commands: [
                        "node -v && npm -v"
                    ]
                },
                build: {
                    commands: [
                        "npm run build",
                        "npm run coverage"
                    ]
                }
            }
        }

        new pr.CodeCommitPrValidation(this, 'pr-validation',{
            config: [
                {
                    repoName: 'angular-app-repo',
                    projectConfig: {
                        buildSpec: BuildSpec.fromObject(angularValidationBuildSpec)
                    }
                }
            ]
        })
    }
}

Now when you create a PR it will trigger a codebuild project that would validate your PR. If the validation build passes, the PR will be approved and can be merged using the merge option on the PR. You can also watch the status of the validation build in the Activity tab of the PR.

You can also create PR validation builds for multiple repositories:

import { BuildSpec } from "aws-cdk-lib/aws-codebuild";
import { Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import * as pr from 'pr_validation_codecommit'

export class PullRequestValidationStack extends Stack {
    constructor(scope: Construct, id: string, props: StackProps) {
        super(scope, id)

        const angularValidationBuildSpec = // angular validation buildSpec
        const backendValidationBuildSpec = // backend validation buildSpec

        new pr.CodeCommitPrValidation(this, 'pr-validation',{
            config: [
                {
                    repoName: 'angular-app-repo',
                    projectConfig: {
                        buildSpec: BuildSpec.fromObject(angularValidationBuildSpec)
                    }
                },
                {
                    repoName: 'backend-app-repo',
                    projectConfig: {
                        buildSpec: BuildSpec.fromObject(backendValidationBuildSpec)
                    }
                }
            ]
        })
    }
}

API Reference

See API.md

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago