Git Product home page Git Product logo

pr-automation-with-s3's Introduction

Static Site Automation

What it is?

This Gihub action that uses the golang aws sdk to build s3 bucket and attach policy for static website deploy the static file to that newly created s3 bucket and comment the url to the PR. To deploy static file it uses either from your repository or build during your workflow. There is self hosted tool, if Github action is not feasible.

Best for?

  • Immediate feedback visually to developers or anyone interested in changes.
  • Reduce burden of having to build application for QA and verify the changes.
  • Faster iterations.

How to use?

Add .yml file/s such as given examples in your .github/workflows folder. Refer to the documentation on workflow YAML syntax here.

The following example will:
  • Create s3 bucket and attach policy for static site
  • Build the javascript/typescript frontend application with the help of given command (ex: BUILD_COMMAND="yarn build")
  • Upload build file (static site) to s3
  • Comment the URL of the static site to the Pull Request
  • Delete the aws S3 bucket after PR is merged
Config file: .github/workflows/deploy-on-pr.yml
name: Deploy site to S3 And add comment to PR and delete after merge

on:
  pull_request:
    branches:
    - master

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: Static site deploy to s3 and comment on PR
      uses: razzkumar/[email protected]
      env:
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN}}
        AWS_REGION: 'us-east-2'     # optional: defaults to us-east-2
        SRC_FOLDER: 'build'         # optional: defaults to build (react app)
        IS_BUILD: 'true'            # optional: defaults to true
        ACTION: "create"            # optional: defaults to create (option:create,delete and deploy)
        BUILD_COMMAND: "yarn build" # optional: defaults to `yarn build`
Config file: .github/workflows/cleanup-on-pr-merge.yml
name: Delete S3 bucket after PR merge

on:
  pull_request:
    types: [closed]

jobs:
  delete:
    runs-on: ubuntu-latest
    steps:
    - name: Clean up temperory bucket
      if: github.event.pull_request.merged == true
      uses: razzkumar/[email protected]
      env:
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        AWS_REGION: 'us-east-2'     # optional: defaults to us-east-2
        ACTION: "delete"            # Action must be delete to delete

Configuration

The following settings must be passed as environment variables as shown in the example. Sensitive information, especially GH_ACCESS_TOKEN,AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, should be set as encrypted secrets โ€” otherwise, they'll be public to anyone browsing your repository's source code and CI logs.

Key Value Suggested Type Required Default
GH_ACCESS_TOKEN Your Github access token used while commenting PR secrect env YES/NO If ACTION: create then it's required,otherwise it's optional NA
AWS_ACCESS_KEY_ID Your AWS Access Key. More info here. secret env Yes N/A
AWS_SECRET_ACCESS_KEY Your AWS Secret Access Key. More info here. secret env Yes N/A
AWS_S3_BUCKET The name of the bucket you're syncing to. For example, jarv.is or my-app-releases. secret env YES/NO - If running on PR it will genereat by tool PR-Branch.prPR-number.auto-deploy - In the case of depoyment it required
AWS_REGION The region where you created your bucket. Set to us-east-2 by default. Full list of regions here. env No us-east-2
SRC_FOLDER The local directory (or file) you wish to deploy to S3. For example, public. Defaults to build. env No build (based on react app)
IS_BUILD This is the flag that indicate that build a project or not env No true (It will run yarn && yarn build by default)
ACTION This is also a flag that indicate what to do (create:-create s3 (if not exist) bucket,build react and comment on PR,deploy:helps to deploy to s3,delete: delete the s3 bucket) env No create (It will create s3 (if not exist),built the app, deploy to s3 and comment URL to PR`)
BUILD_COMMAND How to build the react app if its npm run build then it will run npm install && npm run build env No yarn build (It will run yarn && yarn build by default)

Note for S3 Bucket creation

  • It only create a s3 bucket if not exist
  • While Creating bucket for the pull_request S3 bucket name will be: PR-Branch.prPR-number.auto-deploy
    • For Eg.:
      • if base branch is SIG-1000 and PR number is 23 the the bucket name will be sig-100.pr23.auto-deploy
  • If we deploy app on push or (not on pull requst) like prebuild app deployment, app build and deploy then the bucket name will be $AWS_S3_BUCKET.auto-deploy
    • For Eg.
      • if AWS_S3_BUCKET=dev-test-deployment then bucket will be dev-test-deployment.auto-deploy

TODO

  • Add tests
  • Add option to deploy on aws cloudfront
  • Design PR comment done by tool
  • Maintain code quality

Contributing

Feel free to send pull requests

License

This project is distributed under the MIT license

HitCount

pr-automation-with-s3's People

Contributors

razzkumar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.