git actions-examples

257 阅读1分钟

英文

  1. essential 基本的
  2. demonstrate 演示
  3. diagram 图表,图解
  4. capabilities 能力

文章

首先贴一张原文中workflow的流程图 示例流程图 这个示例展示了git actions的一些基本能力:

  1. on,事件触发自动执行工作流
  2. workflow_dispatch,从UI手动运行工作流,需要配置workflow_dispatch
  3. concurrency,控制同时多少workflow和job进行工作
  4. runs-on,设置不同runner上运行job
  5. 在runner里clone仓库代码,action/checkout
  6. 在runner上安装node,action/setup-node
  7. 在runner上使用三方action
  8. 在runner上使用script

示例配置如下,文章中进行逐句的讲解,大家自己看吧,我贴一下yml文件

name: 'Link Checker: All English'

# **What it does**: Renders the content of every page and check all internal links.
# **Why we have it**: To make sure all links connect correctly.
# **Who does it impact**: Docs content.

on:
  workflow_dispatch:
  push:
    branches:
      - main
  pull_request:

permissions:
  contents: read
  # Needed for the 'trilom/file-changes-action' action
  pull-requests: read

# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
  group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
  cancel-in-progress: true

jobs:
  check-links:
    runs-on: ${{ fromJSON('["ubuntu-latest", "self-hosted"]')[github.repository == 'github/docs-internal'] }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup node
        uses: actions/setup-node@v3
        with:
          node-version: 16.13.x
          cache: npm

      - name: Install
        run: npm ci

      # Creates file "$/files.json", among others
      - name: Gather files changed
        uses: trilom/file-changes-action@a6ca26c14274c33b15e6499323aac178af06ad4b
        with:
          fileOutput: 'json'

      # For verification
      - name: Show files changed
        run: cat $HOME/files.json

      - name: Link check (warnings, changed files)
        run: |
          ./script/rendered-content-link-checker.mjs \
            --language en \
            --max 100 \
            --check-anchors \
            --check-images \
            --verbose \
            --list $HOME/files.json

      - name: Link check (critical, all files)
        run: |
          ./script/rendered-content-link-checker.mjs \
            --language en \
            --exit \
            --verbose \
            --check-images \
            --level critical

文章来源

use script test code