【问题标题】:composite github action, automatically cd into actions directory?复合 github 动作,自动 cd 进入动作目录?
【发布时间】:2021-03-14 23:01:48
【问题描述】:

我正在尝试设置一个 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-actions


    【解决方案1】:

    动作定义文件action.yaml所在目录的路径可以使用${{github.action_path}}

    [...]
    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 |您的操作所在的路径。您可以使用此路径轻松访问与您的操作位于同一存储库中的文件。此属性仅在复合运行步骤操作中受支持。

    https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context

    【讨论】:

      猜你喜欢
      • 2017-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-30
      • 2022-10-09
      • 2012-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多