1
0
Fork 0
mirror of https://github.com/subosito/flutter-action.git synced 2024-08-16 10:19:50 +02:00

shellcheck linter

This commit is contained in:
Alif Rachmawadi 2022-07-24 19:30:59 +07:00
parent 54864698df
commit becfb71246
No known key found for this signature in database
GPG key ID: 19EE1E10C3733F31
2 changed files with 151 additions and 145 deletions

View file

@ -4,9 +4,15 @@ on:
branches: branches:
- main - main
pull_request: pull_request:
branches: paths:
- main - setup.sh
- action.yml
jobs: jobs:
lint_shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ludeeus/action-shellcheck@master
test_channel: test_channel:
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
strategy: strategy:

View file

@ -2,8 +2,8 @@
OS_NAME=$(echo "$RUNNER_OS" | awk '{print tolower($0)}') OS_NAME=$(echo "$RUNNER_OS" | awk '{print tolower($0)}')
MANIFEST_BASE_URL="https://storage.googleapis.com/flutter_infra_release/releases" MANIFEST_BASE_URL="https://storage.googleapis.com/flutter_infra_release/releases"
MANIFEST_URL="${MANIFEST_BASE_URL}/releases_${OS_NAME}.json" MANIFEST_URL="$MANIFEST_BASE_URL/releases_$OS_NAME.json"
MANIFEST_TEST_PATH="test/releases_${OS_NAME}.json" MANIFEST_TEST_PATH="test/releases_$OS_NAME.json"
RELEASE_MANIFEST="" RELEASE_MANIFEST=""
VERSION_MANIFEST=null VERSION_MANIFEST=null
@ -42,18 +42,18 @@ get_version() {
if [[ $1 == any && $2 == any ]]; then if [[ $1 == any && $2 == any ]]; then
latest_version latest_version
elif [[ $2 == any ]]; then elif [[ $2 == any ]]; then
latest_channel_version $1 latest_channel_version "$1"
else else
wildcard_version $1 $2 wildcard_version "$1" "$2"
fi fi
} }
get_version_manifest() { get_version_manifest() {
version_manifest=$(echo $RELEASE_MANIFEST | get_version $1 $(normalize_version $2)) version_manifest=$(echo "$RELEASE_MANIFEST" | get_version "$1" "$(normalize_version "$2")")
if [[ $version_manifest == null ]]; then if [[ $version_manifest == null ]]; then
# fallback through legacy version format # fallback through legacy version format
version_manifest=$(echo "$RELEASE_MANIFEST" | wildcard_version $1 "v$(normalize_version $2)") version_manifest=$(echo "$RELEASE_MANIFEST" | wildcard_version "$1" "v$(normalize_version "$2")")
fi fi
version_arch=$(echo "$version_manifest" | jq -r '.dart_sdk_arch') version_arch=$(echo "$version_manifest" | jq -r '.dart_sdk_arch')
@ -67,10 +67,10 @@ get_version_manifest() {
download_archive() { download_archive() {
archive_url="$MANIFEST_BASE_URL/$1" archive_url="$MANIFEST_BASE_URL/$1"
archive_name=$(basename $1) archive_name=$(basename "$1")
archive_local="$RUNNER_TEMP/$archive_name" archive_local="$RUNNER_TEMP/$archive_name"
curl --connect-timeout 15 --retry 5 $archive_url >$archive_local curl --connect-timeout 15 --retry 5 "$archive_url" >"$archive_local"
# Create the target folder # Create the target folder
mkdir -p "$2" mkdir -p "$2"
@ -82,12 +82,12 @@ download_archive() {
# This is a little bit of a hack since the "mv --no-target-directory" # This is a little bit of a hack since the "mv --no-target-directory"
# linux option is not available here # linux option is not available here
rm -r "$2" rm -r "$2"
mv ${RUNNER_TEMP}/flutter "$2" mv "$RUNNER_TEMP"/flutter "$2"
else else
tar xf "$archive_local" -C "$2" --strip-components=1 tar xf "$archive_local" -C "$2" --strip-components=1
fi fi
rm $archive_local rm "$archive_local"
} }
transform_path() { transform_path() {
@ -133,7 +133,7 @@ CACHE_KEY=""
PRINT_MODE="" PRINT_MODE=""
while getopts 'c:k:p:' flag; do while getopts 'c:k:p:' flag; do
case "${flag}" in case "$flag" in
c) CACHE_PATH="$OPTARG" ;; c) CACHE_PATH="$OPTARG" ;;
k) CACHE_KEY="$OPTARG" ;; k) CACHE_KEY="$OPTARG" ;;
p) PRINT_MODE="$OPTARG" ;; p) PRINT_MODE="$OPTARG" ;;
@ -141,9 +141,13 @@ while getopts 'c:k:p:' flag; do
esac esac
done done
CHANNEL="${@:$OPTIND:1}" ARR_CHANNEL=("${@:$OPTIND:1}")
VERSION="${@:$OPTIND+1:1}" ARR_VERSION=("${@:$OPTIND+1:1}")
ARCH=$(echo "${@:$OPTIND+2:1}" | awk '{print tolower($0)}') ARR_ARCH=("${@:$OPTIND+2:1}")
CHANNEL="${ARR_CHANNEL[0]}"
VERSION="${ARR_VERSION[0]}"
ARCH=$(echo "${ARR_ARCH[0]}" | awk '{print tolower($0)}')
# default values # default values
[[ -z $CHANNEL ]] && CHANNEL=stable [[ -z $CHANNEL ]] && CHANNEL=stable
@ -160,17 +164,9 @@ if [[ -n "$PRINT_MODE" ]]; then
fi fi
if [[ "$PRINT_MODE" == cache-key ]]; then if [[ "$PRINT_MODE" == cache-key ]]; then
# MASTER_HASH=$(git ls-remote https://github.com/flutter/flutter.git | head -n 1 | awk '{print $1}') VERSION_MANIFEST="{\"channel\":\"$CHANNEL\",\"version\":\"$CHANNEL\",\"dart_sdk_arch\":\"$ARCH\",\"hash\":\"$CHANNEL\",\"sha256\":\"$CHANNEL\"}"
VERSION_MANIFEST="{
\"channel\":\"$CHANNEL\",
\"version\":\"$CHANNEL\",
\"dart_sdk_arch\":\"$ARCH\",
\"hash\":\"$CHANNEL\",
\"sha256\":\"$CHANNEL\"
}"
EXPANDED_KEY=$(expand_key "$CACHE_KEY") EXPANDED_KEY=$(expand_key "$CACHE_KEY")
echo "$EXPANDED_KEY" echo "$EXPANDED_KEY"
exit 0 exit 0
fi fi
@ -179,10 +175,10 @@ if [[ -n "$PRINT_MODE" ]]; then
fi fi
RELEASE_MANIFEST=$(cat "$MANIFEST_TEST_PATH") RELEASE_MANIFEST=$(cat "$MANIFEST_TEST_PATH")
VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION) VERSION_MANIFEST=$(get_version_manifest "$CHANNEL" "$VERSION")
if [[ $VERSION_MANIFEST == null ]]; then if [[ $VERSION_MANIFEST == null ]]; then
not_found_error $CHANNEL $VERSION $ARCH not_found_error "$CHANNEL" "$VERSION" "$ARCH"
exit 1 exit 1
fi fi
@ -205,26 +201,30 @@ fi
CACHE_PATH=$(transform_path "$CACHE_PATH") CACHE_PATH=$(transform_path "$CACHE_PATH")
SDK_CACHE=$(expand_key "$CACHE_PATH") SDK_CACHE=$(expand_key "$CACHE_PATH")
PUB_CACHE=$(expand_key "${SDK_CACHE}/.pub-cache") PUB_CACHE=$(expand_key "$SDK_CACHE/.pub-cache")
if [[ ! -x "${SDK_CACHE}/bin/flutter" ]]; then if [[ ! -x "$SDK_CACHE/bin/flutter" ]]; then
if [[ $CHANNEL == master ]]; then if [[ $CHANNEL == master ]]; then
git clone -b master https://github.com/flutter/flutter.git "$SDK_CACHE" git clone -b master https://github.com/flutter/flutter.git "$SDK_CACHE"
else else
RELEASE_MANIFEST=$(curl --silent --connect-timeout 15 --retry 5 "$MANIFEST_URL") RELEASE_MANIFEST=$(curl --silent --connect-timeout 15 --retry 5 "$MANIFEST_URL")
VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION) VERSION_MANIFEST=$(get_version_manifest "$CHANNEL" "$VERSION")
if [[ $VERSION_MANIFEST == null ]]; then if [[ $VERSION_MANIFEST == null ]]; then
not_found_error $CHANNEL $VERSION $ARCH not_found_error "$CHANNEL" "$VERSION" "$ARCH"
exit 1 exit 1
fi fi
ARCHIVE_PATH=$(echo $VERSION_MANIFEST | jq -r '.archive') ARCHIVE_PATH=$(echo "$VERSION_MANIFEST" | jq -r '.archive')
download_archive "$ARCHIVE_PATH" "$SDK_CACHE" download_archive "$ARCHIVE_PATH" "$SDK_CACHE"
fi fi
fi fi
echo "FLUTTER_ROOT=${SDK_CACHE}" >>$GITHUB_ENV {
echo "PUB_CACHE=${PUB_CACHE}" >>$GITHUB_ENV echo "FLUTTER_ROOT=$SDK_CACHE"
echo "PUB_CACHE=$PUB_CACHE"
} >>"$GITHUB_ENV"
echo "${SDK_CACHE}/bin" >>$GITHUB_PATH {
echo "${SDK_CACHE}/bin/cache/dart-sdk/bin" >>$GITHUB_PATH echo "$SDK_CACHE/bin"
echo "${PUB_CACHE}/bin" >>$GITHUB_PATH echo "$SDK_CACHE/bin/cache/dart-sdk/bin"
echo "$PUB_CACHE/bin"
} >>"$GITHUB_PATH"