Skip to content
Automatically generating badges for build status on GCP Cloud Build.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
functions
.firebaserc
.gitattributes
.gitignore
LICENSE
README.md
cloudbuild.yaml
downloadable-url.png
firebase.json
storage.rules

README.md

Badges for GCP Cloud Build

Build Status Version GitHub

⬆️ Hey! This repository's build badge is generated by the service this repo provides.

Automatically generating badges for build status on GCP Cloud Build. Badges are great!

Tutorial

Step 0. Star This Project

Without this step, other steps may fail with unknown reasons.

Step 1. Setup Your GCP Cloud Build According to Google's Docs.

You need to setup build triggers for cloud build.

Step 2. Deploy This Project on Firebase.

Note: You need to deploy this service on a Firebase project that is bind to your GCP project that uses Cloud Build.

Option 1: Command Line (Easier)

Install Firebase Tools, sign in, and simply run firebase deploy.

Option 2: GCP Cloud Build (Fancier)

Fork this repository, and follow this tutorial to automatically push to Firebase.

Remember to edit cloudbuild.yaml and replace dev-sam with your project id and supply your own Firebase token.

This repository uses option 2.

Step 3. Trigger A Build

Step 4. Find the URL for the Badge in Firebase Storage Console

The file should be located inside badges-4-cloud-build/b/. Depending on whether the build is triggered from a repo or from storage, the name of the svg may be different.

You can find the downloadable URL here:

Downloadable URL

Step 5: Add the Badge to GitHub README

![Build Status](URL_OF_THE_BADGE)

Here are a set of badges that can possibly show up:

Build Status Build Status Build Status Build Status Build Status Build Status Build Status Build Status

Actual Workflow

  1. The cloud build will trigger a pub-sub event with topic cloud-builds.
  2. The Firebase Function in this project subscribes to the event in index.ts.
  3. The function reads build status and the repository info from the event data in build-info.ts.
  4. The function uses Shields to generate the badge and stores it in Firebase Storage. The build info is also stored privately in a JSON file in Firebase Storage.
  5. The files are protected by Firebase Storage Security Rules in storage.rules.

Customization

You can edit the build-info.ts file to change some config. For example, you can edit the switch block to change the color of the badge.

FAQ

Q: Why Firebase?

A: It is very convenient to setup and deploy, and Firebase can easily access many GCP resources. The security config for Firebase Storage is also very easy to understand.

Q: Is there a real world example to follow?

A: This repository is a very good example to use the service with Cloud Build. You can also check my website's frontend GitHub Repo and backend GitHub Repo, which also have build badges generated by this service.

Q: How can I contribute?

A: Just make a pull request.

Q: What's the purpose of the project?

A: I want to use GCP Cloud Build, and I like badges! Also I hope one day this project is no longer useful because Google has developed a fully managed solution for this.

You can’t perform that action at this time.