runner icon indicating copy to clipboard operation
runner copied to clipboard

github.action_path contains wrong path when used inside a container

Open WIStudent opened this issue 3 years ago • 1 comments

Describe the bug When using ${{ github.action_path }} inside a local composite action and calling this action in a job that runs inside a container, ${{ github.action_path }} gets resolved to /home/runner/work/ga-test-public/ga-test-public/./.github/actions/repro instead of /__w/ga-test-public/ga-test-public/./.github/actions/repro.

There are other closed issues describing the same problem (https://github.com/actions/runner/issues/716, https://github.com/actions/runner/issues/965) and a merged pull request (https://github.com/actions/runner/pull/1762) that should have fixed the issue, but I am still getting the wrong path on GitHub shared runners with version 2.297.0

To Reproduce Here is a reproduction repo and a workflow run with the mentioned issue.

# .github/workflow/test.yml
name: Reploduce the bug

on: 
  push: {}
  workflow_dispatch: {}

jobs:
  bug-in-container:
    runs-on: ubuntu-20.04
    container:
      image: centos:7
    steps:
      - uses: actions/checkout@v2
      - uses: ./.github/actions/repro

      - run: echo runner.temp = ${{ runner.temp }}
      - run: ls -al ${{ runner.temp }} || true

      - run: echo runner.tool_cache = ${{ runner.tool_cache }}
      - run: ls -al ${{ runner.tool_cache }} || true
# .github/actions/repo/action.yml
name: 'Reproduce the bug'
description: ''
inputs: {}
runs:
  using: 'composite'
  steps:
    - shell: bash
      run: |
        echo github.action_path: ${{ github.action_path }}
        ls -al ${{ github.action_path }} || true

Expected behavior ${{ github.action_path }} should be resolved to a path inside the container, not to a path on the host machine.

Runner Version and Platform

GitHub shared runner version 2.297.0

What's not working?

grafik

WIStudent avatar Oct 06 '22 14:10 WIStudent

Hey @WIStudent,

Thank you for reporting this! We are aware of this issue. The PR #1762 solved this issue, but there was a problem with hash files, executing from a host machine. We are still exploring the best way to achieve this. I will post an update here about the progress regarding this issue.

nikola-jokic avatar Oct 07 '22 10:10 nikola-jokic

What is end result in .yml file how to implement this change to .yml file

abhijeetdhoke avatar May 20 '23 03:05 abhijeetdhoke

Has there been any updates to this issue? This is blocking some internal workflows.

MSAdministrator avatar Jun 07 '23 04:06 MSAdministrator

Hey @MSAdministrator,

This PR is in review and as soon as it is in, and the feature flag is on, then it should be okay. Until then, can you try passing actions_path as an env. Env variables are translated so container paths so it should be okay if you can use it :relaxed:

nikola-jokic avatar Jun 07 '23 09:06 nikola-jokic

I was able to get it by just replacing the string using python

- name: Setup Path
      shell: bash
      run: |
        PROJ_NEW_PATH=$(python -c "print('${{github.action_path}}'.replace('./.', '.'))")
        echo "PROJ_NEW_PATH=$PROJ_NEW_PATH" >> $GITHUB_ENV

MSAdministrator avatar Jun 07 '23 15:06 MSAdministrator

@nikola-jokic any updates on this issue?

azlam-abdulsalam avatar Jun 28 '23 03:06 azlam-abdulsalam

We merged the PR so the next release should have this functionality :relaxed: . We also have a feature flag in case something goes wrong

nikola-jokic avatar Jul 03 '23 10:07 nikola-jokic

For anyone struggling with this:

Let's say you created a custom action with a script, with the script called run.sh and residing in the root of the action.

runs:
  using: composite
  steps:
    - name: Run script
      shell: bash
      run: ${GITHUB_ACTION_PATH}/run.sh

That will get it to work if you are running your build inside a container.

BitProcessor avatar Aug 18 '23 08:08 BitProcessor

This issue is still present on latest runner. See my test workflow here:

github.workspace=/home/runner/work/test-container-env/test-container-env
GITHUB_WORKSPACE=/__w/test-container-env/test-container-env
runner.temp=/home/runner/work/_temp
RUNNER_TEMP=/__w/_temp
RUNNER_CONTEXT: {
...
"tool_cache": "/opt/hostedtoolcache",
"temp": "/home/runner/work/_temp",
"workspace": "/home/runner/work/test-container-env"
}
 GITHUB_CONTEXT: {
    "workspace": "/home/runner/work/test-container-env/test-container-env",
    "event_path": "/home/runner/work/_temp/_github_workflow/event.json",
    "path": "/home/runner/work/_temp/_runner_file_commands/add_path_9a5f7639-e36c-409b-a5df-9fe4b1a53cdc",
    "env": "/home/runner/work/_temp/_runner_file_commands/set_env_9a5f7639-e36c-409b-a5df-9fe4b1a53cdc",
    "step_summary": "/home/runner/work/_temp/_runner_file_commands/step_summary_9a5f7639-e36c-409b-a5df-9fe4b1a53cdc",
    "state": "/home/runner/work/_temp/_runner_file_commands/save_state_9a5f7639-e36c-409b-a5df-9fe4b1a53cdc",
    "output": "/home/runner/work/_temp/_runner_file_commands/set_output_9a5f7639-e36c-409b-a5df-9fe4b1a53cdc"
}

nicola-lunghi avatar Oct 06 '23 13:10 nicola-lunghi