-
Notifications
You must be signed in to change notification settings - Fork 976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
github.workspace and runner.workspace are incorrect inside container jobs #2058
Comments
Hi @tspascoal, Thanks for reporting this issue. We've investigated this issue before and are working on resolving it 👍 2022-08-22 Update: Correctly translating github.workspace causes some regressions, considering introducing |
Hello @fhammerl, Did you make any progress on this issue ? |
Has anyone figured out a workaround for this? |
GitHub runner open issue: actions/runner#2058 $ echo ${{ github.workspace }} /home/runner/work/<REPO_NAME>/<REPO_NAME> $ echo $GITHUB_WORKSPACE /__w/<REPO_NAME>/<REPO_NAME
We've started experiencing same issues since we moved to running jobs inside containers and what was the most interesting is the fact that we used in all cases build:
name: Build, Test & Publish
runs-on: self-hosted
container:
image: internalregistry.io/internal-image:3
steps:
- uses: actions/checkout@v3
- name: Build, Test and analyze
shell: bash
run: |
dotnet test
- name: Publish
shell: bash
run: |
for f in $(find src -name '*.csproj'); do
d=$(dirname $f)
outputFolder=${{ github.workspace }}/${{ env.ARTIFACT }}/$d
( cd "$d" && dotnet publish --no-self-contained -c $BUILD_CONFIGURATION -o $outputFolder )
done
- name: Publish artifacts
uses: actions/upload-artifact@v3.1.1
with:
name: ${{ env.ARTIFACT }}-v${{ github.run_number }}
retention-days: 1
path: ${{ github.workspace }}/${{ env.ARTIFACT }}/src
if-no-files-found: error And
Then we changed workflow to this to overcome this problem and it started working: build:
name: Build, Test & Publish
runs-on: self-hosted
container:
image: internalregistry.io/internal-image:3
steps:
- uses: actions/checkout@v3
- name: Build, Test and analyze
shell: bash
run: |
dotnet test
- name: Publish
shell: bash
run: |
echo "GITHUB_WORKSPACE=$GITHUB_WORKSPACE" >> $GITHUB_ENV
for f in $(find src -name '*.csproj'); do
d=$(dirname $f)
outputFolder=${{ env.GITHUB_WORKSPACE }}/${{ env.ARTIFACT }}/$d
( cd "$d" && dotnet publish --no-self-contained -c $BUILD_CONFIGURATION -o $outputFolder )
done
- name: Publish artifacts
uses: actions/upload-artifact@v3.1.1
with:
name: ${{ env.ARTIFACT }}-v${{ github.run_number }}
retention-days: 1
path: ${{ env.GITHUB_WORKSPACE }}/${{ env.ARTIFACT }}/src
if-no-files-found: error Now paths in both steps look similar: |
I started using Artifacts.
In the second Job, download the file in order to use it.
After all other tasks: Delete the artifact, we dont want to keep it outside of the job run
The infra people at our organisation wanted the workers to be ephermeral and not link in storage. |
…poke action to validate env var config and that this issue is handled: actions/runner#2058
…poke action to validate env var config and that this issue is handled: actions/runner#2058
…poke action to validate env var config and that this issue is handled: actions/runner#2058
…poke action to validate env var config and that this issue is handled: actions/runner#2058
…poke action to validate env var config and that this issue is handled: actions/runner#2058
…poke action to validate env var config and that this issue is handled: actions/runner#2058
…poke action to validate env var config and that this issue is handled: actions/runner#2058
…poke action to validate env var config and that this issue is handled: actions/runner#2058
…poke action to validate env var config and that this issue is handled: actions/runner#2058
…poke action to validate env var config and that this issue is handled: actions/runner#2058
…poke action to validate env var config and that this issue is handled: actions/runner#2058
…poke action to validate env var config and that this issue is handled: actions/runner#2058
…poke action to validate env var config and that this issue is handled: actions/runner#2058
…poke action to validate env var config and that this issue is handled: actions/runner#2058
The former resolves to a non-existing path. See actions/runner#2058
It's almost 2 years, you could at least update the documentation, so people would not hit this bug. |
I got a nice workaround for this, thanks to Pi AI for the help, by using working-directory directive for the container and for the steps, like:
Then beware to not use ${{github.workspace}} directly in the run commands, just use the working-directory directive instead. |
Any update on this? Even when setting a custom environmental variable, the runner actions strips this out during run-time: Run echo "CUSTOM_WORKSPACE=/actions-runner/_work/<repo>/<repo>" >> $GITHUB_ENV
echo "CUSTOM_WORKSPACE=/actions-runner/_work/<repo>/<repo>" >> $GITHUB_ENV
shell: sh -e {0} Run echo "CUSTOM WORKSPACE: $CUSTOM_WORKSPACE"
echo "CUSTOM WORKSPACE: $CUSTOM_WORKSPACE"
echo "github.workspace: /actions-runner/_work/<repo>/<repo>"
shell: sh -e {0}
env:
CUSTOM_WORKSPACE: /actions-runner/_work/<repo>/<repo>
CUSTOM WORKSPACE: /__w/<repo>/<repo>
github.workspace: /actions-runner/_work/<repo>/<repo> Is there any solution to the runner referencing an absolute directory on the host? I'm running a docker container that needs to mount checked out directories. |
If anyone comes across this, a fix that works but could be better is the following: - name: Set abs-path file
run: |
echo "${{ github.workspace }}" >> abs-path
cat abs-path
|
Github actions is broken and expands ${{ github.workspace }} to different paths depending on context: actions/runner#2058
Not affiliated with GitHub but I think it is fair to assume that this inconsistency will never be fixed as it would break containers and actions that depend on the current behaviour. |
@st3fan never say never. That's what major version upgrades are for. That way, it would be OK. |
instead of ${{ github.workspace }} due to a bug in the runner where $GITHUB_WORKSPACE and ${{ github.workspace }} are not the same when running inside a container. See actions/runner#2058
Describe the bug
github.Workspace
andrunner.Workspace
don't point to container valid paths when executing inside a container job.The values are also inconsistent with the values for env variables
GITHUB_WORKSPACE
andRUNNER_WORKSPACE
(both contain a valid path.To Reproduce
Steps to reproduce the behavior:
Expected behavior
On the container job
github.workspace
andrunner.workspace
should point to a path in the directory/__w
Runner Version and Platform
Version of your runner? 2.295.0
OS of the machine running the runner? ubuntu 20.04.4 (ubuntu-latest)
What's not working?
The values for
github.workspace
andrunner.workspace
are incorrect in the container job (and inconsistent with respective env variables)Job Log Output
If applicable, include the relevant part of the job / step log output here. All sensitive information should already be masked out, but please double-check before pasting here.
Output of container
dump
step in the container jobRunner and Worker's Diagnostic Logs
If applicable, add relevant diagnostic log information. Logs are located in the runner's
_diag
folder. The runner logs are prefixed withRunner_
and the worker logs are prefixed withWorker_
. Each job run correlates to a worker log. All sensitive information should already be masked out, but please double-check before pasting here.The text was updated successfully, but these errors were encountered: