Skip to content

Commit 1e95277

Browse files
author
Alif Rachmawadi
committed
enhance set output
1 parent 9d48f4e commit 1e95277

File tree

3 files changed

+83
-107
lines changed

3 files changed

+83
-107
lines changed

.github/workflows/workflow.yml

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
push:
44
branches:
55
- main
6+
- dev
67
pull_request:
78
paths:
89
- setup.sh
@@ -43,85 +44,95 @@ jobs:
4344
shell: bash
4445
- run: flutter --version
4546
shell: bash
46-
test_version:
47+
test_print_output:
4748
runs-on: macos-latest
4849
steps:
4950
- uses: actions/checkout@v3
50-
- run: ./setup.sh -t -p version | grep -x 'stable:any:x64|stable:3.0.5:x64'
51+
- run: ./setup.sh -t -p | grep 'stable'
5152
shell: bash
52-
- run: ./setup.sh -t -p version stable | grep -x 'stable:any:x64|stable:3.0.5:x64'
53+
- run: ./setup.sh -t -p | grep '3.0.5'
5354
shell: bash
54-
- run: ./setup.sh -t -p version beta | grep -x 'beta:any:x64|beta:3.1.0-9.0.pre:x64'
55+
- run: ./setup.sh -t -p | grep 'x64'
5556
shell: bash
56-
- run: ./setup.sh -t -p version master | grep -x 'master:master:x64|master:master:x64'
57+
- run: ./setup.sh -t -p stable | grep 'stable'
5758
shell: bash
58-
- run: ./setup.sh -t -p version -n 2 stable | grep -x 'stable:2:x64|stable:2.10.5:x64'
59+
- run: ./setup.sh -t -p beta | grep 'beta'
5960
shell: bash
60-
- run: ./setup.sh -t -p version -n 2 beta | grep -x 'beta:2:x64|beta:2.13.0-0.4.pre:x64'
61+
- run: ./setup.sh -t -p beta | grep '3.1.0-9.0.pre'
6162
shell: bash
62-
- run: ./setup.sh -t -p version -n 2 any | grep -x 'any:2:x64|beta:2.13.0-0.4.pre:x64'
63+
- run: ./setup.sh -t -p master | grep 'master'
6364
shell: bash
64-
- run: ./setup.sh -t -p version -n 3 any | grep -x 'any:3:x64|stable:3.0.5:x64'
65+
- run: ./setup.sh -t -p -n 2 stable | grep '2.10.5'
6566
shell: bash
66-
- run: ./setup.sh -t -p version -n 3 -a arm64 any | grep -x 'any:3:arm64|stable:3.0.5:arm64'
67+
- run: ./setup.sh -t -p -n 2 beta | grep '2.13.0-0.4.pre'
6768
shell: bash
68-
- run: ./setup.sh -t -p version -n any -a arm64 stable | grep -x 'stable:any:arm64|stable:3.0.5:arm64'
69+
- run: ./setup.sh -t -p -n 2 any | grep 'beta'
6970
shell: bash
70-
- run: ./setup.sh -t -p version -n 1 stable | grep -x 'stable:1:x64|stable:1.22.6:x64'
71+
- run: ./setup.sh -t -p -n 2 any | grep '2.13.0-0.4.pre'
7172
shell: bash
72-
- run: ./setup.sh -t -p version -n v1 stable | grep -x 'stable:v1:x64|stable:v1.12.13+hotfix.9:x64'
73+
- run: ./setup.sh -t -p -n 3 any | grep 'stable'
7374
shell: bash
74-
- run: ./setup.sh -t -p version -n 0 any | grep -x 'any:0:x64|beta:v0.11.13:x64'
75+
- run: ./setup.sh -t -p -n 3 any | grep '3.0.5'
7576
shell: bash
76-
- run: ./setup.sh -t -p version -n v0 any | grep -x 'any:v0:x64|beta:v0.11.13:x64'
77+
- run: ./setup.sh -t -p -n 3 -a arm64 any | grep 'arm64'
7778
shell: bash
78-
test_cache_key:
79-
runs-on: macos-latest
80-
steps:
81-
- uses: actions/checkout@v3
82-
- run: ./setup.sh -t -p cache-key | grep -x 'flutter-macos-stable-3.0.5-x64-f1875d570e39de09040c8f79aa13cc56baab8db1'
79+
- run: ./setup.sh -t -p -n any -a arm64 stable | grep 'stable'
8380
shell: bash
84-
- run: ./setup.sh -t -p cache-key stable | grep -x 'flutter-macos-stable-3.0.5-x64-f1875d570e39de09040c8f79aa13cc56baab8db1'
81+
- run: ./setup.sh -t -p -n any -a arm64 stable | grep '3.0.5'
8582
shell: bash
86-
- run: ./setup.sh -t -p cache-key beta | grep -x 'flutter-macos-beta-3.1.0-9.0.pre-x64-f28e570c8cb12a004fae2d796d0d9cd46603bde9'
83+
- run: ./setup.sh -t -p -n any -a arm64 stable | grep 'arm64'
8784
shell: bash
88-
- run: ./setup.sh -t -p cache-key master | grep -x 'flutter-macos-master-master-x64-master'
85+
- run: ./setup.sh -t -p -n 1 stable | grep '1.22.6'
8986
shell: bash
90-
- run: ./setup.sh -t -p cache-key -n 2 stable | grep -x 'flutter-macos-stable-2.10.5-x64-5464c5bac742001448fe4fc0597be939379f88ea'
87+
- run: ./setup.sh -t -p -n v1 stable | grep 'v1.12.13+hotfix.9'
9188
shell: bash
92-
- run: ./setup.sh -t -p cache-key -n 2 beta | grep -x 'flutter-macos-beta-2.13.0-0.4.pre-x64-25caf1461b8f643092a9f6f5b224453b5c057d10'
89+
- run: ./setup.sh -t -p -n 0 any | grep 'beta'
9390
shell: bash
94-
- run: ./setup.sh -t -p cache-key -n 2 any | grep -x 'flutter-macos-beta-2.13.0-0.4.pre-x64-25caf1461b8f643092a9f6f5b224453b5c057d10'
91+
- run: ./setup.sh -t -p -n 0 any | grep 'v0.11.13'
9592
shell: bash
96-
- run: ./setup.sh -t -p cache-key -n 3 any | grep -x 'flutter-macos-stable-3.0.5-x64-f1875d570e39de09040c8f79aa13cc56baab8db1'
93+
- run: ./setup.sh -t -p -n v0 any | grep 'beta'
9794
shell: bash
98-
- run: ./setup.sh -t -p cache-key -n 3 -a arm64 any | grep -x 'flutter-macos-stable-3.0.5-arm64-f1875d570e39de09040c8f79aa13cc56baab8db1'
95+
- run: ./setup.sh -t -p -n v0 any | grep 'v0.11.13'
9996
shell: bash
100-
- run: ./setup.sh -t -p cache-key -n any -a arm64 stable | grep -x 'flutter-macos-stable-3.0.5-arm64-f1875d570e39de09040c8f79aa13cc56baab8db1'
97+
- run: ./setup.sh -t -p | grep 'flutter-macos-stable-3.0.5-x64-f1875d570e39de09040c8f79aa13cc56baab8db1'
10198
shell: bash
102-
- run: ./setup.sh -t -p cache-key -n 1 stable | grep -x 'flutter-macos-stable-1.22.6-x64-9b2d32b605630f28625709ebd9d78ab3016b2bf6'
99+
- run: ./setup.sh -t -p stable | grep 'flutter-macos-stable-3.0.5-x64-f1875d570e39de09040c8f79aa13cc56baab8db1'
103100
shell: bash
104-
- run: ./setup.sh -t -p cache-key -n v1 stable | grep -x 'flutter-macos-stable-v1.12.13+hotfix.9-x64-f139b11009aeb8ed2a3a3aa8b0066e482709dde3'
101+
- run: ./setup.sh -t -p beta | grep 'flutter-macos-beta-3.1.0-9.0.pre-x64-f28e570c8cb12a004fae2d796d0d9cd46603bde9'
105102
shell: bash
106-
- run: ./setup.sh -t -p cache-key -n 0 any | grep -x 'flutter-macos-beta-v0.11.13-x64-58c8489fcdb4e4ef6c010117584c9b23d15221aa'
103+
- run: ./setup.sh -t -p master | grep 'flutter-macos-master-master-x64-master'
107104
shell: bash
108-
- run: ./setup.sh -t -p cache-key -n v0 any | grep -x 'flutter-macos-beta-v0.11.13-x64-58c8489fcdb4e4ef6c010117584c9b23d15221aa'
105+
- run: ./setup.sh -t -p -n 2 stable | grep 'flutter-macos-stable-2.10.5-x64-5464c5bac742001448fe4fc0597be939379f88ea'
109106
shell: bash
110-
- run: ./setup.sh -t -p cache-key -k 'custom-:channel:-:version:-:hash:' | grep -x 'custom-stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1'
107+
- run: ./setup.sh -t -p -n 2 beta | grep 'flutter-macos-beta-2.13.0-0.4.pre-x64-25caf1461b8f643092a9f6f5b224453b5c057d10'
111108
shell: bash
112-
- run: ./setup.sh -t -p cache-key -k 'custom-:channel:-:version:-:sha256:' | grep -x 'custom-stable-3.0.5-e79a04dcfd1b583e5831433fc200800ba0d1e9fe4567cb661479bd2542d4c685'
109+
- run: ./setup.sh -t -p -n 2 any | grep 'flutter-macos-beta-2.13.0-0.4.pre-x64-25caf1461b8f643092a9f6f5b224453b5c057d10'
113110
shell: bash
114-
test_cache_path:
115-
runs-on: ubuntu-latest
116-
steps:
117-
- uses: actions/checkout@v3
118-
- run: ./setup.sh -t -p cache-path | grep -x '/home/runner/work/_temp/flutter/stable-3.0.5-x64'
111+
- run: ./setup.sh -t -p -n 3 any | grep 'flutter-macos-stable-3.0.5-x64-f1875d570e39de09040c8f79aa13cc56baab8db1'
112+
shell: bash
113+
- run: ./setup.sh -t -p -n 3 -a arm64 any | grep 'flutter-macos-stable-3.0.5-arm64-f1875d570e39de09040c8f79aa13cc56baab8db1'
114+
shell: bash
115+
- run: ./setup.sh -t -p -n any -a arm64 stable | grep 'flutter-macos-stable-3.0.5-arm64-f1875d570e39de09040c8f79aa13cc56baab8db1'
116+
shell: bash
117+
- run: ./setup.sh -t -p -n 1 stable | grep 'flutter-macos-stable-1.22.6-x64-9b2d32b605630f28625709ebd9d78ab3016b2bf6'
118+
shell: bash
119+
- run: ./setup.sh -t -p -n v1 stable | grep 'flutter-macos-stable-v1.12.13+hotfix.9-x64-f139b11009aeb8ed2a3a3aa8b0066e482709dde3'
120+
shell: bash
121+
- run: ./setup.sh -t -p -n 0 any | grep 'flutter-macos-beta-v0.11.13-x64-58c8489fcdb4e4ef6c010117584c9b23d15221aa'
122+
shell: bash
123+
- run: ./setup.sh -t -p -n v0 any | grep 'flutter-macos-beta-v0.11.13-x64-58c8489fcdb4e4ef6c010117584c9b23d15221aa'
124+
shell: bash
125+
- run: ./setup.sh -t -p | grep '/Users/runner/work/_temp/flutter/stable-3.0.5-x64'
126+
shell: bash
127+
- run: ./setup.sh -t -p stable | grep '/Users/runner/work/_temp/flutter/stable-3.0.5-x64'
128+
shell: bash
129+
- run: ./setup.sh -t -p beta | grep '/Users/runner/work/_temp/flutter/beta-3.1.0-9.0.pre-x64'
119130
shell: bash
120-
- run: ./setup.sh -t -p cache-path stable | grep -x '/home/runner/work/_temp/flutter/stable-3.0.5-x64'
131+
- run: ./setup.sh -t -p master | grep '/Users/runner/work/_temp/flutter/master-master-x64'
121132
shell: bash
122-
- run: ./setup.sh -t -p cache-path beta | grep -x '/home/runner/work/_temp/flutter/beta-3.1.0-9.0.pre-x64'
133+
- run: ./setup.sh -t -p -k 'custom-:channel:-:version:-:hash:' | grep 'custom-stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1'
123134
shell: bash
124-
- run: ./setup.sh -t -p cache-path master | grep -x '/home/runner/work/_temp/flutter/master-master-x64'
135+
- run: ./setup.sh -t -p -k 'custom-:channel:-:version:-:sha256:' | grep 'custom-stable-3.0.5-e79a04dcfd1b583e5831433fc200800ba0d1e9fe4567cb661479bd2542d4c685'
125136
shell: bash
126-
- run: ./setup.sh -t -p cache-path -c '/tmp/flutter/:channel:-:version:-:hash:' | grep -x '/tmp/flutter/stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1'
137+
- run: ./setup.sh -t -p -c '/tmp/flutter/:channel:-:version:-:hash:' | grep '/tmp/flutter/stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1'
127138
shell: bash

action.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,17 @@ inputs:
2828
architecture:
2929
description: 'The architecture of Flutter SDK executable (x64 or arm64)'
3030
required: false
31-
default: ${{ runner.arch }}
31+
default: '${{ runner.arch }}'
3232
runs:
3333
using: 'composite'
3434
steps:
35-
- id: flutter-action-cache-path-builder
36-
run: echo "::set-output name=cache-path::$($GITHUB_ACTION_PATH/setup.sh -p cache-path -c '${{ inputs.cache-path }}' -n '${{ inputs.flutter-version }}' -a '${{ inputs.architecture }}' ${{ inputs.channel }})"
37-
shell: bash
38-
- if: ${{ inputs.cache == 'true' }}
39-
id: flutter-action-cache-key-builder
40-
run: echo "::set-output name=cache-key::$($GITHUB_ACTION_PATH/setup.sh -p cache-key -k ${{ inputs.cache-key }} -n '${{ inputs.flutter-version }}' -a '${{ inputs.architecture }}' ${{ inputs.channel }})"
35+
- id: flutter-action
36+
run: $GITHUB_ACTION_PATH/setup.sh -p -c '${{ inputs.cache-path }}' -n '${{ inputs.flutter-version }}' -a '${{ inputs.architecture }}' ${{ inputs.channel }}
4137
shell: bash
4238
- if: ${{ inputs.cache == 'true' }}
4339
uses: actions/cache@v3
4440
with:
45-
path: ${{ steps.flutter-action-cache-path-builder.outputs.cache-path }}
46-
key: ${{ steps.flutter-action-cache-key-builder.outputs.cache-key }}
47-
- run: $GITHUB_ACTION_PATH/setup.sh -c '${{ steps.flutter-action-cache-path-builder.outputs.cache-path }}' -n '${{ inputs.flutter-version }}' -a '${{ inputs.architecture }}' ${{ inputs.channel }}
41+
path: ${{ steps.flutter-action.outputs.cache-path }}
42+
key: ${{ steps.flutter-action.outputs.cache-key }}
43+
- 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 }}
4844
shell: bash

setup.sh

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ download_archive() {
6767

6868
curl --connect-timeout 15 --retry 5 "$archive_url" >"$archive_local"
6969

70-
# Create the target folder
7170
mkdir -p "$2"
7271

7372
if [[ "$archive_name" == *zip ]]; then
@@ -92,11 +91,11 @@ USE_TEST_FIXTURE=false
9291
ARCH=""
9392
VERSION=""
9493

95-
while getopts 'tc:k:p:a:n:' flag; do
94+
while getopts 'tc:k:pa:n:' flag; do
9695
case "$flag" in
9796
c) CACHE_PATH="$OPTARG" ;;
9897
k) CACHE_KEY="$OPTARG" ;;
99-
p) PRINT_MODE="$OPTARG" ;;
98+
p) PRINT_MODE=true ;;
10099
t) USE_TEST_FIXTURE=true ;;
101100
a) ARCH="$(echo "$OPTARG" | awk '{print tolower($0)}')" ;;
102101
n) VERSION="$OPTARG" ;;
@@ -154,72 +153,43 @@ expand_key() {
154153
echo "$expanded_key"
155154
}
156155

157-
print_version() {
158-
version_debug=$(echo "$VERSION_MANIFEST" | jq -j '.channel,":",.version,":",.dart_sdk_arch')
159-
echo "$CHANNEL:$VERSION:$ARCH|$version_debug"
160-
}
161-
162-
if [[ -n "$PRINT_MODE" ]]; then
163-
if [[ "$CHANNEL" == master ]]; then
164-
if [[ "$PRINT_MODE" == version ]]; then
165-
echo "master:master:$ARCH|master:master:$ARCH"
166-
exit 0
167-
fi
168-
169-
VERSION_MANIFEST="{\"channel\":\"$CHANNEL\",\"version\":\"$CHANNEL\",\"dart_sdk_arch\":\"$ARCH\",\"hash\":\"$CHANNEL\",\"sha256\":\"$CHANNEL\"}"
170-
171-
if [[ "$PRINT_MODE" == cache-key ]]; then
172-
expanded_key=$(expand_key "$CACHE_KEY")
173-
174-
echo "$expanded_key"
175-
exit 0
176-
fi
177-
178-
if [[ "$PRINT_MODE" == cache-path ]]; then
179-
cache_path=$(transform_path "$CACHE_PATH")
180-
expanded_path=$(expand_key "$cache_path")
181-
182-
echo "$expanded_path"
183-
exit 0
184-
fi
185-
186-
exit 1
187-
fi
188-
156+
if [[ "$PRINT_MODE" == true ]]; then
189157
if [[ "$USE_TEST_FIXTURE" == true ]]; then
190158
RELEASE_MANIFEST=$(cat "$MANIFEST_TEST_FIXTURE")
191159
else
192160
RELEASE_MANIFEST=$(curl --silent --connect-timeout 15 --retry 5 "$MANIFEST_URL")
193161
fi
194162

195-
VERSION_MANIFEST=$(get_version_manifest)
163+
if [[ "$CHANNEL" == master ]]; then
164+
VERSION_MANIFEST="{\"channel\":\"$CHANNEL\",\"version\":\"$CHANNEL\",\"dart_sdk_arch\":\"$ARCH\",\"hash\":\"$CHANNEL\",\"sha256\":\"$CHANNEL\"}"
165+
else
166+
VERSION_MANIFEST=$(get_version_manifest)
167+
fi
196168

197169
if [[ -z "$VERSION_MANIFEST" ]]; then
198170
not_found_error "$CHANNEL" "$VERSION" "$ARCH"
199171
exit 1
200172
fi
201173

202-
if [[ "$PRINT_MODE" == version ]]; then
203-
print_version
204-
exit 0
205-
fi
206-
207-
if [[ "$PRINT_MODE" == cache-key ]]; then
208-
expanded_key=$(expand_key "$CACHE_KEY")
174+
version_info=$(echo "$VERSION_MANIFEST" | jq -j '.channel,":",.version,":",.dart_sdk_arch')
209175

210-
echo "$expanded_key"
211-
exit 0
176+
if [[ "$version_info" == *null* ]]; then
177+
not_found_error "$CHANNEL" "$VERSION" "$ARCH"
178+
exit 1
212179
fi
213180

214-
if [[ "$PRINT_MODE" == cache-path ]]; then
215-
cache_path=$(transform_path "$CACHE_PATH")
216-
expanded_path=$(expand_key "$cache_path")
181+
echo "::set-output name=channel::$(echo "$version_info" | awk -F ':' '{print $1}')"
182+
echo "::set-output name=version::$(echo "$version_info" | awk -F ':' '{print $2}')"
183+
echo "::set-output name=architecture::$(echo "$version_info" | awk -F ':' '{print $3}')"
217184

218-
echo "$expanded_path"
219-
exit 0
220-
fi
185+
expanded_key=$(expand_key "$CACHE_KEY")
186+
echo "::set-output name=cache-key::$expanded_key"
221187

222-
exit 1
188+
cache_path=$(transform_path "$CACHE_PATH")
189+
expanded_path=$(expand_key "$cache_path")
190+
191+
echo "::set-output name=cache-path::$expanded_path"
192+
exit 0
223193
fi
224194

225195
CACHE_PATH=$(transform_path "$CACHE_PATH")
@@ -240,7 +210,6 @@ if [[ ! -x "$SDK_CACHE/bin/flutter" ]]; then
240210

241211
ARCHIVE_PATH=$(echo "$VERSION_MANIFEST" | jq -r '.archive')
242212
download_archive "$ARCHIVE_PATH" "$SDK_CACHE"
243-
print_version
244213
fi
245214
fi
246215

0 commit comments

Comments
 (0)