From 6622f58c447610e884866ffcba3ac6dff23b1039 Mon Sep 17 00:00:00 2001 From: Pedro Monteiro <83165668+pedroafmonteiro@users.noreply.github.com> Date: Wed, 18 Mar 2026 13:18:09 +0000 Subject: [PATCH] feat: fvm support (#383) * feat: added support for .fvmrc files, so it can fetch the flutter version from there * feat: changed README description of action to accomodate new changes --- README.md | 4 ++-- action.yaml | 4 ++-- setup.sh | 25 ++++++++++++++++++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3322676..6bd41f6 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ steps: - run: flutter --version ``` -### Use version from pubspec.yaml +### Use version from pubspec.yaml or FVM config This is inspired by [`actions/setup-go`](https://github.com/actions/setup-go). @@ -35,7 +35,7 @@ steps: uses: subosito/flutter-action@v2 with: channel: stable - flutter-version-file: pubspec.yaml # path to pubspec.yaml + flutter-version-file: pubspec.yaml # path to pubspec.yaml or .fvmrc or .fvm/fvm_config.json - run: flutter --version ``` diff --git a/action.yaml b/action.yaml index 905d086..2bc1ec8 100644 --- a/action.yaml +++ b/action.yaml @@ -15,7 +15,7 @@ inputs: required: false default: "" flutter-version-file: - description: The pubspec.yaml file with exact Flutter version defined + description: The pubspec.yaml or FVM config file with exact Flutter version defined required: false default: "" architecture: @@ -91,7 +91,7 @@ runs: # It's not preinstalled on Windows runners. # See https://github.com/actions/runner-images/issues/7443#issuecomment-1514597691 - name: Make yq tool available on Windows runners - if: runner.os == 'Windows' && inputs.flutter-version-file != '' + if: runner.os == 'Windows' && inputs.flutter-version-file != '' && !endsWith(inputs.flutter-version-file, '.fvmrc') && !endsWith(inputs.flutter-version-file, 'fvm_config.json') run: choco install yq shell: bash diff --git a/setup.sh b/setup.sh index 6100d42..0a01308 100755 --- a/setup.sh +++ b/setup.sh @@ -92,9 +92,11 @@ while getopts 'tc:k:d:l:pa:n:f:g:' flag; do n) VERSION="$OPTARG" ;; f) VERSION_FILE="$OPTARG" - if [ -n "$VERSION_FILE" ] && ! check_command yq; then - echo "yq not found. Install it from https://mikefarah.gitbook.io/yq" - exit 1 + if [ -n "$VERSION_FILE" ]; then + if [[ "$VERSION_FILE" != *".fvmrc" ]] && [[ "$VERSION_FILE" != *"fvm_config.json" ]] && ! check_command yq; then + echo "yq not found. Install it from https://mikefarah.gitbook.io/yq" + exit 1 + fi fi ;; g) GIT_SOURCE="$OPTARG" ;; @@ -110,11 +112,24 @@ if [ -n "$VERSION_FILE" ]; then exit 1 fi - VERSION="$(yq eval '.environment.flutter' "$VERSION_FILE")" + if [[ "$VERSION_FILE" == *".fvmrc" ]]; then + VERSION="$(jq -r '.flutter' "$VERSION_FILE")" + elif [[ "$VERSION_FILE" == *"fvm_config.json" ]]; then + VERSION="$(jq -r '.flutterSdkVersion // .flutter' "$VERSION_FILE")" + else + VERSION="$(yq eval '.environment.flutter' "$VERSION_FILE")" + fi + + if [[ "$VERSION" == "stable" ]] || [[ "$VERSION" == "beta" ]] || [[ "$VERSION" == "master" ]] || [[ "$VERSION" == "main" ]]; then + CHANNEL="$VERSION" + VERSION="any" + fi fi ARR_CHANNEL=("${@:$OPTIND:1}") -CHANNEL="${ARR_CHANNEL[0]:-}" +if [ -z "${CHANNEL:-}" ]; then + CHANNEL="${ARR_CHANNEL[0]:-}" +fi [ -z "$CHANNEL" ] && CHANNEL=stable [ -z "$VERSION" ] && VERSION=any