1

I am trying to setup a github actions bot that uses composite to build when the action runs. Notably, this isn't required, and I know that ncc would also achieve the same thing, but I'm curious if it's possible to make this work in a sustainable way.

For some context, I'm trying to run my alita-moore/EIP-Bot private action with the yaml script being...

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

And this currently runs with a given repo's workflow yaml being

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/[email protected]
        id: auto-merge-bot
        with:
          GITHUB-TOKEN: ${{ secrets.TOKEN }} 
          VERSION: 1.0.8

You may have noticed that before the npm ci && npm run build I first had to cd /home/runner/work/_actions/alita-moore/EIP-Bot/${{ inputs.VERSION }}

If you don't do this it'll throw the following error

Run alita-moore/[email protected]
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.

Is there a better way to do this?

2 Answers 2

9

You can use ${{github.action_path}} for the path of the directory containing the action definition file 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 | The path where your action is located. You can use this path to easily access files located in the same repository as your action. This attribute is only supported in composite run steps actions.

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

Sign up to request clarification or add additional context in comments.

Comments

1

The value for ${{ github.action_path }} is also available by default as the environment variable GITHUB_ACTION_PATH, so something like this is also an option:

[...]
- uses: actions/setup-python@v4
  with:
    python-version: '3.9'

- name: install-dependencies
      run: pip install -r $GITHUB_ACTION_PATH/requirements.txt
      shell: bash

This assumes the requirements.txt file is at the root of my composite actions directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.