Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.

Commit 4f9f307

Browse files
authored
DIOS-1960 using locally stored action (#45)
1 parent 4226f95 commit 4f9f307

File tree

8 files changed

+13958
-1
lines changed

8 files changed

+13958
-1
lines changed

.github/actions/.DS_Store

6 KB
Binary file not shown.
6 KB
Binary file not shown.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: 'Flutter action'
2+
description: 'Setup your runner with Flutter environment'
3+
author: 'Alif Rachmawadi'
4+
branding:
5+
icon: 'maximize'
6+
color: 'blue'
7+
inputs:
8+
flutter-version:
9+
description: 'The Flutter version to make available on the path'
10+
required: false
11+
default: 'any'
12+
channel:
13+
description: 'The Flutter build release channel'
14+
required: false
15+
default: 'stable'
16+
cache:
17+
description: 'Cache the Flutter SDK'
18+
required: false
19+
default: false
20+
cache-key:
21+
description: 'Identifier for the Flutter SDK cache'
22+
required: false
23+
default: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
24+
cache-path:
25+
description: 'Flutter SDK cache path'
26+
required: false
27+
default: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:'
28+
architecture:
29+
description: 'The architecture of Flutter SDK executable (x64 or arm64)'
30+
required: false
31+
default: '${{ runner.arch }}'
32+
outputs:
33+
CACHE-PATH:
34+
value: '${{ steps.flutter-action.outputs.CACHE-PATH }}'
35+
CACHE-KEY:
36+
value: '${{ steps.flutter-action.outputs.CACHE-KEY }}'
37+
CHANNEL:
38+
value: '${{ steps.flutter-action.outputs.CHANNEL }}'
39+
VERSION:
40+
value: '${{ steps.flutter-action.outputs.VERSION }}'
41+
ARCHITECTURE:
42+
value: '${{ steps.flutter-action.outputs.ARCHITECTURE }}'
43+
runs:
44+
using: 'composite'
45+
steps:
46+
- id: flutter-action
47+
run: $GITHUB_ACTION_PATH/setup.sh -p -c '${{ inputs.cache-path }}' -k '${{ inputs.cache-key }}' -n '${{ inputs.flutter-version }}' -a '${{ inputs.architecture }}' ${{ inputs.channel }}
48+
shell: bash
49+
- if: ${{ inputs.cache == 'true' }}
50+
uses: actions/cache@v3
51+
with:
52+
path: ${{ steps.flutter-action.outputs.CACHE-PATH }}
53+
key: ${{ steps.flutter-action.outputs.CACHE-KEY }}-${{ hashFiles('**/pubspec.lock') }}
54+
restore-keys: |
55+
${{ steps.flutter-action.outputs.CACHE-KEY }}-${{ hashFiles('**/pubspec.lock') }}
56+
${{ steps.flutter-action.outputs.CACHE-KEY }}
57+
- 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 }}
58+
shell: bash
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
#!/bin/bash
2+
3+
check_command() {
4+
command -v "$1" >/dev/null 2>&1
5+
}
6+
7+
if ! check_command jq; then
8+
echo "jq not found, please install it, https://stedolan.github.io/jq/download/"
9+
exit 1
10+
fi
11+
12+
OS_NAME=$(echo "$RUNNER_OS" | awk '{print tolower($0)}')
13+
MANIFEST_BASE_URL="https://storage.googleapis.com/flutter_infra_release/releases"
14+
MANIFEST_JSON_PATH="releases_$OS_NAME.json"
15+
MANIFEST_URL="$MANIFEST_BASE_URL/$MANIFEST_JSON_PATH"
16+
17+
filter_by_channel() {
18+
jq --arg channel "$1" '[.releases[] | select($channel == "any" or .channel == $channel)]'
19+
}
20+
21+
filter_by_arch() {
22+
jq --arg arch "$1" '[.[] | select(.dart_sdk_arch == $arch or ($arch == "x64" and (has("dart_sdk_arch") | not)))]'
23+
}
24+
25+
filter_by_version() {
26+
jq --arg version "$1" '.[].version |= gsub("^v"; "") | (if $version == "any" then .[0] else (map(select(.version == $version or (.version | startswith(($version | sub("\\.x$"; "")) + ".")) and .version != $version)) | .[0]) end)'
27+
}
28+
29+
not_found_error() {
30+
echo "Unable to determine Flutter version for channel: $1 version: $2 architecture: $3"
31+
}
32+
33+
transform_path() {
34+
if [[ "$OS_NAME" == windows ]]; then
35+
echo "$1" | sed -e 's/^\///' -e 's/\//\\/g'
36+
else
37+
echo "$1"
38+
fi
39+
}
40+
41+
download_archive() {
42+
archive_url="$MANIFEST_BASE_URL/$1"
43+
archive_name=$(basename "$1")
44+
archive_local="$RUNNER_TEMP/$archive_name"
45+
46+
curl --connect-timeout 15 --retry 5 "$archive_url" >"$archive_local"
47+
48+
mkdir -p "$2"
49+
50+
if [[ "$archive_name" == *zip ]]; then
51+
unzip -q -o "$archive_local" -d "$RUNNER_TEMP"
52+
# Remove the folder again so that the move command can do a simple rename
53+
# instead of moving the content into the target folder.
54+
# This is a little bit of a hack since the "mv --no-target-directory"
55+
# linux option is not available here
56+
rm -r "$2"
57+
mv "$RUNNER_TEMP"/flutter "$2"
58+
else
59+
tar xf "$archive_local" -C "$2" --strip-components=1
60+
fi
61+
62+
rm "$archive_local"
63+
}
64+
65+
CACHE_PATH=""
66+
CACHE_KEY=""
67+
PRINT_ONLY=""
68+
TEST_MODE=false
69+
ARCH=""
70+
VERSION=""
71+
72+
while getopts 'tc:k:pa:n:' flag; do
73+
case "$flag" in
74+
c) CACHE_PATH="$OPTARG" ;;
75+
k) CACHE_KEY="$OPTARG" ;;
76+
p) PRINT_ONLY=true ;;
77+
t) TEST_MODE=true ;;
78+
a) ARCH="$(echo "$OPTARG" | awk '{print tolower($0)}')" ;;
79+
n) VERSION="$OPTARG" ;;
80+
?) exit 2 ;;
81+
esac
82+
done
83+
84+
ARR_CHANNEL=("${@:$OPTIND:1}")
85+
CHANNEL="${ARR_CHANNEL[0]}"
86+
87+
[[ -z $CHANNEL ]] && CHANNEL=stable
88+
[[ -z $VERSION ]] && VERSION=any
89+
[[ -z $ARCH ]] && ARCH=x64
90+
[[ -z $CACHE_PATH ]] && CACHE_PATH="$RUNNER_TEMP/flutter/:channel:-:version:-:arch:"
91+
[[ -z $CACHE_KEY ]] && CACHE_KEY="flutter-:os:-:channel:-:version:-:arch:-:hash:"
92+
93+
if [[ "$TEST_MODE" == true ]]; then
94+
RELEASE_MANIFEST=$(cat "$(dirname -- "${BASH_SOURCE[0]}")/test/$MANIFEST_JSON_PATH")
95+
else
96+
RELEASE_MANIFEST=$(curl --silent --connect-timeout 15 --retry 5 "$MANIFEST_URL")
97+
fi
98+
99+
if [[ "$CHANNEL" == "master" ]]; then
100+
VERSION_MANIFEST="{\"channel\":\"$CHANNEL\",\"version\":\"$CHANNEL\",\"dart_sdk_arch\":\"$ARCH\",\"hash\":\"$CHANNEL\",\"sha256\":\"$CHANNEL\"}"
101+
else
102+
VERSION_MANIFEST=$(echo "$RELEASE_MANIFEST" | filter_by_channel "$CHANNEL" | filter_by_arch "$ARCH" | filter_by_version "$VERSION")
103+
fi
104+
105+
if [[ "$VERSION_MANIFEST" == *null* ]]; then
106+
not_found_error "$CHANNEL" "$VERSION" "$ARCH"
107+
exit 1
108+
fi
109+
110+
expand_key() {
111+
version_channel=$(echo "$VERSION_MANIFEST" | jq -r '.channel')
112+
version_version=$(echo "$VERSION_MANIFEST" | jq -r '.version')
113+
version_arch=$(echo "$VERSION_MANIFEST" | jq -r '.dart_sdk_arch // "x64"')
114+
version_hash=$(echo "$VERSION_MANIFEST" | jq -r '.hash')
115+
version_sha_256=$(echo "$VERSION_MANIFEST" | jq -r '.sha256')
116+
117+
expanded_key="${1/:channel:/$version_channel}"
118+
expanded_key="${expanded_key/:version:/$version_version}"
119+
expanded_key="${expanded_key/:arch:/$version_arch}"
120+
expanded_key="${expanded_key/:hash:/$version_hash}"
121+
expanded_key="${expanded_key/:sha256:/$version_sha_256}"
122+
expanded_key="${expanded_key/:os:/$OS_NAME}"
123+
124+
echo "$expanded_key"
125+
}
126+
127+
CACHE_KEY=$(expand_key "$CACHE_KEY")
128+
CACHE_PATH=$(expand_key "$(transform_path "$CACHE_PATH")")
129+
130+
if [[ "$PRINT_ONLY" == true ]]; then
131+
version_info=$(echo "$VERSION_MANIFEST" | jq -j '.channel,":",.version,":",.dart_sdk_arch // "x64"')
132+
133+
info_channel=$(echo "$version_info" | awk -F ':' '{print $1}')
134+
info_version=$(echo "$version_info" | awk -F ':' '{print $2}')
135+
info_architecture=$(echo "$version_info" | awk -F ':' '{print $3}')
136+
137+
if [[ "$TEST_MODE" == true ]]; then
138+
echo "CHANNEL=$info_channel"
139+
echo "VERSION=$info_version"
140+
echo "ARCHITECTURE=$info_architecture"
141+
echo "CACHE-KEY=$CACHE_KEY"
142+
echo "CACHE-PATH=$CACHE_PATH"
143+
exit 0
144+
fi
145+
146+
{
147+
echo "CHANNEL=$info_channel"
148+
echo "VERSION=$info_version"
149+
echo "ARCHITECTURE=$info_architecture"
150+
echo "CACHE-KEY=$CACHE_KEY"
151+
echo "CACHE-PATH=$CACHE_PATH"
152+
} >>"$GITHUB_OUTPUT"
153+
154+
exit 0
155+
fi
156+
157+
if [[ ! -x "$CACHE_PATH/bin/flutter" ]]; then
158+
if [[ "$CHANNEL" == "master" ]]; then
159+
git clone -b master https://github.com/flutter/flutter.git "$CACHE_PATH"
160+
else
161+
archive_url=$(echo "$VERSION_MANIFEST" | jq -r '.archive')
162+
download_archive "$archive_url" "$CACHE_PATH"
163+
fi
164+
fi
165+
166+
{
167+
echo "FLUTTER_ROOT=$CACHE_PATH"
168+
echo "PUB_CACHE=$CACHE_PATH/.pub-cache"
169+
} >>"$GITHUB_ENV"
170+
171+
{
172+
echo "$CACHE_PATH/bin"
173+
echo "$CACHE_PATH/bin/cache/dart-sdk/bin"
174+
echo "$CACHE_PATH/.pub-cache/bin"
175+
} >>"$GITHUB_PATH"

0 commit comments

Comments
 (0)