cloud-build-badge

1.4.1 • Public • Published

cloud-build-badge

npm version License

Automate the creation of Google Cloud Build badges for your project! Cloud builds in the Google Cloud Platform are fun, but unlike Travis, Circle-CI, and AppVeyor, it doesn't provide badges out-of-the-box. This small script aims to provide a solution.

(This is a fork of sbsends/cloud-build-badge that solves the same problem using sed commands and environment variables. My aim is to provide a more "JS-native" solution)

I also wrote a blog post tutorial for creating Cloud Build badges. Read it here

Setup

The first three steps ensure that we have the required badges in our project's cloud storage. The last step simply install this package in your system.

  1. Ensure that you have the Google Cloud SDK installed in your system.
  2. In your project, create a Google Cloud Storage bucket (referred to as ${BUCKET}), and make a folder named build.
  3. Inside build/, save an SVG copy of the SUCCESS and FAILURE badges. You can create your own here, or you can just copy and save from here (success, failure).
  4. Install cloud-build-badge via npm:
$ npm install cloud-build-badge

Deploy

It only takes three steps to start deploying your cloud badges! First we create the deploy script, then we call gcloud functions to send it over to GCP, then we put the resulting badge in our project's README

  1. Run cloud-build-badge and supply the following arguments:
--id            deploy function unique ID
--repository    target repository name
--branches      target branches, e.g. master, development
--bucket        name of bucket, e.g. ${BUCKET}

For example,

cloud-build-badge \
    --id myFunction \
    --repository my-repository \
    --branches master development # You can supply multiple values 
    --bucket my-project-bucket

This will generate a JS file (default is function.js) that contains the deploy function that we'll need.

  1. Copy the resulting command to deploy via gcloud functions. As reference, here's what it looks like:
gcloud functions deploy <ID> \
    --runtime nodejs6 \
    --trigger-resource cloud-builds \
    --trigger-event google.pubsub.topic.publish
  1. You'll find the resulting badge saved inside your project's GCS bucket! You can then use it for your README's badge! This badge, through Cloud Functions, will change depending on the status of your latest build.
[![cloud build status](https://storage.googleapis.com/<BUCKET>/build/<REPOSITORY>-<BADGE>.svg)](https://github.com/ljvmiranda921/cloud-build-badge)

Package Sidebar

Install

npm i cloud-build-badge

Weekly Downloads

0

Version

1.4.1

License

Apache-2.0

Unpacked Size

20.8 kB

Total Files

9

Last publish

Collaborators

  • ljvmiranda921