github-actions - 复合 github 动作,自动 cd 进入动作目录?
问题描述
我正在尝试设置一个 github 操作机器人,它在操作运行时使用复合来构建。值得注意的是,这不是必需的,我知道 ncc 也可以实现相同的目标,但我很好奇是否有可能以可持续的方式进行这项工作。
在某些情况下,我正在尝试使用 yaml 脚本运行我的alita-moore/EIP-Bot私人操作...
name: "Auto Merge EIP"
description: "A bot that lints EIP edits, finds common errors, and can auto-merge"
inputs:
GITHUB-TOKEN:
description: |-
The Github token to be used by this bot when merging, posting comments, or requesting reviewers
required: true
VERSION:
description: version of the action; this is required because of how actions work
required: true
runs:
using: "composite"
steps:
- run: cd /home/runner/work/_actions/alita-moore/EIP-Bot/${{ inputs.VERSION }} && npm ci && npm run build && GITHUB_TOKEN=${{ inputs.GITHUB-TOKEN }} node build/index.js
shell: bash
这目前使用给定 repo 的工作流 yaml 运行
on: [pull_request]
jobs:
auto_merge_bot:
runs-on: ubuntu-latest
name: EIP Auto-Merge Bot
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js Enviornment
uses: actions/setup-node@v2
with:
node-version: '14'
- name: auto-merge-bot
uses: alita-moore/EIP-Bot@1.0.8
id: auto-merge-bot
with:
GITHUB-TOKEN: ${{ secrets.TOKEN }}
VERSION: 1.0.8
您可能已经注意到,在npm ci && npm run build
我第一次必须cd /home/runner/work/_actions/alita-moore/EIP-Bot/${{ inputs.VERSION }}
如果你不这样做,它会抛出以下错误
Run alita-moore/EIP-Bot@1.0.1
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/runner/work/EIPs/EIPs/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/runner/work/EIPs/EIPs/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2021-03-14T09_02_26_002Z-debug.log
Error: Process completed with exit code 254.
有一个更好的方法吗?
解决方案
您可以使用${{github.action_path}}
包含操作定义文件的目录的路径action.yaml
:
[...]
runs:
using: "composite"
steps:
- run: cd ${{github.action_path}} && npm ci && npm run build && GITHUB_TOKEN=${{ inputs.GITHUB-TOKEN }} node build/index.js
shell: bash
github.action_path
|string
| 您的操作所在的路径。您可以使用此路径轻松访问与您的操作位于同一存储库中的文件。此属性仅在复合运行步骤操作中受支持。
推荐阅读
- vuejs2 - 如何在使用 vue-cli3 创建的 Vue2 项目中使用 axios
- javascript - 通过 UID 定位对象的递归 JavaScript 函数
- mysql - 连接到多个mysql数据库时连接初始化顺序很重要的可能原因
- c# - 为什么要从最高到最低打印数字?
- google-apps-script - 在导入范围的动态数据列旁边添加值
- javascript - 我如何测试我的脚本以删除 cookie
- java - 错误:无法在类路径中找到类:testCases.MyClassName & 删除 .m2 后类中的错误
- namespaces - 无法在具有命名空间的 Lightning 容器中加载静态资源
- c# - Web API 上传文件,然后在一个 Web API 请求中处理和下载文件
- azure - 如何获取从 webhook 开始的 Azure Runbook 的响应?