diff --git a/setup-flutter/action.yml b/setup-flutter/action.yml index 1131575..d7c3c2f 100644 --- a/setup-flutter/action.yml +++ b/setup-flutter/action.yml @@ -45,13 +45,22 @@ runs: if: runner.os != 'Windows' && steps.flutter-cache.outputs.cache-hit != 'true' shell: bash run: | + LOCK_DIR="${TMPDIR:-/tmp}/flutter-sdk-setup.lock" + for i in {1..60}; do + if mkdir "$LOCK_DIR" 2>/dev/null; then + break + fi + echo "Waiting for concurrent Flutter setup lock ($i/60)..." + sleep 2 + done + SDK_DIR="$HOME/flutter-sdk" CLONE_URL="${{ inputs.mirror_url }}" if [ -n "${{ inputs.git_token }}" ] && [[ "$CLONE_URL" == https://* ]]; then CLONE_URL="https://git:${{ inputs.git_token }}@${CLONE_URL#https://}" fi - if [ ! -d "$SDK_DIR/.git" ]; then + if [ ! -d "$SDK_DIR/.git" ] || [ ! -f "$SDK_DIR/bin/flutter" ]; then echo "Cloning Flutter ${{ inputs.version }} from $CLONE_URL to $SDK_DIR..." rm -rf "$SDK_DIR" git clone --depth 1 --branch ${{ inputs.version }} "$CLONE_URL" "$SDK_DIR" || { @@ -59,15 +68,28 @@ runs: git clone --depth 1 --branch ${{ inputs.version }} https://github.com/flutter/flutter.git "$SDK_DIR" } else - echo "Updating existing Flutter SDK at $SDK_DIR..." - git -C "$SDK_DIR" fetch origin ${{ inputs.version }} --depth=1 - git -C "$SDK_DIR" reset --hard origin/${{ inputs.version }} + echo "Flutter SDK already present at $SDK_DIR. Ready to use." fi + rm -rf "$LOCK_DIR" || true + - name: Install Flutter (Windows) if: runner.os == 'Windows' && steps.flutter-cache.outputs.cache-hit != 'true' shell: powershell run: | + $lockDir = Join-Path $env:TEMP "flutter-sdk-setup.lock" + $waited = 0 + while ($true) { + try { + [System.IO.Directory]::CreateDirectory($lockDir) | Out-Null + break + } catch { + Start-Sleep -Seconds 2 + $waited += 2 + if ($waited -ge 120) { break } + } + } + $sdkDir = "C:\flutter-sdk" $cloneUrl = "${{ inputs.mirror_url }}" if ("${{ inputs.git_token }}" -ne "" -and $cloneUrl.StartsWith("https://")) { @@ -83,9 +105,11 @@ runs: git clone --depth 1 --branch ${{ inputs.version }} https://github.com/flutter/flutter.git $sdkDir } } else { - echo "Updating existing Flutter SDK at $sdkDir..." - git -C $sdkDir fetch origin ${{ inputs.version }} --depth=1 - git -C $sdkDir reset --hard origin/${{ inputs.version }} + echo "Flutter SDK already present at $sdkDir. Ready to use." + } + + if (Test-Path $lockDir) { + try { [System.IO.Directory]::Delete($lockDir, $true) } catch {} } - name: Add to PATH and Configure (macOS / Linux)