feat(setup-flutter): auto-resolve Flutter version from FVM config
Update README Actions Table / update-readme (push) Successful in 9s

This commit is contained in:
2026-10-13 12:32:13 -07:00
parent 163e593d26
commit 387645e9b6
+48 -13
View File
@@ -2,9 +2,9 @@ name: 'Setup Flutter'
description: 'Cross-platform setup for Flutter with local mirror and multi-runner concurrency support.'
inputs:
version:
description: 'Flutter channel, version tag, or commit hash (e.g., master, stable, 3.29.0, 4ebf37fe7df0a130ba5bee17315b98f905c10b34)'
description: 'Flutter channel, version tag, or commit hash (e.g., master, stable, 3.29.0, 4ebf37fe7df0a130ba5bee17315b98f905c10b34). If omitted, automatically detected from .fvmrc or .fvm/fvm_config.json.'
required: false
default: 'master'
default: ''
mirror_url:
description: 'Git repository URL for Flutter SDK'
required: false
@@ -25,6 +25,22 @@ runs:
if: runner.os != 'Windows'
shell: bash
run: |
TARGET_VERSION="${{ inputs.version }}"
if [ -z "$TARGET_VERSION" ]; then
if [ -f ".fvmrc" ]; then
TARGET_VERSION=$(grep -o '"flutter"[[:space:]]*:[[:space:]]*"[^"]*"' .fvmrc | head -n 1 | sed -E 's/.*"flutter"[[:space:]]*:[[:space:]]*"([^"]*)".*/\1/')
elif [ -f ".fvm/fvm_config.json" ]; then
TARGET_VERSION=$(grep -o '"flutterSdkVersion"[[:space:]]*:[[:space:]]*"[^"]*"' .fvm/fvm_config.json | head -n 1 | sed -E 's/.*"flutterSdkVersion"[[:space:]]*:[[:space:]]*"([^"]*)".*/\1/')
if [ -z "$TARGET_VERSION" ]; then
TARGET_VERSION=$(grep -o '"flutter"[[:space:]]*:[[:space:]]*"[^"]*"' .fvm/fvm_config.json | head -n 1 | sed -E 's/.*"flutter"[[:space:]]*:[[:space:]]*"([^"]*)".*/\1/')
fi
fi
fi
if [ -z "$TARGET_VERSION" ]; then
TARGET_VERSION="master"
fi
echo "Resolved Flutter version: $TARGET_VERSION"
LOCK_DIR="/opt/hostedtoolcache/flutter-sdk-setup.lock"
if [ ! -d "/opt/hostedtoolcache" ] || [ ! -w "/opt/hostedtoolcache" ]; then
LOCK_DIR="${TMPDIR:-/tmp}/flutter-sdk-setup.lock"
@@ -55,16 +71,16 @@ runs:
git clone https://github.com/flutter/flutter.git "$SDK_DIR"
}
git -C "$SDK_DIR" config --global --add safe.directory "$SDK_DIR" || true
git -C "$SDK_DIR" checkout "${{ inputs.version }}"
git -C "$SDK_DIR" checkout "$TARGET_VERSION"
else
git -C "$SDK_DIR" config --global --add safe.directory "$SDK_DIR" || true
CURRENT_COMMIT=$(git -C "$SDK_DIR" rev-parse HEAD 2>/dev/null || true)
if [ "$CURRENT_COMMIT" != "${{ inputs.version }}" ] && [ "${{ inputs.version }}" != "master" ]; then
echo "Checking out Flutter ${{ inputs.version }}..."
git -C "$SDK_DIR" fetch origin "${{ inputs.version }}" --depth=1 2>/dev/null || git -C "$SDK_DIR" fetch origin
git -C "$SDK_DIR" checkout "${{ inputs.version }}"
if [ "$CURRENT_COMMIT" != "$TARGET_VERSION" ] && [ "$TARGET_VERSION" != "master" ]; then
echo "Checking out Flutter $TARGET_VERSION..."
git -C "$SDK_DIR" fetch origin "$TARGET_VERSION" --depth=1 2>/dev/null || git -C "$SDK_DIR" fetch origin
git -C "$SDK_DIR" checkout "$TARGET_VERSION"
else
echo "Flutter SDK already at ${{ inputs.version }}. Ready to use."
echo "Flutter SDK already at $TARGET_VERSION. Ready to use."
fi
fi
@@ -74,6 +90,25 @@ runs:
if: runner.os == 'Windows'
shell: powershell
run: |
$targetVersion = "${{ inputs.version }}"
if (-not $targetVersion) {
if (Test-Path ".fvmrc") {
try {
$fvm = Get-Content ".fvmrc" | ConvertFrom-Json
$targetVersion = $fvm.flutter
} catch {}
} elseif (Test-Path ".fvm\fvm_config.json") {
try {
$fvm = Get-Content ".fvm\fvm_config.json" | ConvertFrom-Json
$targetVersion = if ($fvm.flutterSdkVersion) { $fvm.flutterSdkVersion } else { $fvm.flutter }
} catch {}
}
}
if (-not $targetVersion) {
$targetVersion = "master"
}
Write-Output "Resolved Flutter version: $targetVersion"
$lockDir = Join-Path $env:TEMP "flutter-sdk-setup.lock"
$waited = 0
while ($true) {
@@ -101,15 +136,15 @@ runs:
echo "Failed to clone from mirror, falling back to GitHub..."
git clone https://github.com/flutter/flutter.git $sdkDir
}
git -C $sdkDir checkout "${{ inputs.version }}"
git -C $sdkDir checkout $targetVersion
} else {
$currentCommit = git -C $sdkDir rev-parse HEAD 2>$null
if ($currentCommit -ne "${{ inputs.version }}" -and "${{ inputs.version }}" -ne "master") {
echo "Checking out Flutter ${{ inputs.version }}..."
if ($currentCommit -ne $targetVersion -and $targetVersion -ne "master") {
echo "Checking out Flutter $targetVersion..."
git -C $sdkDir fetch origin
git -C $sdkDir checkout "${{ inputs.version }}"
git -C $sdkDir checkout $targetVersion
} else {
echo "Flutter SDK already at ${{ inputs.version }}. Ready to use."
echo "Flutter SDK already at $targetVersion. Ready to use."
}
}