Coder Social home page Coder Social logo

cloud-build-on-prs's Introduction

Cloud Build on PRs

Cloud Build on PRs is a GitHub App designed to trigger Google Cloud Build builds when GitHub pull requests are opened or new commits are pushed to them.

The main differences with the official Google Cloud Build GitHub App are:

  • Builds are only triggered for commits associated to an open PR, rather than all commits pushed to all branches
  • It can trigger different types of builds (manifest files) depending on which files changed in the PR
  • It can trigger multiple parallel builds, each appearing as an individual check on GitHub

Configuration

The configuration of each build type can be set in file cloud-functions/github-pr-update/src/config/builds.ts.

Example config

Each build type has a label, which will appear in GitHub's checks list, a corresponding manifest file, and a list of paths to watch for changes in order to trigger the build. A specific path can be watched by different build types, perfect for files that are shared across different projects.

How it works

This project uses the GitHub and Google Cloud Build APIs and is deployed as two Google Cloud Functions: github-pr-update and cloudbuild-update.

In order to use GitHub's checks API, the cloud functions authenticate as the installation of the "Cloud Build on PRs" GitHub App.

The desired functionality is:

  1. Using the GitHub PR Webhook, detect when a PR is either opened or new commits are pushed to it
  2. Use the GitHub API to list which files from this PR are changed
  3. Based on these files, identify which of our projects have changed
  4. Use the Google Cloud API to launch cloud builds using the manifests from the projects with changes
  5. Use the GitHub API to create a check run to update the build status (in progress, failed, success) of the latest PR commit
  6. Update the status of the check run whenever the cloud build's status is updated, by listening to Cloud Build PubSub messages

Sequence diagram

Deploying to Google Cloud Functions

Google Cloud Functions are not automatically re-deployed on new git commits. You must manually redeploy them if any changes are made. A change to the manifests however doesn't require a redeploy.

For both github-pr-update and cloudbuild-update projects:

  1. Build the project: yarn build.
  2. Push the dist folder to git.
  3. Trigger a Cloud Function deployment from the GCP console by clicking "Edit" then "Save".

The following environment variables must be set for the cloud functions to run:

  • GITHUB_OWNER: The GitHub repo's owner (user or organization name)
  • GITHUB_APP_ID: The GitHub App's ID
  • GITHUB_APP_PRIVATE_KEY: The GitHub App's private key

cloud-build-on-prs's People

Stargazers

BBA avatar Alex Hester avatar Paramanantham Harrison avatar David Fernandez avatar Pascal Giguère avatar Arach Tchoupani avatar Mathieu Breault (Matt) avatar Amanda Wai avatar Martin Carel avatar robin avatar Niels Hofmans avatar

Watchers

Jean-Francois Couture avatar James Cloos 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.