subosito / flutter-action

Flutter environment for use in GitHub Actions. It works on Linux, Windows, and macOS.
MIT License
2.28k stars 202 forks source link

Regression: invalid `PUB_CACHE` variable on the windows runner when using git overrides in pubspec #278

Closed richardshiue closed 8 months ago

richardshiue commented 9 months ago

First and foremost congrats and thank you for maintaining this action.

Version

latest release (version 2.13.0)

Description

When specifying a dependency override in pubspec.yaml to a git ref, calls to flutter pub get and similar fail in the windows runner with the message:

Git error. Command: `git clone --mirror https://github.com/<repo>.git /c/Users/runneradmin/.pub-cache\git\cache\<repo>-<ref>`
stdout: 
stderr: fatal: destination path '/c/Users/runneradmin/.pub-cache\git\cache\<repo>-<ref>' already exists and is not an empty directory.
exit code: 128

I can reproduce with cache either empty (implying false) or true.

Adding this job before using the action fixes the issue.

- name: Export pub environment variable on Windows
  run: |
    if [ "$RUNNER_OS" == "Windows" ]; then
      echo "PUB_CACHE=$LOCALAPPDATA\\Pub\\Cache" >> $GITHUB_ENV
    fi
  shell: bash

I believe the problem is that https://github.com/subosito/flutter-action/pull/265 changes the caching to be two parts: one for the flutter and one for pub cache. However, the default directory for PUB_CACHE is set to $HOME/.pub-cache in all the runners, instead of only macOS and Ubuntu, and then the AppData version in Windows.

On a somewhat related note, I find that supplying a pub-cache-path argument produces a warning

Warning: Unexpected input(s) 'pub-cache-path', valid inputs are ['flutter-version', 'channel', 'cache', 'cache-key', 'pub-cache-key', 'cache-path', 'architecture']

As I understand it from looking at setup.sh, the logic for this parameter seems to be incomplete.

Solution

The solution is to set the value of $GITHUB_ENV's PUB_CACHE to %LOCALAPPDATA%\Pub\Cache if it's empty and the os is Windows. Or use pub-cache-path if it's supplied then export it to $GITHUB_ENV as normal.

Other

Other reports of this issue: