Add concurrency mutex lock and SDK reuse to prevent race conditions during parallel CI jobs
Update README Actions Table / update-readme (push) Failing after 16s
Update README Actions Table / update-readme (push) Failing after 16s
This commit is contained in:
@@ -45,13 +45,22 @@ runs:
|
|||||||
if: runner.os != 'Windows' && steps.flutter-cache.outputs.cache-hit != 'true'
|
if: runner.os != 'Windows' && steps.flutter-cache.outputs.cache-hit != 'true'
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
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"
|
SDK_DIR="$HOME/flutter-sdk"
|
||||||
CLONE_URL="${{ inputs.mirror_url }}"
|
CLONE_URL="${{ inputs.mirror_url }}"
|
||||||
if [ -n "${{ inputs.git_token }}" ] && [[ "$CLONE_URL" == https://* ]]; then
|
if [ -n "${{ inputs.git_token }}" ] && [[ "$CLONE_URL" == https://* ]]; then
|
||||||
CLONE_URL="https://git:${{ inputs.git_token }}@${CLONE_URL#https://}"
|
CLONE_URL="https://git:${{ inputs.git_token }}@${CLONE_URL#https://}"
|
||||||
fi
|
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..."
|
echo "Cloning Flutter ${{ inputs.version }} from $CLONE_URL to $SDK_DIR..."
|
||||||
rm -rf "$SDK_DIR"
|
rm -rf "$SDK_DIR"
|
||||||
git clone --depth 1 --branch ${{ inputs.version }} "$CLONE_URL" "$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"
|
git clone --depth 1 --branch ${{ inputs.version }} https://github.com/flutter/flutter.git "$SDK_DIR"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
echo "Updating existing Flutter SDK at $SDK_DIR..."
|
echo "Flutter SDK already present at $SDK_DIR. Ready to use."
|
||||||
git -C "$SDK_DIR" fetch origin ${{ inputs.version }} --depth=1
|
|
||||||
git -C "$SDK_DIR" reset --hard origin/${{ inputs.version }}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -rf "$LOCK_DIR" || true
|
||||||
|
|
||||||
- name: Install Flutter (Windows)
|
- name: Install Flutter (Windows)
|
||||||
if: runner.os == 'Windows' && steps.flutter-cache.outputs.cache-hit != 'true'
|
if: runner.os == 'Windows' && steps.flutter-cache.outputs.cache-hit != 'true'
|
||||||
shell: powershell
|
shell: powershell
|
||||||
run: |
|
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"
|
$sdkDir = "C:\flutter-sdk"
|
||||||
$cloneUrl = "${{ inputs.mirror_url }}"
|
$cloneUrl = "${{ inputs.mirror_url }}"
|
||||||
if ("${{ inputs.git_token }}" -ne "" -and $cloneUrl.StartsWith("https://")) {
|
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
|
git clone --depth 1 --branch ${{ inputs.version }} https://github.com/flutter/flutter.git $sdkDir
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
echo "Updating existing Flutter SDK at $sdkDir..."
|
echo "Flutter SDK already present at $sdkDir. Ready to use."
|
||||||
git -C $sdkDir fetch origin ${{ inputs.version }} --depth=1
|
}
|
||||||
git -C $sdkDir reset --hard origin/${{ inputs.version }}
|
|
||||||
|
if (Test-Path $lockDir) {
|
||||||
|
try { [System.IO.Directory]::Delete($lockDir, $true) } catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
- name: Add to PATH and Configure (macOS / Linux)
|
- name: Add to PATH and Configure (macOS / Linux)
|
||||||
|
|||||||
Reference in New Issue
Block a user