setup-python: Cannot create directory ‘/opt/hostedtoolcache’ after recent release

Description:

The following error start happening after the recent action release:

2022-07-12T14:12:47.7158848Z ##[group]Run actions/setup-python@v4
2022-07-12T14:12:47.7159230Z with:
2022-07-12T14:12:47.7159527Z   python-version: 3.x
2022-07-12T14:12:47.7160059Z   token: ***
2022-07-12T14:12:47.7160394Z   update-environment: true
2022-07-12T14:12:47.7162682Z ##[endgroup]
2022-07-12T14:12:48.0166854Z Version 3.x was not found in the local cache
2022-07-12T14:12:48.3072207Z Version 3.x is available for downloading
2022-07-12T14:12:48.3074130Z Download from "https://github.com/actions/python-versions/releases/download/3.10.5-2452607758/python-3.10.5-linux-20.04-x64.tar.gz"
2022-07-12T14:12:49.1279090Z Extract downloaded archive
2022-07-12T14:12:49.1380950Z [command]/usr/bin/tar xz --warning=no-unknown-keyword -C /actions-runner/_work/_temp/2d83bfeb-a252-4083-95bf-6f30cffc5507 -f /actions-runner/_work/_temp/c2619dbf-23ad-46f0-9b07-baf06258c9c8
2022-07-12T14:12:52.2679935Z Execute installation script
2022-07-12T14:12:52.2887302Z Check if Python hostedtoolcache folder exist...
2022-07-12T14:12:52.2888180Z Creating Python hostedtoolcache folder...
2022-07-12T14:12:52.2921018Z ##[error]mkdir:
2022-07-12T14:12:52.2937518Z ##[error]cannot create directory ‘/opt/hostedtoolcache’
2022-07-12T14:12:52.2939104Z ##[error]: Permission denied
2022-07-12T14:12:52.2941609Z ##[error]The process '/usr/bin/bash' failed with exit code 1
2022-07-12T14:12:52.3294942Z Post job cleanup.

Action version:

v4

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version:

  • 3.10.5

Repro steps:

  setup-python:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: 3.x

Expected behavior:

Won’t error.

Actual behavior:

It errors.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 8
  • Comments: 24 (20 by maintainers)

Commits related to this issue

Most upvoted comments

@k24dizzle - Alternatively, you can use the context variable.

        env:
          AGENT_TOOLSDIRECTORY: ${{ runner.tool_cache }}
        uses: actions/setup-python@v4
        with:
          python-version: "3.11.0-beta.4"

We where having this issue while setting up our own runners with the ubuntu example in: https://github.com/philips-labs/terraform-aws-github-runner. We could fix it by making these changes to the ubuntu example: https://github.com/philips-labs/terraform-aws-github-runner/pull/2302/files

dsame

Fair enough, I guess I am probably looking at this trough the this would be better for my use case lens without seeing the bigger picture.

env: AGENT_TOOLSDIRECTORY: /home/actions/actions-runner/_work/_tool/

Hi, I am working on the same repo as @kenorb where we are using the setup-python GH action.

I ended up following the suggestion from @techman83:

       env:
          AGENT_TOOLSDIRECTORY: ${{ runner.tool_cache }}
        uses: actions/setup-python@v4
        with:
          python-version: "3.11.0-beta.4"

This really makes me wonder why AGENT_TOOLSDIRECTORY doesn’t default to the value of RUNNER_TOOL_CACHE if not set/defined instead of defaulting to /opt/hostedtoolcache.

Cf this comment from @techman83 :

Internally they use a TOOLCACHE_ROOT variable, which they set to RUNNER_TOOL_CACHE when AGENT_TOOLSDIRECTORY is not provided. If the same is implemented here, actions-python will behave in the same manner, and respect the path that is configured as part of the self hosted runner options.

That would make a lot more sense to me and by doing so we wouldn’t have to tinker with AGENT_TOOLSDIRECTORY when calling the action.

@dsame I don’t, I hope I have articulated clearly enough to show that this is a regression for self hosted users. Even though that regression technically aligns the behaviour of actions/setup-python with the documentation, I don’t think that is the best technical outcome here.

@k24dizzle just set AGENT_TOOLSDIRECTORY to any location the runner user has write permission to.

Namely for Pytjon-3.11.0-betat.4 as in the log above:

  env:
    AGENT_TOOLSDIRECTORY: /home/actions/actions-runner/_work/_tool/Python/3.11.0-beta.4/x64/