From 4448068c1597f5c1006f93792547b562cc54992d Mon Sep 17 00:00:00 2001 From: Rody Davis Date: Sat, 22 Aug 2026 21:00:50 -0700 Subject: [PATCH] Add setup-flutter composite action --- setup-flutter/action.yml | 115 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 setup-flutter/action.yml diff --git a/setup-flutter/action.yml b/setup-flutter/action.yml new file mode 100644 index 0000000..1131575 --- /dev/null +++ b/setup-flutter/action.yml @@ -0,0 +1,115 @@ +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: | + 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 + 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 "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 }} + fi + + - name: Install Flutter (Windows) + if: runner.os == 'Windows' && steps.flutter-cache.outputs.cache-hit != 'true' + shell: powershell + run: | + $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 "Updating existing Flutter SDK at $sdkDir..." + git -C $sdkDir fetch origin ${{ inputs.version }} --depth=1 + git -C $sdkDir reset --hard origin/${{ inputs.version }} + } + + - 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