Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flutter-version-file #290

Merged
merged 14 commits into from
Apr 1, 2024
Merged
33 changes: 28 additions & 5 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,35 @@ jobs:
- run: flutter --version
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:
runs-on: macos-latest

steps:
- name: Clone repository
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'
shell: bash
- run: ./setup.sh -t -p | grep '3.7.7'
Expand Down Expand Up @@ -146,15 +169,15 @@ jobs:
shell: bash
- run: ./setup.sh -t -p -n 0 any | grep 'flutter-macos-beta-0.11.13-x64-58c8489fcdb4e4ef6c010117584c9b23d15221aa'
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
- 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
- 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
- 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
- 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
- run: ./setup.sh -t -p -k 'custom-:channel:-:version:-:hash:' | grep 'custom-stable-3.7.7-2ad6cd72c040113b47ee9055e722606a490ef0da'
shell: bash
Expand Down
85 changes: 67 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ macOS.

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
steps:
Expand All @@ -16,12 +16,52 @@ steps:
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: 3.19.0
- run: flutter --version
```

### 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
```

Use latest release for particular channel:
> [!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
steps:
Expand All @@ -34,7 +74,7 @@ steps:
- run: flutter --version
```

Use latest release for particular version and/or channel:
### Use latest release for particular version and/or channel

```yaml
steps:
Expand All @@ -43,12 +83,12 @@ steps:
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: 1.22.x
channel: dev
flutter-version: 1.22.x
- run: flutter --version
```

Use particular version on any channel:
### Use particular version on any channel

```yaml
steps:
Expand All @@ -57,12 +97,12 @@ steps:
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: 3.x
channel: any
flutter-version: 3.x
- run: flutter --version
```

Use particular git reference on master channel:
### Use particular git reference on master channel

```yaml
steps:
Expand All @@ -71,8 +111,8 @@ steps:
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: 5b12b74 # tag, commit or branch
channel: master
flutter-version: 5b12b74 # tag, commit or branch
- run: flutter --version
```

Expand All @@ -94,7 +134,11 @@ steps:
- run: flutter build appbundle
```

Build for **iOS** (macOS runners only):
### Build for iOS

> [!NOTE]
>
> Building for iOS requires a macOS runner.

```yaml
jobs:
Expand All @@ -112,7 +156,7 @@ jobs:
- run: flutter build ios --release --no-codesign
```

Build for the **web**:
### Build for the web

```yaml
steps:
Expand All @@ -121,13 +165,13 @@ steps:
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: "stable"
channel: stable
- run: flutter pub get
- run: flutter test
- run: flutter build web
```

Build for **Windows**:
### Build for Windows

```yaml
jobs:
Expand All @@ -143,7 +187,7 @@ jobs:
- run: flutter build windows
```

Build for **Linux** desktop:
### Build for Linux desktop

```yaml
jobs:
Expand All @@ -162,7 +206,11 @@ jobs:
- run: flutter build linux
```

Build for **macOS** desktop:
### Build for macOS desktop

> [!NOTE]
>
> Building for macOS requires a macOS runner.

```yaml
jobs:
Expand All @@ -174,7 +222,7 @@ jobs:
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: "stable"
channel: stable
- run: flutter build macos
```

Expand Down Expand Up @@ -220,13 +268,14 @@ steps:
id: flutter-action
with:
channel: stable
- run: |
- name: Print outputs
shell: bash
run: |
echo CACHE-PATH=${{ steps.flutter-action.outputs.CACHE-PATH }}
echo CACHE-KEY=${{ steps.flutter-action.outputs.CACHE-KEY }}
echo CHANNEL=${{ steps.flutter-action.outputs.CHANNEL }}
echo VERSION=${{ steps.flutter-action.outputs.VERSION }}
echo ARCHITECTURE=${{ steps.flutter-action.outputs.ARCHITECTURE }}
echo PUB-CACHE-PATH=${{ steps.flutter-action.outputs.PUB-CACHE-PATH }}
echo PUB-CACHE-KEY=${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}
shell: bash
```
55 changes: 30 additions & 25 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,44 @@ branding:
color: blue

inputs:
flutter-version:
description: The Flutter version to make available on the path
required: false
default: any
channel:
description: The Flutter build release channel
required: false
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:
description: Cache the Flutter SDK
required: false
default: "false"
cache-key:
description: Identifier for the Flutter SDK cache
required: false
default: "flutter-:os:-:channel:-:version:-:arch:-:hash:"
pub-cache-key:
description: Identifier for the Dart .pub-cache cache
required: false
default: "flutter-pub:os:-:channel:-:version:-:arch:-:hash:"
default: ""
cache-path:
description: Flutter SDK cache path
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:
description: Flutter pub cache path
required: false
default: default
architecture:
description: The architecture of Flutter SDK executable (x64 or arm64)
required: false
default: "${{ runner.arch }}"

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:
value: "${{ steps.flutter-action.outputs.CHANNEL }}"
description: The selected Flutter release channel
Expand All @@ -55,6 +53,12 @@ outputs:
ARCHITECTURE:
value: "${{ steps.flutter-action.outputs.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:
value: "${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}"
description: Key used to cache the pub dependencies
Expand All @@ -74,12 +78,13 @@ runs:
shell: bash
run: |
$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 }}' \
-f '${{ inputs.flutter-version-file }}' \
-a '${{ inputs.architecture }}' \
-k '${{ inputs.cache-key }}' \
-c '${{ inputs.cache-path }}' \
-l '${{ inputs.pub-cache-key }}' \
-d '${{ inputs.pub-cache-path }}' \
${{ inputs.channel }}

- name: Cache Flutter
Expand All @@ -105,7 +110,7 @@ runs:
shell: bash
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 }}' \
-c '${{ steps.flutter-action.outputs.CACHE-PATH }}' \
${{ steps.flutter-action.outputs.CHANNEL }}
Loading