如何使用 React 应用程序的 Github Actions 将徽章添加到 .readme

ANi*_*120 0 github-actions

假设我有一个基本的 github 操作来构建我的应用程序,然后将其部署到 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 }}
Run Code Online (Sandbox Code Playgroud)

如何使用此操作自动更新 .readme 上的“构建”徽章?如果操作成功,我想显示“构建通过”徽章,如果不成功,则显示“构建失败”徽章。您在哪里编写构建徽章的逻辑?

在运行操作之前,我是否需要在自述文件中包含徽章?

构建徽章是稳定的 url,还是会因运行时的操作而更改?

这是你甚至可以用 actions 来做的事情还是你需要使用 travis-ci ?

通常是为了深入了解这些徽章的工作原理以及如何将它们与 Github Actions 结合使用。

在此输入图像描述

Den*_*uev 5

以下是有关如何添加工作流程状态徽章的文档。

状态徽章代表一个图像 -.png该图像由 GitHub 自动更新 - 例如,如果您的工作流程是:

  • 成功徽章将为“绿色”并且状态为“成功”
  • 失败徽章将显示为“红色”并且状态为“失败”

徽章的第一部分是工作流的名称(属性name:或文件名)

您还可以使用 UI 生成徽章。在这个答案中查看更多内容。


问: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?

A:这是GitHub Action功能,不需要Travis-CI