GitHub Actions by Example: Actions

Actions 提供可重用的“代码”来减少工作流步骤。 对于正常任务: 使用 uses 关键词运行一个 action 使用以下格式指向一个GitHub仓库 {仓库持有者id}/{仓库名}@{ref} or {仓库持有者id}/{仓库名}/{路径}@{ref} 如果工作流位于子目录下,ref 可以是分支(branch),标签(tag)或者SHA。

GitHub官方提供了许多常用的actions。详见

name: actions-example
on:
  push:
jobs:
  use-actions:
    runs-on: ubuntu-latest
    steps:

checkout 检出你的仓库(触发工作流的ref)文件至工作目录(例:被推送的分支)。

      - uses: actions/checkout@v2

setup-node 使npm和node在接下来的步骤中可用。

      - uses: actions/setup-node@v1

一些actions也需要可选的或必须的参数。

        with:
          node-version: '15.8.0'
      -
        name: Install repo dependencies
        run: npm install
      -
        name: Run script from repo
        run: node helloWorld.js

下一个例子:Environment Variables