perf(setup-flutter): persist flutter-sdk in /opt/hostedtoolcache on Linux Docker runners and expose dart-sdk on PATH [skip ci]
This commit is contained in:
@@ -25,7 +25,10 @@ runs:
|
|||||||
if: runner.os != 'Windows'
|
if: runner.os != 'Windows'
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
LOCK_DIR="/opt/hostedtoolcache/flutter-sdk-setup.lock"
|
||||||
|
if [ ! -d "/opt/hostedtoolcache" ] || [ ! -w "/opt/hostedtoolcache" ]; then
|
||||||
LOCK_DIR="${TMPDIR:-/tmp}/flutter-sdk-setup.lock"
|
LOCK_DIR="${TMPDIR:-/tmp}/flutter-sdk-setup.lock"
|
||||||
|
fi
|
||||||
for i in {1..60}; do
|
for i in {1..60}; do
|
||||||
if mkdir "$LOCK_DIR" 2>/dev/null; then
|
if mkdir "$LOCK_DIR" 2>/dev/null; then
|
||||||
break
|
break
|
||||||
@@ -35,6 +38,10 @@ runs:
|
|||||||
done
|
done
|
||||||
|
|
||||||
SDK_DIR="$HOME/flutter-sdk"
|
SDK_DIR="$HOME/flutter-sdk"
|
||||||
|
if [ -d "/opt/hostedtoolcache" ] && [ -w "/opt/hostedtoolcache" ]; then
|
||||||
|
SDK_DIR="/opt/hostedtoolcache/flutter-sdk"
|
||||||
|
fi
|
||||||
|
|
||||||
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://}"
|
||||||
@@ -47,8 +54,10 @@ runs:
|
|||||||
echo "Failed to clone from mirror, falling back to GitHub..."
|
echo "Failed to clone from mirror, falling back to GitHub..."
|
||||||
git clone https://github.com/flutter/flutter.git "$SDK_DIR"
|
git clone https://github.com/flutter/flutter.git "$SDK_DIR"
|
||||||
}
|
}
|
||||||
|
git -C "$SDK_DIR" config --global --add safe.directory "$SDK_DIR" || true
|
||||||
git -C "$SDK_DIR" checkout "${{ inputs.version }}"
|
git -C "$SDK_DIR" checkout "${{ inputs.version }}"
|
||||||
else
|
else
|
||||||
|
git -C "$SDK_DIR" config --global --add safe.directory "$SDK_DIR" || true
|
||||||
CURRENT_COMMIT=$(git -C "$SDK_DIR" rev-parse HEAD 2>/dev/null || true)
|
CURRENT_COMMIT=$(git -C "$SDK_DIR" rev-parse HEAD 2>/dev/null || true)
|
||||||
if [ "$CURRENT_COMMIT" != "${{ inputs.version }}" ] && [ "${{ inputs.version }}" != "master" ]; then
|
if [ "$CURRENT_COMMIT" != "${{ inputs.version }}" ] && [ "${{ inputs.version }}" != "master" ]; then
|
||||||
echo "Checking out Flutter ${{ inputs.version }}..."
|
echo "Checking out Flutter ${{ inputs.version }}..."
|
||||||
@@ -113,8 +122,12 @@ runs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
SDK_DIR="$HOME/flutter-sdk"
|
SDK_DIR="$HOME/flutter-sdk"
|
||||||
export PATH="$SDK_DIR/bin:$PATH"
|
if [ -d "/opt/hostedtoolcache/flutter-sdk" ]; then
|
||||||
|
SDK_DIR="/opt/hostedtoolcache/flutter-sdk"
|
||||||
|
fi
|
||||||
|
export PATH="$SDK_DIR/bin:$SDK_DIR/bin/cache/dart-sdk/bin:$PATH"
|
||||||
echo "$SDK_DIR/bin" >> $GITHUB_PATH
|
echo "$SDK_DIR/bin" >> $GITHUB_PATH
|
||||||
|
echo "$SDK_DIR/bin/cache/dart-sdk/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
if [ "${{ inputs.enable_windowing }}" = "true" ]; then
|
if [ "${{ inputs.enable_windowing }}" = "true" ]; then
|
||||||
"$SDK_DIR/bin/flutter" config --enable-windowing
|
"$SDK_DIR/bin/flutter" config --enable-windowing
|
||||||
@@ -127,7 +140,8 @@ runs:
|
|||||||
run: |
|
run: |
|
||||||
$sdkDir = "C:\flutter-sdk"
|
$sdkDir = "C:\flutter-sdk"
|
||||||
[System.IO.File]::AppendAllText($env:GITHUB_PATH, "$sdkDir\bin`r`n")
|
[System.IO.File]::AppendAllText($env:GITHUB_PATH, "$sdkDir\bin`r`n")
|
||||||
$env:PATH = "$sdkDir\bin;$env:PATH"
|
[System.IO.File]::AppendAllText($env:GITHUB_PATH, "$sdkDir\bin\cache\dart-sdk\bin`r`n")
|
||||||
|
$env:PATH = "$sdkDir\bin;$sdkDir\bin\cache\dart-sdk\bin;$env:PATH"
|
||||||
|
|
||||||
if ("${{ inputs.enable_windowing }}" -eq "true") {
|
if ("${{ inputs.enable_windowing }}" -eq "true") {
|
||||||
& "$sdkDir\bin\flutter.bat" config --enable-windowing
|
& "$sdkDir\bin\flutter.bat" config --enable-windowing
|
||||||
|
|||||||
Reference in New Issue
Block a user