0

Let's say I have a basic github action that builds my application, then deploys it to firebase:

name: Firebase Deploy
on:
  push:
    branches:
      - master
jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v2.3.2
      - name: Install Dependencies
        run: npm install
      - name: Run Tests
        env:
          CI: true
        run: npm test
      - name: Build
        run: npm run build
      - name: Archive Production Artifact
        uses: actions/upload-artifact@v2
        with:
          name: build
          path: build
  deploy:
    name: Deploy
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v2.3.2
      - name: Download Artifact
        uses: actions/download-artifact@v2
        with:
          name: build
          path: build
      - name: Deploy to Firebase
        uses: w9jds/firebase-action@master
        with:
          args: deploy --only hosting
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

How do I use this action to automatically update the "build" badge on my .readme? If the action is successful, I'd like to display a "build passing" badge, if it is not, a "build fail" badge. Where do you write the logic for the build badges?

Do I need to have the badge in my readme before I run the action?

Is the build badge a stable url, or is it changed by the action at runtime?

Is this something you can even do with actions or do you need to use travis-ci?

Generally looking for insight into how these badges work and how to use them with Github Actions.

enter image description here

ANimator120
  • 2,556
  • 1
  • 20
  • 52
  • As far as I know, these are only images. Like . Your build script will exchange the image with its actual status. I am not very sure about this, that's why only a comment instead of an answer – Michael Walter Apr 12 '21 at 03:04

1 Answers1

5

Here is documentation for how to add a workflow status badge.

The status badge represents an image - .png this image is automatically updated by GitHub - e.g if your workflow is:

  • successful the badge will be "green" and the status "success"
  • failing the badge will be "red" and the status "failed"

The first part of the badge is the name of the workflow (either the name: attribute or the name of the file)

You can also use the UI to generate a badge. See more in this answer.


Q: Do I need to have the badge in my readme before I run the action?

A: No you can add it anytime, if you add it before the workflow it shows no information (gray coloring). Keep in mind that you may need to "force refresh" the browser to see the new image (browser caching images)


Q: Is the build badge a stable url, or is it changed by the action at runtime?

A: It is as stable as the name of the workflow - if you change the name the badge will stop working.


Q: Is this something you can even do with actions or do you need to use travis-ci?

A: It is GitHub Action functionality, you do not need Travis-CI

Denis Duev
  • 513
  • 3
  • 5