- Node JS
- AWS CLI
- Github user with personal access token, if you running test on public github, use this link to generate new token: https://github.com/settings/tokens
- Make sure your personal access token have at minimum scope of repo:status
- Github repository as source, you can clone fork this repository for quick start: https://github.com/fss18/example-cicd-ml
- S3 bucket to store the Lambda source code
- Extract the zip file
- Navigate to /lambda-src/cw_handler/
- Edit the config.json file, replace the token value with the Github personal token value
- Replace the secret value with 16 char random string
- Run
npm install --production
- Navigate to /lambda-src/webhook_handler/
- Edit the config.json file, replace the token value with the Github personal token value
- Replace the secret value with 16 char random string
- Run
npm install --production
- Navigate back to top directory
- Run the following command, replace BUCKET_NAME with the name of your S3 bucket
aws cloudformation package --template-file template.yml --s3-bucket BUCKET_NAME --output-template-file packaged.yml
- Run the following command, replace STACK_NAME with your preference and SOURCE_GITHUB_URL with your source github repo
aws cloudformation deploy --template-file packaged.yml --stack-name STACK_NAME --capabilities CAPABILITY_IAM --parameter-overrides GitHubRepoURL=SOURCE_GITHUB_URL
- Once the stack deployed successfully, look at the CloudFormation output to copy the API gateway URL.
- Go to your GitHub repository > Settings > Webhooks , and Add a new webhook
- Paste the API Gateway URL into the Payload URL
- Set content type to application/json
- Paste the secret value (from step 4 or 8) to Secret
- Choose “Let me select individual events” and pick “Pull requests” and if required “Pushes” as well.
To run test: simply push new commit or pull request and watch the comment added as the build start and finishes.
I am using reference from: https://github.com/widdix/github-bot, simplify the setup and replace axios with @octokit/rest