156 lines
5.5 KiB
YAML
156 lines
5.5 KiB
YAML
name: 'Setup Flutter'
|
|
description: 'Cross-platform setup for Flutter with caching on macOS, Windows, and Linux.'
|
|
inputs:
|
|
version:
|
|
description: 'Flutter channel, version tag, or commit hash (e.g., master, stable, 3.29.0, 4ebf37fe7df0a130ba5bee17315b98f905c10b34)'
|
|
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 SDK to $SDK_DIR..."
|
|
rm -rf "$SDK_DIR"
|
|
git clone "$CLONE_URL" "$SDK_DIR" || {
|
|
echo "Failed to clone from mirror, falling back to GitHub..."
|
|
git clone https://github.com/flutter/flutter.git "$SDK_DIR"
|
|
}
|
|
git -C "$SDK_DIR" checkout "${{ inputs.version }}"
|
|
else
|
|
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 }}"
|
|
else
|
|
echo "Flutter SDK already at ${{ inputs.version }}. Ready to use."
|
|
fi
|
|
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 SDK to $sdkDir..."
|
|
try {
|
|
git clone $cloneUrl $sdkDir
|
|
} catch {
|
|
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 }}"
|
|
} 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 }}..."
|
|
git -C $sdkDir fetch origin
|
|
git -C $sdkDir checkout "${{ inputs.version }}"
|
|
} else {
|
|
echo "Flutter SDK already at ${{ inputs.version }}. 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
|