Badges for GCP Cloud Build
Automatically generating badges for build status on GCP Cloud Build. Badges are great!
Step 0. Star This Project
Without this step, other steps may fail with unknown reasons.
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
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:
Step 5: Add the Badge to GitHub README
Here are a set of badges that can possibly show up:
- The cloud build will trigger a pub-sub event with topic
- The Firebase Function in this project subscribes to the event in index.ts.
- The function reads build status and the repository info from the event data in build-info.ts.
- 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.
- The files are protected by Firebase Storage Security Rules in storage.rules.
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.
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.