mirror of
https://github.com/subosito/flutter-action.git
synced 2024-08-16 10:19:50 +02:00
Merge pull request #288 from subosito/chore/action_yaml_refactor
Split longer lines in action.yaml
This commit is contained in:
commit
7564de34b3
4 changed files with 55 additions and 29 deletions
2
.github/workflows/workflow.yaml
vendored
2
.github/workflows/workflow.yaml
vendored
|
@ -69,7 +69,7 @@ jobs:
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
channel: stable
|
channel: stable
|
||||||
flutter-version: "3.10.6"
|
flutter-version: 3.10.6
|
||||||
cache: true
|
cache: true
|
||||||
- run: dart --version
|
- run: dart --version
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
|
@ -57,7 +57,7 @@ steps:
|
||||||
- name: Set up Flutter
|
- name: Set up Flutter
|
||||||
uses: subosito/flutter-action@v2
|
uses: subosito/flutter-action@v2
|
||||||
with:
|
with:
|
||||||
flutter-version: "3.x"
|
flutter-version: 3.x
|
||||||
channel: any
|
channel: any
|
||||||
- run: flutter --version
|
- run: flutter --version
|
||||||
```
|
```
|
||||||
|
|
31
action.yaml
31
action.yaml
|
@ -4,6 +4,7 @@ author: Alif Rachmawadi
|
||||||
branding:
|
branding:
|
||||||
icon: maximize
|
icon: maximize
|
||||||
color: blue
|
color: blue
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
flutter-version:
|
flutter-version:
|
||||||
description: The Flutter version to make available on the path
|
description: The Flutter version to make available on the path
|
||||||
|
@ -37,6 +38,7 @@ inputs:
|
||||||
description: The architecture of Flutter SDK executable (x64 or arm64)
|
description: The architecture of Flutter SDK executable (x64 or arm64)
|
||||||
required: false
|
required: false
|
||||||
default: "${{ runner.arch }}"
|
default: "${{ runner.arch }}"
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
CACHE-KEY:
|
CACHE-KEY:
|
||||||
value: "${{ steps.flutter-action.outputs.CACHE-KEY }}"
|
value: "${{ steps.flutter-action.outputs.CACHE-KEY }}"
|
||||||
|
@ -59,32 +61,51 @@ outputs:
|
||||||
PUB-CACHE-PATH:
|
PUB-CACHE-PATH:
|
||||||
value: "${{ steps.flutter-action.outputs.PUB-CACHE-PATH }}"
|
value: "${{ steps.flutter-action.outputs.PUB-CACHE-PATH }}"
|
||||||
description: Path to pub cache
|
description: Path to pub cache
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
- name: Make setup script executable
|
- name: Make setup script executable
|
||||||
run: chmod +x "$GITHUB_ACTION_PATH/setup.sh"
|
run: chmod +x "$GITHUB_ACTION_PATH/setup.sh"
|
||||||
shell: bash
|
shell: bash
|
||||||
- name: Print configuration
|
|
||||||
|
- name: Set action inputs
|
||||||
id: flutter-action
|
id: flutter-action
|
||||||
run: $GITHUB_ACTION_PATH/setup.sh -p -c '${{ inputs.cache-path }}' -k '${{ inputs.cache-key }}' -d '${{ inputs.pub-cache-path }}' -l '${{ inputs.pub-cache-key }}' -n '${{ inputs.flutter-version }}' -a '${{ inputs.architecture }}' ${{ inputs.channel }}
|
|
||||||
shell: bash
|
shell: bash
|
||||||
|
run: |
|
||||||
|
$GITHUB_ACTION_PATH/setup.sh -p \
|
||||||
|
-c '${{ inputs.cache-path }}' \
|
||||||
|
-k '${{ inputs.cache-key }}' \
|
||||||
|
-d '${{ inputs.pub-cache-path }}' \
|
||||||
|
-l '${{ inputs.pub-cache-key }}' \
|
||||||
|
-n '${{ inputs.flutter-version }}' \
|
||||||
|
-a '${{ inputs.architecture }}' \
|
||||||
|
${{ inputs.channel }}
|
||||||
|
|
||||||
- name: Cache Flutter
|
- name: Cache Flutter
|
||||||
if: ${{ inputs.cache == 'true' }}
|
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
|
if: ${{ inputs.cache == 'true' }}
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.flutter-action.outputs.CACHE-PATH }}
|
path: ${{ steps.flutter-action.outputs.CACHE-PATH }}
|
||||||
key: ${{ steps.flutter-action.outputs.CACHE-KEY }}
|
key: ${{ steps.flutter-action.outputs.CACHE-KEY }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ steps.flutter-action.outputs.CACHE-KEY }}
|
${{ steps.flutter-action.outputs.CACHE-KEY }}
|
||||||
|
|
||||||
- name: Cache pub dependencies
|
- name: Cache pub dependencies
|
||||||
if: ${{ inputs.cache == 'true' }}
|
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
|
if: ${{ inputs.cache == 'true' }}
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.flutter-action.outputs.PUB-CACHE-PATH }}
|
path: ${{ steps.flutter-action.outputs.PUB-CACHE-PATH }}
|
||||||
key: ${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}-${{ hashFiles('**/pubspec.lock') }}
|
key: ${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}-${{ hashFiles('**/pubspec.lock') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}-${{ hashFiles('**/pubspec.lock') }}
|
${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}-${{ hashFiles('**/pubspec.lock') }}
|
||||||
${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}
|
${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}
|
||||||
- run: $GITHUB_ACTION_PATH/setup.sh -c '${{ steps.flutter-action.outputs.CACHE-PATH }}' -n '${{ steps.flutter-action.outputs.VERSION }}' -a '${{ steps.flutter-action.outputs.ARCHITECTURE }}' ${{ steps.flutter-action.outputs.CHANNEL }}
|
|
||||||
|
- name: Run setup script
|
||||||
shell: bash
|
shell: bash
|
||||||
|
run: |
|
||||||
|
$GITHUB_ACTION_PATH/setup.sh \
|
||||||
|
-c '${{ steps.flutter-action.outputs.CACHE-PATH }}' \
|
||||||
|
-n '${{ steps.flutter-action.outputs.VERSION }}' \
|
||||||
|
-a '${{ steps.flutter-action.outputs.ARCHITECTURE }}' \
|
||||||
|
${{ steps.flutter-action.outputs.CHANNEL }}
|
||||||
|
|
49
setup.sh
49
setup.sh
|
@ -32,7 +32,7 @@ not_found_error() {
|
||||||
}
|
}
|
||||||
|
|
||||||
transform_path() {
|
transform_path() {
|
||||||
if [[ "$OS_NAME" == windows ]]; then
|
if [ "$OS_NAME" = windows ]; then
|
||||||
echo "$1" | sed -e 's/^\///' -e 's/\//\\/g'
|
echo "$1" | sed -e 's/^\///' -e 's/\//\\/g'
|
||||||
else
|
else
|
||||||
echo "$1"
|
echo "$1"
|
||||||
|
@ -48,7 +48,8 @@ download_archive() {
|
||||||
|
|
||||||
mkdir -p "$2"
|
mkdir -p "$2"
|
||||||
|
|
||||||
if [[ "$archive_name" == *zip ]]; then
|
case "$archive_name" in
|
||||||
|
*.zip)
|
||||||
EXTRACT_PATH="$RUNNER_TEMP/_unzip_temp"
|
EXTRACT_PATH="$RUNNER_TEMP/_unzip_temp"
|
||||||
unzip -q -o "$archive_local" -d "$EXTRACT_PATH"
|
unzip -q -o "$archive_local" -d "$EXTRACT_PATH"
|
||||||
# Remove the folder again so that the move command can do a simple rename
|
# Remove the folder again so that the move command can do a simple rename
|
||||||
|
@ -58,9 +59,11 @@ download_archive() {
|
||||||
rm -r "$2"
|
rm -r "$2"
|
||||||
mv "$EXTRACT_PATH"/flutter "$2"
|
mv "$EXTRACT_PATH"/flutter "$2"
|
||||||
rm -r "$EXTRACT_PATH"
|
rm -r "$EXTRACT_PATH"
|
||||||
else
|
;;
|
||||||
|
*)
|
||||||
tar xf "$archive_local" -C "$2" --strip-components=1
|
tar xf "$archive_local" -C "$2" --strip-components=1
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
rm "$archive_local"
|
rm "$archive_local"
|
||||||
}
|
}
|
||||||
|
@ -88,18 +91,18 @@ while getopts 'tc:k:d:l:pa:n:' flag; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ -z $ARCH ]] && ARCH="$ARCH_NAME"
|
[ -z "$ARCH" ] && ARCH="$ARCH_NAME"
|
||||||
|
|
||||||
ARR_CHANNEL=("${@:$OPTIND:1}")
|
ARR_CHANNEL=("${@:$OPTIND:1}")
|
||||||
CHANNEL="${ARR_CHANNEL[0]}"
|
CHANNEL="${ARR_CHANNEL[0]}"
|
||||||
|
|
||||||
[[ -z $CHANNEL ]] && CHANNEL=stable
|
[ -z "$CHANNEL" ] && CHANNEL=stable
|
||||||
[[ -z $VERSION ]] && VERSION=any
|
[ -z "$VERSION" ] && VERSION=any
|
||||||
[[ -z $ARCH ]] && ARCH=x64
|
[ -z "$ARCH" ] && ARCH=x64
|
||||||
[[ -z $CACHE_PATH ]] && CACHE_PATH="$RUNNER_TEMP/flutter/:channel:-:version:-:arch:"
|
[ -z "$CACHE_PATH" ] && CACHE_PATH="$RUNNER_TEMP/flutter/:channel:-:version:-:arch:"
|
||||||
[[ -z $CACHE_KEY ]] && CACHE_KEY="flutter-:os:-:channel:-:version:-:arch:-:hash:"
|
[ -z "$CACHE_KEY" ] && CACHE_KEY="flutter-:os:-:channel:-:version:-:arch:-:hash:"
|
||||||
[[ -z $PUB_CACHE_KEY ]] && PUB_CACHE_KEY="flutter-pub-:os:-:channel:-:version:-:arch:-:hash:"
|
[ -z "$PUB_CACHE_KEY" ] && PUB_CACHE_KEY="flutter-pub-:os:-:channel:-:version:-:arch:-:hash:"
|
||||||
[[ -z $PUB_CACHE_PATH ]] && PUB_CACHE_PATH="default"
|
[ -z "$PUB_CACHE_PATH" ] && PUB_CACHE_PATH="default"
|
||||||
|
|
||||||
# `PUB_CACHE` is what Dart and Flutter looks for in the environment, while
|
# `PUB_CACHE` is what Dart and Flutter looks for in the environment, while
|
||||||
# `PUB_CACHE_PATH` is passed in from the action.
|
# `PUB_CACHE_PATH` is passed in from the action.
|
||||||
|
@ -110,29 +113,31 @@ CHANNEL="${ARR_CHANNEL[0]}"
|
||||||
if [ -z "$PUB_CACHE" ]; then
|
if [ -z "$PUB_CACHE" ]; then
|
||||||
if [ "$PUB_CACHE_PATH" != "default" ]; then
|
if [ "$PUB_CACHE_PATH" != "default" ]; then
|
||||||
PUB_CACHE="$PUB_CACHE_PATH"
|
PUB_CACHE="$PUB_CACHE_PATH"
|
||||||
elif [ "$OS_NAME" == "windows" ]; then
|
elif [ "$OS_NAME" = "windows" ]; then
|
||||||
PUB_CACHE="$LOCALAPPDATA\\Pub\\Cache"
|
PUB_CACHE="$LOCALAPPDATA\\Pub\\Cache"
|
||||||
else
|
else
|
||||||
PUB_CACHE="$HOME/.pub-cache"
|
PUB_CACHE="$HOME/.pub-cache"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$TEST_MODE" == true ]]; then
|
if [ "$TEST_MODE" = true ]; then
|
||||||
RELEASE_MANIFEST=$(cat "$(dirname -- "${BASH_SOURCE[0]}")/test/$MANIFEST_JSON_PATH")
|
RELEASE_MANIFEST=$(cat "$(dirname -- "${BASH_SOURCE[0]}")/test/$MANIFEST_JSON_PATH")
|
||||||
else
|
else
|
||||||
RELEASE_MANIFEST=$(curl --silent --connect-timeout 15 --retry 5 "$MANIFEST_URL")
|
RELEASE_MANIFEST=$(curl --silent --connect-timeout 15 --retry 5 "$MANIFEST_URL")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$CHANNEL" == "master" || "$CHANNEL" == "main" ]]; then
|
if [ "$CHANNEL" = "master" ] || [ "$CHANNEL" = "main" ]; then
|
||||||
VERSION_MANIFEST="{\"channel\":\"$CHANNEL\",\"version\":\"$VERSION\",\"dart_sdk_arch\":\"$ARCH\",\"hash\":\"$CHANNEL\",\"sha256\":\"$CHANNEL\"}"
|
VERSION_MANIFEST="{\"channel\":\"$CHANNEL\",\"version\":\"$VERSION\",\"dart_sdk_arch\":\"$ARCH\",\"hash\":\"$CHANNEL\",\"sha256\":\"$CHANNEL\"}"
|
||||||
else
|
else
|
||||||
VERSION_MANIFEST=$(echo "$RELEASE_MANIFEST" | filter_by_channel "$CHANNEL" | filter_by_arch "$ARCH" | filter_by_version "$VERSION")
|
VERSION_MANIFEST=$(echo "$RELEASE_MANIFEST" | filter_by_channel "$CHANNEL" | filter_by_arch "$ARCH" | filter_by_version "$VERSION")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$VERSION_MANIFEST" == *null* ]]; then
|
case "$VERSION_MANIFEST" in
|
||||||
|
*null*)
|
||||||
not_found_error "$CHANNEL" "$VERSION" "$ARCH"
|
not_found_error "$CHANNEL" "$VERSION" "$ARCH"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
expand_key() {
|
expand_key() {
|
||||||
version_channel=$(echo "$VERSION_MANIFEST" | jq -r '.channel')
|
version_channel=$(echo "$VERSION_MANIFEST" | jq -r '.channel')
|
||||||
|
@ -155,14 +160,14 @@ CACHE_KEY=$(expand_key "$CACHE_KEY")
|
||||||
PUB_CACHE_KEY=$(expand_key "$PUB_CACHE_KEY")
|
PUB_CACHE_KEY=$(expand_key "$PUB_CACHE_KEY")
|
||||||
CACHE_PATH=$(expand_key "$(transform_path "$CACHE_PATH")")
|
CACHE_PATH=$(expand_key "$(transform_path "$CACHE_PATH")")
|
||||||
|
|
||||||
if [[ "$PRINT_ONLY" == true ]]; then
|
if [ "$PRINT_ONLY" = true ]; then
|
||||||
version_info=$(echo "$VERSION_MANIFEST" | jq -j '.channel,":",.version,":",.dart_sdk_arch // "x64"')
|
version_info=$(echo "$VERSION_MANIFEST" | jq -j '.channel,":",.version,":",.dart_sdk_arch // "x64"')
|
||||||
|
|
||||||
info_channel=$(echo "$version_info" | awk -F ':' '{print $1}')
|
info_channel=$(echo "$version_info" | awk -F ':' '{print $1}')
|
||||||
info_version=$(echo "$version_info" | awk -F ':' '{print $2}')
|
info_version=$(echo "$version_info" | awk -F ':' '{print $2}')
|
||||||
info_architecture=$(echo "$version_info" | awk -F ':' '{print $3}')
|
info_architecture=$(echo "$version_info" | awk -F ':' '{print $3}')
|
||||||
|
|
||||||
if [[ "$TEST_MODE" == true ]]; then
|
if [ "$TEST_MODE" = true ]; then
|
||||||
echo "CHANNEL=$info_channel"
|
echo "CHANNEL=$info_channel"
|
||||||
echo "VERSION=$info_version"
|
echo "VERSION=$info_version"
|
||||||
echo "ARCHITECTURE=$info_architecture"
|
echo "ARCHITECTURE=$info_architecture"
|
||||||
|
@ -186,10 +191,10 @@ if [[ "$PRINT_ONLY" == true ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -x "$CACHE_PATH/bin/flutter" ]]; then
|
if [ ! -x "$CACHE_PATH/bin/flutter" ]; then
|
||||||
if [[ "$CHANNEL" == "master" || "$CHANNEL" == "main" ]]; then
|
if [ "$CHANNEL" = "master" ] || [ "$CHANNEL" = "main" ]; then
|
||||||
git clone -b "$CHANNEL" https://github.com/flutter/flutter.git "$CACHE_PATH"
|
git clone -b "$CHANNEL" https://github.com/flutter/flutter.git "$CACHE_PATH"
|
||||||
if [[ "$VERSION" != "any" ]]; then
|
if [ "$VERSION" != "any" ]; then
|
||||||
git config --global --add safe.directory "$CACHE_PATH"
|
git config --global --add safe.directory "$CACHE_PATH"
|
||||||
(cd "$CACHE_PATH" && git checkout "$VERSION")
|
(cd "$CACHE_PATH" && git checkout "$VERSION")
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue