Trigger GitHub actions in AWS CodePipeline
This is the source code for an AWS Lambda function that can be used as a CodePipeline step to create and optionally merge a GitHub pull request between branches. This is most useful as part of a continuous integration flow between a staging pipeline and a production pipeline.
To use this in your own CodePipeline you can build the project and upload it to your own S3 bucket, or you can reference the latest build at s3://lightrail-public-resources/cloudformation/codepipeline-github-action/2020-03-17.zip
This function uses the following environment variables:
GITHUB_REPO_OWNER
- The owner of the GitHub repo to create a pull request in. eg: Giftbit in https://github.com/Giftbit/codepipeline-github-action
GITHUB_REPO
- The GitHub repo to create a pull request in. eg: codepipeline-github-action in https://github.com/Giftbit/codepipeline-github-action
GITHUB_SOURCE_BRANCH
- The GitHub branch to pull from (head).
GITHUB_DEST_BRANCH
- The GitHub branch to pull to (base).
GITHUB_OAUTH
- The github oauth token for the GitHub user to run the commands as. This value must be KMS encrypted and the lambda function must have permission to decrypt. See the example CloudFormation template linked below on how this is best configured.
AUTO_MERGE
(optional)- If
true
automatically merge the created pull request.
- If
PULL_REQUEST_MESSAGE
(optional)- The message to apply to the pull request. Defaults to
"Automatic pull request by CI"
.
- The message to apply to the pull request. Defaults to
MERGE_MESSAGE
(optional)- The message to apply to the merge, if
AUTO_MERGE
istrue
. Defaults to"Automatic merge by CI"
.
- The message to apply to the merge, if
Check out Giftbit/sam-scaffold for an example CloudFormation template that uses this function.
The only external dependency is node >= 10. The source code is written in TypeScript.
From the command line npm install && npm run build
to build the distribution zip file, which will be at dist/dist.zip
.