Skip to content

Commit

Permalink
test mode and cache key builder (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
subosito authored Jul 24, 2022
1 parent ea686d7 commit 5486469
Show file tree
Hide file tree
Showing 7 changed files with 12,421 additions and 87 deletions.
139 changes: 71 additions & 68 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,93 +12,96 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
channel: [stable, beta]
channel: [stable, beta, master]
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/checkout@v3
- uses: ./
with:
channel: ${{ matrix.channel }}
- name: Print FLUTTER_ROOT
- run: dart --version
shell: bash
run: echo "FLUTTER_ROOT set to $FLUTTER_ROOT"
- name: Print PUB_CACHE
- run: flutter --version
shell: bash
run: echo "PUB_CACHE set to $PUB_CACHE"
- name: Run dart --version
shell: bash
run: dart --version
- name: Run flutter --version
shell: bash
run: flutter --version
test_version:
runs-on: ubuntu-latest
test_cache:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
version: [ 2.5.3, 2.x, 1, v1.12 ]
operating-system: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/checkout@v3
- uses: ./
with:
channel: stable
flutter-version: ${{ matrix.version }}
- name: Run dart --version
cache: true
- run: dart --version
shell: bash
run: dart --version
- name: Run flutter --version
- run: flutter --version
shell: bash
run: flutter --version
test_master_channel:
runs-on: windows-latest
test_version:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: ./
with:
channel: master
- name: Run dart --version
- uses: actions/checkout@v3
- run: ./setup.sh -p version | grep -x 'stable:any:x64|stable:3.0.5:x64'
shell: bash
run: dart --version
- name: Run flutter --version
- run: ./setup.sh -p version stable | grep -x 'stable:any:x64|stable:3.0.5:x64'
shell: bash
run: flutter --version
test_any_channel:
runs-on: ubuntu-latest
strategy:
matrix:
version: [ 2, any ]
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: ./
with:
channel: any
flutter-version: ${{ matrix.version }}
- name: Run dart --version
- run: ./setup.sh -p version beta | grep -x 'beta:any:x64|beta:3.1.0-9.0.pre:x64'
shell: bash
run: dart --version
- name: Run flutter --version
- run: ./setup.sh -p version master | grep -x 'master:master:x64|master:master:x64'
shell: bash
run: flutter --version
test_cache:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
- run: ./setup.sh -p version stable 2 | grep -x 'stable:2:x64|stable:2.10.5:x64'
shell: bash
- run: ./setup.sh -p version beta 2 | grep -x 'beta:2:x64|beta:2.13.0-0.4.pre:x64'
shell: bash
- run: ./setup.sh -p version any 2 | grep -x 'any:2:x64|beta:2.13.0-0.4.pre:x64'
shell: bash
- run: ./setup.sh -p version any 3 | grep -x 'any:3:x64|stable:3.0.5:x64'
shell: bash
- run: ./setup.sh -p version any 3 arm64 | grep -x 'any:3:arm64|stable:3.0.5:arm64'
shell: bash
- run: ./setup.sh -p version stable any arm64 | grep -x 'stable:any:arm64|stable:3.0.5:arm64'
shell: bash
- run: ./setup.sh -p version stable 1 | grep -x 'stable:1:x64|stable:1.22.6:x64'
shell: bash
- run: ./setup.sh -p version stable v1 | grep -x 'stable:v1:x64|stable:v1.12.13+hotfix.9:x64'
shell: bash
- run: ./setup.sh -p version any 0 | grep -x 'any:0:x64|beta:v0.11.13:x64'
shell: bash
- run: ./setup.sh -p version any v0 | grep -x 'any:v0:x64|beta:v0.11.13:x64'
shell: bash
test_cache_key:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: ./
with:
channel: stable
flutter-version: 2.5.0
cache: true
cache-key: key-20220113
cache-path: ${{ runner.tool_cache }}/flutter/2.5.0-stable
- name: Run dart --version
- uses: actions/checkout@v3
- run: ./setup.sh -p cache-key | grep -x 'flutter-macos-x64-stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1'
shell: bash
- run: ./setup.sh -p cache-key stable | grep -x 'flutter-macos-x64-stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1'
shell: bash
- run: ./setup.sh -p cache-key beta | grep -x 'flutter-macos-x64-beta-3.1.0-9.0.pre-f28e570c8cb12a004fae2d796d0d9cd46603bde9'
shell: bash
- run: ./setup.sh -p cache-key master | grep -x 'flutter-macos-x64-master-master-master'
shell: bash
- run: ./setup.sh -p cache-key stable 2 | grep -x 'flutter-macos-x64-stable-2.10.5-5464c5bac742001448fe4fc0597be939379f88ea'
shell: bash
- run: ./setup.sh -p cache-key beta 2 | grep -x 'flutter-macos-x64-beta-2.13.0-0.4.pre-25caf1461b8f643092a9f6f5b224453b5c057d10'
shell: bash
- run: ./setup.sh -p cache-key any 2 | grep -x 'flutter-macos-x64-beta-2.13.0-0.4.pre-25caf1461b8f643092a9f6f5b224453b5c057d10'
shell: bash
- run: ./setup.sh -p cache-key any 3 | grep -x 'flutter-macos-x64-stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1'
shell: bash
- run: ./setup.sh -p cache-key any 3 arm64 | grep -x 'flutter-macos-arm64-stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1'
shell: bash
- run: ./setup.sh -p cache-key stable any arm64 | grep -x 'flutter-macos-arm64-stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1'
shell: bash
- run: ./setup.sh -p cache-key stable 1 | grep -x 'flutter-macos-x64-stable-1.22.6-9b2d32b605630f28625709ebd9d78ab3016b2bf6'
shell: bash
- run: ./setup.sh -p cache-key stable v1 | grep -x 'flutter-macos-x64-stable-v1.12.13+hotfix.9-f139b11009aeb8ed2a3a3aa8b0066e482709dde3'
shell: bash
- run: ./setup.sh -p cache-key any 0 | grep -x 'flutter-macos-x64-beta-v0.11.13-58c8489fcdb4e4ef6c010117584c9b23d15221aa'
shell: bash
- run: ./setup.sh -p cache-key any v0 | grep -x 'flutter-macos-x64-beta-v0.11.13-58c8489fcdb4e4ef6c010117584c9b23d15221aa'
shell: bash
- run: ./setup.sh -p cache-key -k 'custom-:channel:-:version:-:hash:' | grep -x 'custom-stable-3.0.5-f1875d570e39de09040c8f79aa13cc56baab8db1'
shell: bash
run: dart --version
- name: Run flutter --version
- run: ./setup.sh -p cache-key -k 'custom-:channel:-:version:-:sha256:' | grep -x 'custom-stable-3.0.5-e79a04dcfd1b583e5831433fc200800ba0d1e9fe4567cb661479bd2542d4c685'
shell: bash
run: flutter --version
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ steps:
flutter-version: '2.10.x'
channel: 'stable'
cache: true
cache-key: flutter # optional, change this to force refresh cache
cache-key: 'flutter-:os:-:arch:-:channel:-:version:-:hash:' # optional, change this to force refresh cache
cache-path: ${{ runner.tool_cache }}/flutter # optional, change this to specify the cache path
architecture: x64 # optional, x64 or arm64
- run: flutter --version
Expand Down
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ inputs:
cache-key:
description: 'Identifier for the Flutter SDK cache'
required: false
default: 'flutter'
default: 'flutter-:os:-:arch:-:channel:-:version:-:hash:'
cache-path:
description: 'Flutter SDK cache path'
required: false
Expand All @@ -31,10 +31,14 @@ inputs:
runs:
using: 'composite'
steps:
- if: ${{ inputs.cache == 'true' }}
id: flutter-action-cache-key-builder
run: echo "::set-output name=cache-key::$($GITHUB_ACTION_PATH/setup.sh -p cache-key -k ${{ inputs.cache-key }} ${{ inputs.channel }} ${{ inputs.flutter-version }} ${{ inputs.architecture }})"
shell: bash
- if: ${{ inputs.cache == 'true' }}
uses: actions/cache@v3
with:
path: ${{ inputs.cache-path }}
key: ${{ inputs.cache-key }}-${{ runner.os }}-${{ inputs.architecture }}-${{ inputs.channel }}-${{ inputs.flutter-version }}
key: ${{ steps.flutter-action-cache-key-builder.outputs.cache-key }}
- run: $GITHUB_ACTION_PATH/setup.sh -c "${{ inputs.cache-path }}" ${{ inputs.channel }} ${{ inputs.flutter-version }} ${{ inputs.architecture }}
shell: bash
125 changes: 109 additions & 16 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
OS_NAME=$(echo "$RUNNER_OS" | awk '{print tolower($0)}')
MANIFEST_BASE_URL="https://storage.googleapis.com/flutter_infra_release/releases"
MANIFEST_URL="${MANIFEST_BASE_URL}/releases_${OS_NAME}.json"
MANIFEST_TEST_PATH="test/releases_${OS_NAME}.json"
RELEASE_MANIFEST=""
VERSION_MANIFEST=null

# convert version like 2.5.x to 2.5
normalize_version() {
if [[ $1 == *x ]]; then
echo ${1::-2}
if [[ $1 == *.x ]]; then
echo "${1/.x/}"
else
echo $1
echo "$1"
fi
}

Expand All @@ -22,7 +25,7 @@ latest_channel_version() {
}

wildcard_version() {
if [ $2 == *"v"* ]; then # is legacy version format
if [[ $2 == *"v"* ]]; then # is legacy version format
if [[ $1 == any ]]; then
jq --arg version "$2" '.releases | map(select(.version | startswith($version) )) | first'
else
Expand All @@ -46,14 +49,19 @@ get_version() {
}

get_version_manifest() {
releases_manifest=$(curl --silent --connect-timeout 15 --retry 5 $MANIFEST_URL)
version_manifest=$(echo $releases_manifest | get_version $1 $(normalize_version $2))
version_manifest=$(echo $RELEASE_MANIFEST | get_version $1 $(normalize_version $2))

if [[ $version_manifest == null ]]; then
# fallback through legacy version format
echo $releases_manifest | wildcard_version $1 "v$(normalize_version $2)"
version_manifest=$(echo "$RELEASE_MANIFEST" | wildcard_version $1 "v$(normalize_version $2)")
fi

version_arch=$(echo "$version_manifest" | jq -r '.dart_sdk_arch')

if [[ "$version_arch" == null ]]; then
echo "$version_manifest" | jq --arg dart_sdk_arch x64 '.+={dart_sdk_arch:$dart_sdk_arch}'
else
echo $version_manifest
echo "$version_manifest"
fi
}

Expand Down Expand Up @@ -84,14 +92,35 @@ download_archive() {

transform_path() {
if [[ $OS_NAME == windows ]]; then
echo $1 | sed -e 's/^\///' -e 's/\//\\/g'
echo "$1" | sed -e 's/^\///' -e 's/\//\\/g'
else
echo $1
echo "$1"
fi
}

expand_key() {
version_channel=$(echo "$VERSION_MANIFEST" | jq -r '.channel')
version_version=$(echo "$VERSION_MANIFEST" | jq -r '.version')
version_arch=$(echo "$VERSION_MANIFEST" | jq -r '.dart_sdk_arch')
version_hash=$(echo "$VERSION_MANIFEST" | jq -r '.hash')
version_sha_256=$(echo "$VERSION_MANIFEST" | jq -r '.sha256')

expanded_key="${1/:channel:/$version_channel}"
expanded_key="${expanded_key/:version:/$version_version}"
expanded_key="${expanded_key/:arch:/$version_arch}"
expanded_key="${expanded_key/:hash:/$version_hash}"
expanded_key="${expanded_key/:sha256:/$version_sha_256}"
expanded_key="${expanded_key/:os:/$OS_NAME}"

echo "$expanded_key"
}

not_found_error() {
echo "Unable to determine Flutter version for channel: $1 version: $2 architecture: $3"
}

check_command() {
command -v "$1" > /dev/null 2>&1
command -v "$1" >/dev/null 2>&1
}

if ! check_command jq; then
Expand All @@ -100,10 +129,14 @@ if ! check_command jq; then
fi

CACHE_PATH=""
CACHE_KEY=""
PRINT_MODE=""

while getopts 'c:' flag; do
while getopts 'c:k:p:' flag; do
case "${flag}" in
c) CACHE_PATH="$OPTARG" ;;
k) CACHE_KEY="$OPTARG" ;;
p) PRINT_MODE="$OPTARG" ;;
?) exit 2 ;;
esac
done
Expand All @@ -112,18 +145,78 @@ CHANNEL="${@:$OPTIND:1}"
VERSION="${@:$OPTIND+1:1}"
ARCH=$(echo "${@:$OPTIND+2:1}" | awk '{print tolower($0)}')

SDK_CACHE="$(transform_path ${CACHE_PATH})"
PUB_CACHE="$(transform_path ${CACHE_PATH}/.pub-cache)"
# default values
[[ -z $CHANNEL ]] && CHANNEL=stable
[[ -z $VERSION ]] && VERSION=any
[[ -z $ARCH ]] && ARCH=x64
[[ -z $CACHE_PATH ]] && CACHE_PATH=/tmp
[[ -z $CACHE_KEY ]] && CACHE_KEY="flutter-:os:-:arch:-:channel:-:version:-:hash:"

if [[ -n "$PRINT_MODE" ]]; then
if [[ "$CHANNEL" == master ]]; then
if [[ "$PRINT_MODE" == version ]]; then
echo "master:master:$ARCH|master:master:$ARCH"
exit 0
fi

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\"
}"

EXPANDED_KEY=$(expand_key "$CACHE_KEY")
echo "$EXPANDED_KEY"
exit 0
fi

exit 1
fi

RELEASE_MANIFEST=$(cat "$MANIFEST_TEST_PATH")
VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION)

if [[ $VERSION_MANIFEST == null ]]; then
not_found_error $CHANNEL $VERSION $ARCH
exit 1
fi

if [[ "$PRINT_MODE" == version ]]; then
VERSION_DEBUG=$(echo "$VERSION_MANIFEST" | jq -j '.channel,":",.version,":",.dart_sdk_arch')

echo "$CHANNEL:$VERSION:$ARCH|$VERSION_DEBUG"
exit $?
fi

if [[ "$PRINT_MODE" == cache-key ]]; then
EXPANDED_KEY=$(expand_key "$CACHE_KEY")

echo "$EXPANDED_KEY"
exit 0
fi

exit 1
fi

CACHE_PATH=$(transform_path "$CACHE_PATH")
SDK_CACHE=$(expand_key "$CACHE_PATH")
PUB_CACHE=$(expand_key "${SDK_CACHE}/.pub-cache")

if [[ ! -x "${SDK_CACHE}/bin/flutter" ]]; then
if [[ $CHANNEL == master ]]; then
git clone -b master https://github.com/flutter/flutter.git "$SDK_CACHE"
else
RELEASE_MANIFEST=$(curl --silent --connect-timeout 15 --retry 5 "$MANIFEST_URL")
VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION)
if [[ $VERSION_MANIFEST == null ]]; then
echo "Unable to determine Flutter version for channel: $CHANNEL version: $VERSION architecture: $ARCH"
not_found_error $CHANNEL $VERSION $ARCH
exit 1
fi
fi
ARCHIVE_PATH=$(echo $VERSION_MANIFEST | jq -r '.archive')
download_archive "$ARCHIVE_PATH" "$SDK_CACHE"
fi
Expand Down
Loading

0 comments on commit 5486469

Please sign in to comment.