taneliang / Cotton

WIP Dependency management GitHub bot for Yarn projects
8 stars 1 forks source link

Cotton

Build Status Maintainability Test Coverage

Cotton is a serverless GitHub app which upgrades dependencies in projects which use Yarn. It is written in Node.js with the Serverless framework.

Features

Todo

Architecture

Cotton is deployed on AWS using the Serverless framework. It is comprised of 3 lambdas written as Serverless handlers. They invoke each other using the Amazon Simple Notification Service (SNS), and can also be invoked through their REST API endpoints.

Handlers

Contributing

Setup

  1. Clone this repo.
  2. Run cp .env.example .env at the repo root.
  3. Set up an AWS account if you haven't.
  4. Generate AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, following https://serverless.com/framework/docs/providers/aws/guide/credentials/.
  5. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in .env.
  6. Register a new GitHub App, following https://developer.github.com/apps/building-github-apps/creating-a-github-app/. Use dummy urls as required. Permission settings are as followed:
    • Repository contents: R&W
    • Issues: R&W
    • Repo metadata: R
    • PRs: R&W
    • Subscribe to events: Push, Issue comment, PR review, PR review comment
  7. Generate (securely, e.g. using a password manager) and set a webhook secret for the new app, and set GITHUB_WEBHOOK_SECRET in .env.
  8. Generate the private key following https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#generating-a-private-key.
  9. Download the key into the repo root and rename it "gh_priv_key.pem".
  10. Use the Github ID on the app settings page to set GITHUB_APP_ID in .env.
  11. Deploy the app by running yarn deploy.
  12. Once deployed, Serverless will output a few URLs. Set the GitHub App's Webhook URL to the githubWebhook POST endpoint by Serverless.

Development

Run yarn start. This starts a serverless-offline server, which simulates API Gateway locally. Note that the upgradeAllInstallations and upgradeInstallation handlers will fail to trigger their downstream lambdas as serverless-offline does not mock SNS.

Testing

Run yarn test. Tests are written with Jest.

Deployment

Run yarn deploy. This command uses serverless to deploy Cotton to AWS.