From 49d7a2a9aece4e150575bfaced3415aa3c184c74 Mon Sep 17 00:00:00 2001 From: Alif Rachmawadi Date: Thu, 6 Jan 2022 07:40:25 +0000 Subject: [PATCH] rewrite flutter-action --- .github/workflows/workflow.yml | 12 ++------ action.yml | 12 ++++---- setup.sh | 52 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 14 deletions(-) create mode 100755 setup.sh diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f9ce5a2..fb140cb 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -7,16 +7,10 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest, windows-latest, macos-latest] + channel: [stable, beta, dev] steps: - name: Checkout uses: actions/checkout@v2 - - name: Set Node.js 10.x - uses: actions/setup-node@v1 + - uses: ./ with: - node-version: 10.x - - name: npm install - run: npm install - - name: Lint - run: npm run format-check - - name: npm test - run: npm test + channel: ${{ matrix.channel }} diff --git a/action.yml b/action.yml index 13255a5..9604329 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,9 @@ name: 'Flutter action' description: 'Setup your runner with Flutter environment' author: 'Alif Rachmawadi' +branding: + icon: 'maximize' + color: 'blue' inputs: flutter-version: description: 'The Flutter version to make available on the path' @@ -10,8 +13,7 @@ inputs: required: false default: 'stable' runs: - using: 'node12' - main: 'dist/index.js' -branding: - icon: 'maximize' - color: 'blue' + using: 'composite' + steps: + - run: $GITHUB_ACTION_PATH/setup.sh ${{ inputs.channel }} ${{ inputs.flutter-version }} + shell: bash diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..e28bc62 --- /dev/null +++ b/setup.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +OS_NAME=$(echo "$OS" | awk '{print tolower($0)}') +MANIFEST_URL="https://storage.googleapis.com/flutter_infra_release/releases/releases_$OS_NAME.json" + +# convert version like 2.5.x to 2.5 +normalize_version() { + if [[ $1 == *x ]]; then + echo ${1::-2} + else + echo $1 + fi +} + +latest_version() { + jq --arg channel "$1" '.releases | map(select(.channel==$channel)) | first' +} + +wildcard_version() { + jq --arg channel "$1" --arg version "^$2" '.releases | map(select(.channel==$channel) | select(.version | test($version))) | first' +} + +get_version() { + if [[ -z $2 ]]; then + latest_version $1 + else + wildcard_version $1 $2 + fi +} + +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)) + + if [[ $version_manifest == null ]]; then + # fallback through legacy version format + echo $releases_manifest | wildcard_version $1 "v$(normalize_version $2)" + else + echo $version_manifest + fi +} + +CHANNEL="$1" +VERSION="$2" +VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION) + +echo $OS_NAME +echo $MANIFEST_URL +echo $CHANNEL +echo $VERSION +echo $VERSION_MANIFEST +