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

Add flutter-version-file (#290)

* update README with new info

* setup.sh: update arg parsing to add support for `flutter-version-file` as `-f pubspec.yaml`

* action.yaml: add flutter-version-file

* setup.sh: require `yq` only when -f option is specified

* fix tests and add a new one

* enable shell options: `errexit` and `nounset`

* move falling back to defaults to single place - setup.sh

* action.yaml: reduce number of arguments in the last invocation
This commit is contained in:
Bartek Pacia 2024-04-01 04:03:05 +02:00 committed by GitHub
parent 7564de34b3
commit 0ef13f12a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 159 additions and 57 deletions

View file

@ -76,12 +76,35 @@ jobs:
- run: flutter --version - run: flutter --version
shell: bash shell: bash
test_version_file:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest]
steps:
- name: Clone repository
uses: actions/checkout@v4
- uses: ./
with:
channel: stable
flutter-version-file: test/pubspec.yaml
- name: Verify Dart version
run: dart --version | grep '2.18.6'
shell: bash
- name: Verify Flutter version
run: flutter --version | grep '3.3.10'
shell: bash
test_print_output: test_print_output:
runs-on: macos-latest runs-on: macos-latest
steps: steps:
- name: Clone repository - name: Clone repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- run: ./setup.sh -t -p -f test/pubspec.yaml | grep '3.3.10'
shell: bash
- run: ./setup.sh -t -p | grep 'stable' - run: ./setup.sh -t -p | grep 'stable'
shell: bash shell: bash
- run: ./setup.sh -t -p | grep '3.7.7' - run: ./setup.sh -t -p | grep '3.7.7'
@ -146,15 +169,15 @@ jobs:
shell: bash shell: bash
- run: ./setup.sh -t -p -n 0 any | grep 'flutter-macos-beta-0.11.13-x64-58c8489fcdb4e4ef6c010117584c9b23d15221aa' - run: ./setup.sh -t -p -n 0 any | grep 'flutter-macos-beta-0.11.13-x64-58c8489fcdb4e4ef6c010117584c9b23d15221aa'
shell: bash shell: bash
- run: ./setup.sh -t -p | grep '/Users/runner/work/_temp/flutter/stable-3.7.7-x64' - run: ./setup.sh -t -p | grep '/Users/runner/hostedtoolcache/flutter/stable-3.7.7-x64'
shell: bash shell: bash
- run: ./setup.sh -t -p stable | grep '/Users/runner/work/_temp/flutter/stable-3.7.7-x64' - run: ./setup.sh -t -p stable | grep '/Users/runner/hostedtoolcache/flutter/stable-3.7.7-x64'
shell: bash shell: bash
- run: ./setup.sh -t -p beta | grep '/Users/runner/work/_temp/flutter/beta-3.9.0-0.1.pre-x64' - run: ./setup.sh -t -p beta | grep '/Users/runner/hostedtoolcache/flutter/beta-3.9.0-0.1.pre-x64'
shell: bash shell: bash
- run: ./setup.sh -t -p dev | grep '/Users/runner/work/_temp/flutter/dev-2.11.0-0.1.pre-x64' - run: ./setup.sh -t -p dev | grep '/Users/runner/hostedtoolcache/flutter/dev-2.11.0-0.1.pre-x64'
shell: bash shell: bash
- run: ./setup.sh -t -p master | grep '/Users/runner/work/_temp/flutter/master-any-x64' - run: ./setup.sh -t -p master | grep '/Users/runner/hostedtoolcache/flutter/master-any-x64'
shell: bash shell: bash
- run: ./setup.sh -t -p -k 'custom-:channel:-:version:-:hash:' | grep 'custom-stable-3.7.7-2ad6cd72c040113b47ee9055e722606a490ef0da' - run: ./setup.sh -t -p -k 'custom-:channel:-:version:-:hash:' | grep 'custom-stable-3.7.7-2ad6cd72c040113b47ee9055e722606a490ef0da'
shell: bash shell: bash

View file

@ -5,9 +5,9 @@ macOS.
The following sections show how to configure this action. The following sections show how to configure this action.
## Flutter version ## Specifying Flutter version
Use specific version and channel: ### Use specific version and channel
```yaml ```yaml
steps: steps:
@ -16,12 +16,52 @@ steps:
- name: Set up Flutter - name: Set up Flutter
uses: subosito/flutter-action@v2 uses: subosito/flutter-action@v2
with: with:
flutter-version: 3.19.0
channel: stable channel: stable
flutter-version: 3.19.0
- run: flutter --version - run: flutter --version
``` ```
Use latest release for particular channel: ### Use version from pubspec.yaml
This is inspired by [`actions/setup-go`](https://github.com/actions/setup-go).
```yaml
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version-file: pubspec.yaml # path to pubspec.yaml
- run: flutter --version
```
> [!IMPORTANT]
>
> For `flutter-version-file` to work, you need to have the exact Flutter version
> defined in your pubspec.yaml:
>
> **Good**
>
> ```yaml
> environment:
> sdk: ">=3.3.0 <4.0.0"
> flutter: 3.19.0
> ```
>
> **Bad**
>
> ```yaml
> environment:
> sdk: ">=3.3.0 <4.0.0"
> flutter: ">= 3.19.0 <4.0.0"
> ```
> [!WARNING]
>
> Using `flutter-version-file` requires [`yq`][https://github.com/mikefarah/yq],
> which is not pre-installed in `windows` images. Install it yourself.
```yaml ```yaml
steps: steps:
@ -34,7 +74,7 @@ steps:
- run: flutter --version - run: flutter --version
``` ```
Use latest release for particular version and/or channel: ### Use latest release for particular version and/or channel
```yaml ```yaml
steps: steps:
@ -43,12 +83,12 @@ steps:
- name: Set up Flutter - name: Set up Flutter
uses: subosito/flutter-action@v2 uses: subosito/flutter-action@v2
with: with:
flutter-version: 1.22.x
channel: dev channel: dev
flutter-version: 1.22.x
- run: flutter --version - run: flutter --version
``` ```
Use particular version on any channel: ### Use particular version on any channel
```yaml ```yaml
steps: steps:
@ -57,12 +97,12 @@ steps:
- name: Set up Flutter - name: Set up Flutter
uses: subosito/flutter-action@v2 uses: subosito/flutter-action@v2
with: with:
flutter-version: 3.x
channel: any channel: any
flutter-version: 3.x
- run: flutter --version - run: flutter --version
``` ```
Use particular git reference on master channel: ### Use particular git reference on master channel
```yaml ```yaml
steps: steps:
@ -71,8 +111,8 @@ steps:
- name: Set up Flutter - name: Set up Flutter
uses: subosito/flutter-action@v2 uses: subosito/flutter-action@v2
with: with:
flutter-version: 5b12b74 # tag, commit or branch
channel: master channel: master
flutter-version: 5b12b74 # tag, commit or branch
- run: flutter --version - run: flutter --version
``` ```
@ -94,7 +134,11 @@ steps:
- run: flutter build appbundle - run: flutter build appbundle
``` ```
Build for **iOS** (macOS runners only): ### Build for iOS
> [!NOTE]
>
> Building for iOS requires a macOS runner.
```yaml ```yaml
jobs: jobs:
@ -112,7 +156,7 @@ jobs:
- run: flutter build ios --release --no-codesign - run: flutter build ios --release --no-codesign
``` ```
Build for the **web**: ### Build for the web
```yaml ```yaml
steps: steps:
@ -121,13 +165,13 @@ steps:
- name: Set up Flutter - name: Set up Flutter
uses: subosito/flutter-action@v2 uses: subosito/flutter-action@v2
with: with:
channel: "stable" channel: stable
- run: flutter pub get - run: flutter pub get
- run: flutter test - run: flutter test
- run: flutter build web - run: flutter build web
``` ```
Build for **Windows**: ### Build for Windows
```yaml ```yaml
jobs: jobs:
@ -143,7 +187,7 @@ jobs:
- run: flutter build windows - run: flutter build windows
``` ```
Build for **Linux** desktop: ### Build for Linux desktop
```yaml ```yaml
jobs: jobs:
@ -162,7 +206,11 @@ jobs:
- run: flutter build linux - run: flutter build linux
``` ```
Build for **macOS** desktop: ### Build for macOS desktop
> [!NOTE]
>
> Building for macOS requires a macOS runner.
```yaml ```yaml
jobs: jobs:
@ -174,7 +222,7 @@ jobs:
- name: Set up Flutter - name: Set up Flutter
uses: subosito/flutter-action@v2 uses: subosito/flutter-action@v2
with: with:
channel: "stable" channel: stable
- run: flutter build macos - run: flutter build macos
``` ```
@ -220,7 +268,9 @@ steps:
id: flutter-action id: flutter-action
with: with:
channel: stable channel: stable
- run: | - name: Print outputs
shell: bash
run: |
echo CACHE-PATH=${{ steps.flutter-action.outputs.CACHE-PATH }} echo CACHE-PATH=${{ steps.flutter-action.outputs.CACHE-PATH }}
echo CACHE-KEY=${{ steps.flutter-action.outputs.CACHE-KEY }} echo CACHE-KEY=${{ steps.flutter-action.outputs.CACHE-KEY }}
echo CHANNEL=${{ steps.flutter-action.outputs.CHANNEL }} echo CHANNEL=${{ steps.flutter-action.outputs.CHANNEL }}
@ -228,5 +278,4 @@ steps:
echo ARCHITECTURE=${{ steps.flutter-action.outputs.ARCHITECTURE }} echo ARCHITECTURE=${{ steps.flutter-action.outputs.ARCHITECTURE }}
echo PUB-CACHE-PATH=${{ steps.flutter-action.outputs.PUB-CACHE-PATH }} echo PUB-CACHE-PATH=${{ steps.flutter-action.outputs.PUB-CACHE-PATH }}
echo PUB-CACHE-KEY=${{ steps.flutter-action.outputs.PUB-CACHE-KEY }} echo PUB-CACHE-KEY=${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}
shell: bash
``` ```

View file

@ -6,14 +6,22 @@ branding:
color: blue color: blue
inputs: inputs:
flutter-version:
description: The Flutter version to make available on the path
required: false
default: any
channel: channel:
description: The Flutter build release channel description: The Flutter build release channel
required: false required: false
default: stable default: stable
flutter-version:
description: The Flutter version to make available on the path
required: false
default: ""
flutter-version-file:
description: The pubspec.yaml file with exact Flutter version defined
required: false
default: ""
architecture:
description: The architecture of Flutter SDK executable (x64 or arm64)
required: false
default: "${{ runner.arch }}"
cache: cache:
description: Cache the Flutter SDK description: Cache the Flutter SDK
required: false required: false
@ -21,31 +29,21 @@ inputs:
cache-key: cache-key:
description: Identifier for the Flutter SDK cache description: Identifier for the Flutter SDK cache
required: false required: false
default: "flutter-:os:-:channel:-:version:-:arch:-:hash:" default: ""
pub-cache-key:
description: Identifier for the Dart .pub-cache cache
required: false
default: "flutter-pub:os:-:channel:-:version:-:arch:-:hash:"
cache-path: cache-path:
description: Flutter SDK cache path description: Flutter SDK cache path
required: false required: false
default: "${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:" default: ""
pub-cache-key:
description: Identifier for the Dart .pub-cache cache
required: false
default: ""
pub-cache-path: pub-cache-path:
description: Flutter pub cache path description: Flutter pub cache path
required: false required: false
default: default default: default
architecture:
description: The architecture of Flutter SDK executable (x64 or arm64)
required: false
default: "${{ runner.arch }}"
outputs: outputs:
CACHE-KEY:
value: "${{ steps.flutter-action.outputs.CACHE-KEY }}"
description: Key used to cache the Flutter SDK
CACHE-PATH:
value: "${{ steps.flutter-action.outputs.CACHE-PATH }}"
description: Path to Flutter SDK
CHANNEL: CHANNEL:
value: "${{ steps.flutter-action.outputs.CHANNEL }}" value: "${{ steps.flutter-action.outputs.CHANNEL }}"
description: The selected Flutter release channel description: The selected Flutter release channel
@ -55,6 +53,12 @@ outputs:
ARCHITECTURE: ARCHITECTURE:
value: "${{ steps.flutter-action.outputs.ARCHITECTURE }}" value: "${{ steps.flutter-action.outputs.ARCHITECTURE }}"
description: The selected Flutter CPU architecture description: The selected Flutter CPU architecture
CACHE-KEY:
value: "${{ steps.flutter-action.outputs.CACHE-KEY }}"
description: Key used to cache the Flutter SDK
CACHE-PATH:
value: "${{ steps.flutter-action.outputs.CACHE-PATH }}"
description: Path to Flutter SDK
PUB-CACHE-KEY: PUB-CACHE-KEY:
value: "${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}" value: "${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}"
description: Key used to cache the pub dependencies description: Key used to cache the pub dependencies
@ -74,12 +78,13 @@ runs:
shell: bash shell: bash
run: | run: |
$GITHUB_ACTION_PATH/setup.sh -p \ $GITHUB_ACTION_PATH/setup.sh -p \
-c '${{ inputs.cache-path }}' \
-k '${{ inputs.cache-key }}' \
-d '${{ inputs.pub-cache-path }}' \
-l '${{ inputs.pub-cache-key }}' \
-n '${{ inputs.flutter-version }}' \ -n '${{ inputs.flutter-version }}' \
-f '${{ inputs.flutter-version-file }}' \
-a '${{ inputs.architecture }}' \ -a '${{ inputs.architecture }}' \
-k '${{ inputs.cache-key }}' \
-c '${{ inputs.cache-path }}' \
-l '${{ inputs.pub-cache-key }}' \
-d '${{ inputs.pub-cache-path }}' \
${{ inputs.channel }} ${{ inputs.channel }}
- name: Cache Flutter - name: Cache Flutter
@ -105,7 +110,7 @@ runs:
shell: bash shell: bash
run: | run: |
$GITHUB_ACTION_PATH/setup.sh \ $GITHUB_ACTION_PATH/setup.sh \
-c '${{ steps.flutter-action.outputs.CACHE-PATH }}' \
-n '${{ steps.flutter-action.outputs.VERSION }}' \ -n '${{ steps.flutter-action.outputs.VERSION }}' \
-a '${{ steps.flutter-action.outputs.ARCHITECTURE }}' \ -a '${{ steps.flutter-action.outputs.ARCHITECTURE }}' \
-c '${{ steps.flutter-action.outputs.CACHE-PATH }}' \
${{ steps.flutter-action.outputs.CHANNEL }} ${{ steps.flutter-action.outputs.CHANNEL }}

View file

@ -1,11 +1,12 @@
#!/bin/bash #!/bin/bash
set -eu
check_command() { check_command() {
command -v "$1" >/dev/null 2>&1 command -v "$1" >/dev/null 2>&1
} }
if ! check_command jq; then if ! check_command jq; then
echo "jq not found, please install it, https://stedolan.github.io/jq/download/" echo "jq not found. Install it from https://stedolan.github.io/jq"
exit 1 exit 1
fi fi
@ -76,8 +77,9 @@ PRINT_ONLY=""
TEST_MODE=false TEST_MODE=false
ARCH="" ARCH=""
VERSION="" VERSION=""
VERSION_FILE=""
while getopts 'tc:k:d:l:pa:n:' flag; do while getopts 'tc:k:d:l:pa:n:f:' flag; do
case "$flag" in case "$flag" in
c) CACHE_PATH="$OPTARG" ;; c) CACHE_PATH="$OPTARG" ;;
k) CACHE_KEY="$OPTARG" ;; k) CACHE_KEY="$OPTARG" ;;
@ -87,19 +89,35 @@ while getopts 'tc:k:d:l:pa:n:' flag; do
t) TEST_MODE=true ;; t) TEST_MODE=true ;;
a) ARCH="$(echo "$OPTARG" | awk '{print tolower($0)}')" ;; a) ARCH="$(echo "$OPTARG" | awk '{print tolower($0)}')" ;;
n) VERSION="$OPTARG" ;; n) VERSION="$OPTARG" ;;
f)
VERSION_FILE="$OPTARG"
if [ -n "$VERSION_FILE" ] && ! check_command yq; then
echo "yq not found. Install it from https://mikefarah.gitbook.io/yq"
exit 1
fi
;;
?) exit 2 ;; ?) exit 2 ;;
esac esac
done done
[ -z "$ARCH" ] && ARCH="$ARCH_NAME" [ -z "$ARCH" ] && ARCH="$ARCH_NAME"
if [ -n "$VERSION_FILE" ]; then
if [ -n "$VERSION" ]; then
echo "Cannot specify both a version and a version file"
exit 1
fi
VERSION="$(yq '.environment.flutter' "$VERSION_FILE")"
fi
ARR_CHANNEL=("${@:$OPTIND:1}") ARR_CHANNEL=("${@:$OPTIND:1}")
CHANNEL="${ARR_CHANNEL[0]}" CHANNEL="${ARR_CHANNEL[0]:-}"
[ -z "$CHANNEL" ] && CHANNEL=stable [ -z "$CHANNEL" ] && CHANNEL=stable
[ -z "$VERSION" ] && VERSION=any [ -z "$VERSION" ] && VERSION=any
[ -z "$ARCH" ] && ARCH=x64 [ -z "$ARCH" ] && ARCH=x64
[ -z "$CACHE_PATH" ] && CACHE_PATH="$RUNNER_TEMP/flutter/:channel:-:version:-:arch:" [ -z "$CACHE_PATH" ] && CACHE_PATH="$RUNNER_TOOL_CACHE/flutter/:channel:-:version:-:arch:"
[ -z "$CACHE_KEY" ] && CACHE_KEY="flutter-:os:-:channel:-:version:-:arch:-:hash:" [ -z "$CACHE_KEY" ] && CACHE_KEY="flutter-:os:-:channel:-:version:-:arch:-:hash:"
[ -z "$PUB_CACHE_KEY" ] && PUB_CACHE_KEY="flutter-pub-:os:-:channel:-:version:-:arch:-:hash:" [ -z "$PUB_CACHE_KEY" ] && PUB_CACHE_KEY="flutter-pub-:os:-:channel:-:version:-:arch:-:hash:"
[ -z "$PUB_CACHE_PATH" ] && PUB_CACHE_PATH="default" [ -z "$PUB_CACHE_PATH" ] && PUB_CACHE_PATH="default"
@ -110,7 +128,7 @@ CHANNEL="${ARR_CHANNEL[0]}"
# If `PUB_CACHE` is set already, then it should continue to be used. Otherwise, satisfy it # If `PUB_CACHE` is set already, then it should continue to be used. Otherwise, satisfy it
# if the action requests a custom path, or set to the Dart default values depending # if the action requests a custom path, or set to the Dart default values depending
# on the operating system. # on the operating system.
if [ -z "$PUB_CACHE" ]; then if [ -z "${PUB_CACHE:-}" ]; then
if [ "$PUB_CACHE_PATH" != "default" ]; then if [ "$PUB_CACHE_PATH" != "default" ]; then
PUB_CACHE="$PUB_CACHE_PATH" PUB_CACHE="$PUB_CACHE_PATH"
elif [ "$OS_NAME" = "windows" ]; then elif [ "$OS_NAME" = "windows" ]; then
@ -170,6 +188,7 @@ if [ "$PRINT_ONLY" = true ]; then
if [ "$TEST_MODE" = true ]; then if [ "$TEST_MODE" = true ]; then
echo "CHANNEL=$info_channel" echo "CHANNEL=$info_channel"
echo "VERSION=$info_version" echo "VERSION=$info_version"
# VERSION_FILE is not printed, because it is essentially same as VERSION
echo "ARCHITECTURE=$info_architecture" echo "ARCHITECTURE=$info_architecture"
echo "CACHE-KEY=$CACHE_KEY" echo "CACHE-KEY=$CACHE_KEY"
echo "CACHE-PATH=$CACHE_PATH" echo "CACHE-PATH=$CACHE_PATH"
@ -181,12 +200,13 @@ if [ "$PRINT_ONLY" = true ]; then
{ {
echo "CHANNEL=$info_channel" echo "CHANNEL=$info_channel"
echo "VERSION=$info_version" echo "VERSION=$info_version"
# VERSION_FILE is not printed, because it is essentially same as VERSION
echo "ARCHITECTURE=$info_architecture" echo "ARCHITECTURE=$info_architecture"
echo "CACHE-KEY=$CACHE_KEY" echo "CACHE-KEY=$CACHE_KEY"
echo "CACHE-PATH=$CACHE_PATH" echo "CACHE-PATH=$CACHE_PATH"
echo "PUB-CACHE-KEY=$PUB_CACHE_KEY" echo "PUB-CACHE-KEY=$PUB_CACHE_KEY"
echo "PUB-CACHE-PATH=$PUB_CACHE" echo "PUB-CACHE-PATH=$PUB_CACHE"
} >>"$GITHUB_OUTPUT" } >>"${GITHUB_OUTPUT:-/dev/null}"
exit 0 exit 0
fi fi
@ -207,10 +227,10 @@ fi
{ {
echo "FLUTTER_ROOT=$CACHE_PATH" echo "FLUTTER_ROOT=$CACHE_PATH"
echo "PUB_CACHE=$PUB_CACHE" echo "PUB_CACHE=$PUB_CACHE"
} >>"$GITHUB_ENV" } >>"${GITHUB_ENV:-/dev/null}"
{ {
echo "$CACHE_PATH/bin" echo "$CACHE_PATH/bin"
echo "$CACHE_PATH/bin/cache/dart-sdk/bin" echo "$CACHE_PATH/bin/cache/dart-sdk/bin"
echo "$PUB_CACHE/bin" echo "$PUB_CACHE/bin"
} >>"$GITHUB_PATH" } >>"${GITHUB_PATH:-/dev/null}"

5
test/pubspec.yaml Normal file
View file

@ -0,0 +1,5 @@
name: flutter_action_test
environment:
dart: ">=2.18.0 <3.0.0"
flutter: 3.3.10