140 lines
4.7 KiB
YAML
140 lines
4.7 KiB
YAML
name: 'Setup Flutter'
|
|
description: 'Cross-platform setup for Flutter with caching on macOS, Windows, and Linux.'
|
|
inputs:
|
|
version:
|
|
description: 'Flutter channel or version tag (e.g., master, stable, 3.29.0)'
|
|
required: false
|
|
default: 'master'
|
|
mirror_url:
|
|
description: 'Git repository URL for Flutter SDK'
|
|
required: false
|
|
default: 'https://git.rodydavis.dev/rodydavis/flutter.git'
|
|
git_token:
|
|
description: 'Gitea token for authenticated git cloning'
|
|
required: false
|
|
default: ''
|
|
cache:
|
|
description: 'Enable Flutter SDK caching'
|
|
required: false
|
|
default: 'true'
|
|
enable_windowing:
|
|
description: 'Enable windowing and desktop support'
|
|
required: false
|
|
default: 'true'
|
|
|
|
runs:
|
|
using: 'composite'
|
|
steps:
|
|
- name: Determine Cache Key
|
|
id: cache-key
|
|
shell: bash
|
|
run: |
|
|
echo "key=flutter-${{ runner.os }}-${{ runner.arch }}-${{ inputs.version }}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Cache Flutter SDK
|
|
if: inputs.cache == 'true'
|
|
id: flutter-cache
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: |
|
|
~/flutter-sdk
|
|
C:\flutter-sdk
|
|
key: ${{ steps.cache-key.outputs.key }}
|
|
|
|
- name: Install Flutter (macOS / Linux)
|
|
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" ] || [ ! -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" || {
|
|
echo "Failed to clone from mirror, falling back to GitHub..."
|
|
git clone --depth 1 --branch ${{ inputs.version }} https://github.com/flutter/flutter.git "$SDK_DIR"
|
|
}
|
|
else
|
|
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://")) {
|
|
$cloneUrl = "https://git:${{ inputs.git_token }}@" + $cloneUrl.Substring(8)
|
|
}
|
|
|
|
if (-not (Test-Path "$sdkDir\bin\flutter.bat")) {
|
|
echo "Cloning Flutter ${{ inputs.version }} from $cloneUrl to $sdkDir..."
|
|
try {
|
|
git clone --depth 1 --branch ${{ inputs.version }} $cloneUrl $sdkDir
|
|
} catch {
|
|
echo "Failed to clone from mirror, falling back to GitHub..."
|
|
git clone --depth 1 --branch ${{ inputs.version }} https://github.com/flutter/flutter.git $sdkDir
|
|
}
|
|
} else {
|
|
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)
|
|
if: runner.os != 'Windows'
|
|
shell: bash
|
|
run: |
|
|
SDK_DIR="$HOME/flutter-sdk"
|
|
export PATH="$SDK_DIR/bin:$PATH"
|
|
echo "$SDK_DIR/bin" >> $GITHUB_PATH
|
|
|
|
if [ "${{ inputs.enable_windowing }}" = "true" ]; then
|
|
"$SDK_DIR/bin/flutter" config --enable-windowing
|
|
fi
|
|
"$SDK_DIR/bin/flutter" --version
|
|
|
|
- name: Add to PATH and Configure (Windows)
|
|
if: runner.os == 'Windows'
|
|
shell: powershell
|
|
run: |
|
|
$sdkDir = "C:\flutter-sdk"
|
|
[System.IO.File]::AppendAllText($env:GITHUB_PATH, "$sdkDir\bin`r`n")
|
|
$env:PATH = "$sdkDir\bin;$env:PATH"
|
|
|
|
if ("${{ inputs.enable_windowing }}" -eq "true") {
|
|
& "$sdkDir\bin\flutter.bat" config --enable-windowing
|
|
}
|
|
& "$sdkDir\bin\flutter.bat" --version
|