Docker Container Action - How to persist files in workspace

Hi,

Can anybody help explain what I’m missing here?

I’m following this guide to run a docker container action, and trying to copy out the files.

It’s a pretty simple container action that runs a shell script like this:

# entrypoint.sh
cd $GITHUB_WORKSPACE
touch workspace.file
mkdir "workspace-folder"
ls -la

From the logs I see that both workspace.file and workspace-folder are created in the running container.

However, if I list the files using  ls  as the next step after the container, it seems that the workspace-folder has been persisted but workspace-file has not (after the container has exited)

# /.github/workflows/main.yml (excerpt)

steps:
      - uses: actions/checkout@v2
      - uses: ./.github/actions/my-action
      - run: ls -la $GITHUB_WORKSPACE

When using a docker container action, there are some volumes configured in docker run command. 

Files inside container under /github/workspace are mapped to runner workspace /home/runner/work/my-repo-name/my-repo-name . And files inside container under /github/home are mapped to /home/runner/work/_temp/_github_home in runner machine. 

The files you created in entrypoint.sh will be persisted after the container has exited but the empty folder will not. 

In your workflow yml file upload artifacts actions, the path you specifed is wrong. 

$GITHUB_WORKSPACE and $HOME is the right syntax in bash script , it could not be replaced in upload artifacts path input variable.  And $HOME in runner is point to /home/runner , it is not mapped to /github/home. You need to use /home/runner/work/_temp/_github_home instead. 

Please try my workflow file sample:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: ./.github/actions/my-action
      - run: ls -la $GITHUB_WORKSPACE
      - run: ls -la /home/runner/work/_temp/_github_home
      - uses: actions/upload-artifact@v2
        with:
          name: workspace_artifacts
          path: ${{github.workspace}}
      - uses: actions/upload-artifact@v2
        with:
          name: home-artifacts
          path: /home/runner/work/_temp/_github_home
1 Like

Thanks so much!  Can’t believe I didn’t think to look at that in the logs