Working Directory for local github actions in subdirectory

Viewed 1816

I'm trying to keep multiple github actions in the same monorepo using subdirectories, and run them like:

workflow.yml

// [...]
jobs:
  run_my_script:
    runs-on: ubuntu-latest
    steps:
      - name: Check out current repo
        uses: actions/checkout@v2
      - uses: ./my_action2
        with:
          my_input_var: "david"

./my_action2/action.yml

// [...]
runs:
  using: "composite"
  steps:
    # Checkout files in this repo
    - name: Checkout
      uses: actions/checkout@v1

    - name: Run myscript
      run: python myscript.py "${{ inputs.my_input_var }}" # location: ./my_action2/myscript.py
      shell: bash

The problem I'm having is that my action uses a python script in it's subdirectory, but the uses: action appears to run from the GITHUB_WORKING_DIR of the workflow and not the directory of the action itself.

python: can't open file 'myscript.py': [Errno 2] No such file or directory

I've looked through most of the working-directory questions surrounding github actions, but I'm still stumped.

I've also tried adding working-directory: ./my_action2 to the job's defaults: but it looks like it's not propagating to run: commands within the uses: step.

My workaround in the meantime has been to add an input for myaction2_working_directory in the workflow, and then add working-directory: ${{ inputs.myaction2_working_directory }} to every run: command in the action. This seems inelegant and repetitive. Is there a better way to do this?

1 Answers

I had similar problem and for my composite actions I just added a first step as:

run: cd ${{ inputs.working_directory }}

and then all next steps are running in it. I couldn't find a better way and having working-directory copy pasted was also something I didn't like.

Related