Skip to content

Commit 7564de3

Browse files
authored
Merge pull request #288 from subosito/chore/action_yaml_refactor
Split longer lines in action.yaml
2 parents cf12a39 + 2b3ab6c commit 7564de3

File tree

4 files changed

+55
-29
lines changed

4 files changed

+55
-29
lines changed

.github/workflows/workflow.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
- uses: ./
7070
with:
7171
channel: stable
72-
flutter-version: "3.10.6"
72+
flutter-version: 3.10.6
7373
cache: true
7474
- run: dart --version
7575
shell: bash

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ steps:
5757
- name: Set up Flutter
5858
uses: subosito/flutter-action@v2
5959
with:
60-
flutter-version: "3.x"
60+
flutter-version: 3.x
6161
channel: any
6262
- run: flutter --version
6363
```

action.yaml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ author: Alif Rachmawadi
44
branding:
55
icon: maximize
66
color: blue
7+
78
inputs:
89
flutter-version:
910
description: The Flutter version to make available on the path
@@ -37,6 +38,7 @@ inputs:
3738
description: The architecture of Flutter SDK executable (x64 or arm64)
3839
required: false
3940
default: "${{ runner.arch }}"
41+
4042
outputs:
4143
CACHE-KEY:
4244
value: "${{ steps.flutter-action.outputs.CACHE-KEY }}"
@@ -59,32 +61,51 @@ outputs:
5961
PUB-CACHE-PATH:
6062
value: "${{ steps.flutter-action.outputs.PUB-CACHE-PATH }}"
6163
description: Path to pub cache
64+
6265
runs:
6366
using: composite
6467
steps:
6568
- name: Make setup script executable
6669
run: chmod +x "$GITHUB_ACTION_PATH/setup.sh"
6770
shell: bash
68-
- name: Print configuration
71+
72+
- name: Set action inputs
6973
id: flutter-action
70-
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 }}
7174
shell: bash
75+
run: |
76+
$GITHUB_ACTION_PATH/setup.sh -p \
77+
-c '${{ inputs.cache-path }}' \
78+
-k '${{ inputs.cache-key }}' \
79+
-d '${{ inputs.pub-cache-path }}' \
80+
-l '${{ inputs.pub-cache-key }}' \
81+
-n '${{ inputs.flutter-version }}' \
82+
-a '${{ inputs.architecture }}' \
83+
${{ inputs.channel }}
84+
7285
- name: Cache Flutter
73-
if: ${{ inputs.cache == 'true' }}
7486
uses: actions/cache@v4
87+
if: ${{ inputs.cache == 'true' }}
7588
with:
7689
path: ${{ steps.flutter-action.outputs.CACHE-PATH }}
7790
key: ${{ steps.flutter-action.outputs.CACHE-KEY }}
7891
restore-keys: |
7992
${{ steps.flutter-action.outputs.CACHE-KEY }}
93+
8094
- name: Cache pub dependencies
81-
if: ${{ inputs.cache == 'true' }}
8295
uses: actions/cache@v4
96+
if: ${{ inputs.cache == 'true' }}
8397
with:
8498
path: ${{ steps.flutter-action.outputs.PUB-CACHE-PATH }}
8599
key: ${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}-${{ hashFiles('**/pubspec.lock') }}
86100
restore-keys: |
87101
${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}-${{ hashFiles('**/pubspec.lock') }}
88102
${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}
89-
- 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 }}
103+
104+
- name: Run setup script
90105
shell: bash
106+
run: |
107+
$GITHUB_ACTION_PATH/setup.sh \
108+
-c '${{ steps.flutter-action.outputs.CACHE-PATH }}' \
109+
-n '${{ steps.flutter-action.outputs.VERSION }}' \
110+
-a '${{ steps.flutter-action.outputs.ARCHITECTURE }}' \
111+
${{ steps.flutter-action.outputs.CHANNEL }}

setup.sh

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ not_found_error() {
3232
}
3333

3434
transform_path() {
35-
if [[ "$OS_NAME" == windows ]]; then
35+
if [ "$OS_NAME" = windows ]; then
3636
echo "$1" | sed -e 's/^\///' -e 's/\//\\/g'
3737
else
3838
echo "$1"
@@ -48,7 +48,8 @@ download_archive() {
4848

4949
mkdir -p "$2"
5050

51-
if [[ "$archive_name" == *zip ]]; then
51+
case "$archive_name" in
52+
*.zip)
5253
EXTRACT_PATH="$RUNNER_TEMP/_unzip_temp"
5354
unzip -q -o "$archive_local" -d "$EXTRACT_PATH"
5455
# Remove the folder again so that the move command can do a simple rename
@@ -58,9 +59,11 @@ download_archive() {
5859
rm -r "$2"
5960
mv "$EXTRACT_PATH"/flutter "$2"
6061
rm -r "$EXTRACT_PATH"
61-
else
62+
;;
63+
*)
6264
tar xf "$archive_local" -C "$2" --strip-components=1
63-
fi
65+
;;
66+
esac
6467

6568
rm "$archive_local"
6669
}
@@ -88,18 +91,18 @@ while getopts 'tc:k:d:l:pa:n:' flag; do
8891
esac
8992
done
9093

91-
[[ -z $ARCH ]] && ARCH="$ARCH_NAME"
94+
[ -z "$ARCH" ] && ARCH="$ARCH_NAME"
9295

9396
ARR_CHANNEL=("${@:$OPTIND:1}")
9497
CHANNEL="${ARR_CHANNEL[0]}"
9598

96-
[[ -z $CHANNEL ]] && CHANNEL=stable
97-
[[ -z $VERSION ]] && VERSION=any
98-
[[ -z $ARCH ]] && ARCH=x64
99-
[[ -z $CACHE_PATH ]] && CACHE_PATH="$RUNNER_TEMP/flutter/:channel:-:version:-:arch:"
100-
[[ -z $CACHE_KEY ]] && CACHE_KEY="flutter-:os:-:channel:-:version:-:arch:-:hash:"
101-
[[ -z $PUB_CACHE_KEY ]] && PUB_CACHE_KEY="flutter-pub-:os:-:channel:-:version:-:arch:-:hash:"
102-
[[ -z $PUB_CACHE_PATH ]] && PUB_CACHE_PATH="default"
99+
[ -z "$CHANNEL" ] && CHANNEL=stable
100+
[ -z "$VERSION" ] && VERSION=any
101+
[ -z "$ARCH" ] && ARCH=x64
102+
[ -z "$CACHE_PATH" ] && CACHE_PATH="$RUNNER_TEMP/flutter/:channel:-:version:-:arch:"
103+
[ -z "$CACHE_KEY" ] && CACHE_KEY="flutter-:os:-:channel:-:version:-:arch:-:hash:"
104+
[ -z "$PUB_CACHE_KEY" ] && PUB_CACHE_KEY="flutter-pub-:os:-:channel:-:version:-:arch:-:hash:"
105+
[ -z "$PUB_CACHE_PATH" ] && PUB_CACHE_PATH="default"
103106

104107
# `PUB_CACHE` is what Dart and Flutter looks for in the environment, while
105108
# `PUB_CACHE_PATH` is passed in from the action.
@@ -110,29 +113,31 @@ CHANNEL="${ARR_CHANNEL[0]}"
110113
if [ -z "$PUB_CACHE" ]; then
111114
if [ "$PUB_CACHE_PATH" != "default" ]; then
112115
PUB_CACHE="$PUB_CACHE_PATH"
113-
elif [ "$OS_NAME" == "windows" ]; then
116+
elif [ "$OS_NAME" = "windows" ]; then
114117
PUB_CACHE="$LOCALAPPDATA\\Pub\\Cache"
115118
else
116119
PUB_CACHE="$HOME/.pub-cache"
117120
fi
118121
fi
119122

120-
if [[ "$TEST_MODE" == true ]]; then
123+
if [ "$TEST_MODE" = true ]; then
121124
RELEASE_MANIFEST=$(cat "$(dirname -- "${BASH_SOURCE[0]}")/test/$MANIFEST_JSON_PATH")
122125
else
123126
RELEASE_MANIFEST=$(curl --silent --connect-timeout 15 --retry 5 "$MANIFEST_URL")
124127
fi
125128

126-
if [[ "$CHANNEL" == "master" || "$CHANNEL" == "main" ]]; then
129+
if [ "$CHANNEL" = "master" ] || [ "$CHANNEL" = "main" ]; then
127130
VERSION_MANIFEST="{\"channel\":\"$CHANNEL\",\"version\":\"$VERSION\",\"dart_sdk_arch\":\"$ARCH\",\"hash\":\"$CHANNEL\",\"sha256\":\"$CHANNEL\"}"
128131
else
129132
VERSION_MANIFEST=$(echo "$RELEASE_MANIFEST" | filter_by_channel "$CHANNEL" | filter_by_arch "$ARCH" | filter_by_version "$VERSION")
130133
fi
131134

132-
if [[ "$VERSION_MANIFEST" == *null* ]]; then
135+
case "$VERSION_MANIFEST" in
136+
*null*)
133137
not_found_error "$CHANNEL" "$VERSION" "$ARCH"
134138
exit 1
135-
fi
139+
;;
140+
esac
136141

137142
expand_key() {
138143
version_channel=$(echo "$VERSION_MANIFEST" | jq -r '.channel')
@@ -155,14 +160,14 @@ CACHE_KEY=$(expand_key "$CACHE_KEY")
155160
PUB_CACHE_KEY=$(expand_key "$PUB_CACHE_KEY")
156161
CACHE_PATH=$(expand_key "$(transform_path "$CACHE_PATH")")
157162

158-
if [[ "$PRINT_ONLY" == true ]]; then
163+
if [ "$PRINT_ONLY" = true ]; then
159164
version_info=$(echo "$VERSION_MANIFEST" | jq -j '.channel,":",.version,":",.dart_sdk_arch // "x64"')
160165

161166
info_channel=$(echo "$version_info" | awk -F ':' '{print $1}')
162167
info_version=$(echo "$version_info" | awk -F ':' '{print $2}')
163168
info_architecture=$(echo "$version_info" | awk -F ':' '{print $3}')
164169

165-
if [[ "$TEST_MODE" == true ]]; then
170+
if [ "$TEST_MODE" = true ]; then
166171
echo "CHANNEL=$info_channel"
167172
echo "VERSION=$info_version"
168173
echo "ARCHITECTURE=$info_architecture"
@@ -186,10 +191,10 @@ if [[ "$PRINT_ONLY" == true ]]; then
186191
exit 0
187192
fi
188193

189-
if [[ ! -x "$CACHE_PATH/bin/flutter" ]]; then
190-
if [[ "$CHANNEL" == "master" || "$CHANNEL" == "main" ]]; then
194+
if [ ! -x "$CACHE_PATH/bin/flutter" ]; then
195+
if [ "$CHANNEL" = "master" ] || [ "$CHANNEL" = "main" ]; then
191196
git clone -b "$CHANNEL" https://github.com/flutter/flutter.git "$CACHE_PATH"
192-
if [[ "$VERSION" != "any" ]]; then
197+
if [ "$VERSION" != "any" ]; then
193198
git config --global --add safe.directory "$CACHE_PATH"
194199
(cd "$CACHE_PATH" && git checkout "$VERSION")
195200
fi

0 commit comments

Comments
 (0)