Skip to content

Commit 0ef13f1

Browse files
authored
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
1 parent 7564de3 commit 0ef13f1

File tree

5 files changed

+158
-56
lines changed

5 files changed

+158
-56
lines changed

.github/workflows/workflow.yaml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,35 @@ jobs:
7676
- run: flutter --version
7777
shell: bash
7878

79+
test_version_file:
80+
runs-on: ${{ matrix.operating-system }}
81+
82+
strategy:
83+
matrix:
84+
operating-system: [ubuntu-latest]
85+
86+
steps:
87+
- name: Clone repository
88+
uses: actions/checkout@v4
89+
- uses: ./
90+
with:
91+
channel: stable
92+
flutter-version-file: test/pubspec.yaml
93+
- name: Verify Dart version
94+
run: dart --version | grep '2.18.6'
95+
shell: bash
96+
- name: Verify Flutter version
97+
run: flutter --version | grep '3.3.10'
98+
shell: bash
99+
79100
test_print_output:
80101
runs-on: macos-latest
81102

82103
steps:
83104
- name: Clone repository
84105
uses: actions/checkout@v4
106+
- run: ./setup.sh -t -p -f test/pubspec.yaml | grep '3.3.10'
107+
shell: bash
85108
- run: ./setup.sh -t -p | grep 'stable'
86109
shell: bash
87110
- run: ./setup.sh -t -p | grep '3.7.7'
@@ -146,15 +169,15 @@ jobs:
146169
shell: bash
147170
- run: ./setup.sh -t -p -n 0 any | grep 'flutter-macos-beta-0.11.13-x64-58c8489fcdb4e4ef6c010117584c9b23d15221aa'
148171
shell: bash
149-
- run: ./setup.sh -t -p | grep '/Users/runner/work/_temp/flutter/stable-3.7.7-x64'
172+
- run: ./setup.sh -t -p | grep '/Users/runner/hostedtoolcache/flutter/stable-3.7.7-x64'
150173
shell: bash
151-
- run: ./setup.sh -t -p stable | grep '/Users/runner/work/_temp/flutter/stable-3.7.7-x64'
174+
- run: ./setup.sh -t -p stable | grep '/Users/runner/hostedtoolcache/flutter/stable-3.7.7-x64'
152175
shell: bash
153-
- run: ./setup.sh -t -p beta | grep '/Users/runner/work/_temp/flutter/beta-3.9.0-0.1.pre-x64'
176+
- run: ./setup.sh -t -p beta | grep '/Users/runner/hostedtoolcache/flutter/beta-3.9.0-0.1.pre-x64'
154177
shell: bash
155-
- run: ./setup.sh -t -p dev | grep '/Users/runner/work/_temp/flutter/dev-2.11.0-0.1.pre-x64'
178+
- run: ./setup.sh -t -p dev | grep '/Users/runner/hostedtoolcache/flutter/dev-2.11.0-0.1.pre-x64'
156179
shell: bash
157-
- run: ./setup.sh -t -p master | grep '/Users/runner/work/_temp/flutter/master-any-x64'
180+
- run: ./setup.sh -t -p master | grep '/Users/runner/hostedtoolcache/flutter/master-any-x64'
158181
shell: bash
159182
- run: ./setup.sh -t -p -k 'custom-:channel:-:version:-:hash:' | grep 'custom-stable-3.7.7-2ad6cd72c040113b47ee9055e722606a490ef0da'
160183
shell: bash

README.md

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ macOS.
55

66
The following sections show how to configure this action.
77

8-
## Flutter version
8+
## Specifying Flutter version
99

10-
Use specific version and channel:
10+
### Use specific version and channel
1111

1212
```yaml
1313
steps:
@@ -16,12 +16,52 @@ steps:
1616
- name: Set up Flutter
1717
uses: subosito/flutter-action@v2
1818
with:
19+
channel: stable
1920
flutter-version: 3.19.0
21+
- run: flutter --version
22+
```
23+
24+
### Use version from pubspec.yaml
25+
26+
This is inspired by [`actions/setup-go`](https://github.com/actions/setup-go).
27+
28+
```yaml
29+
steps:
30+
- name: Clone repository
31+
uses: actions/checkout@v4
32+
- name: Set up Flutter
33+
uses: subosito/flutter-action@v2
34+
with:
2035
channel: stable
36+
flutter-version-file: pubspec.yaml # path to pubspec.yaml
2137
- run: flutter --version
2238
```
2339

24-
Use latest release for particular channel:
40+
> [!IMPORTANT]
41+
>
42+
> For `flutter-version-file` to work, you need to have the exact Flutter version
43+
> defined in your pubspec.yaml:
44+
>
45+
> **Good**
46+
>
47+
> ```yaml
48+
> environment:
49+
> sdk: ">=3.3.0 <4.0.0"
50+
> flutter: 3.19.0
51+
> ```
52+
>
53+
> **Bad**
54+
>
55+
> ```yaml
56+
> environment:
57+
> sdk: ">=3.3.0 <4.0.0"
58+
> flutter: ">= 3.19.0 <4.0.0"
59+
> ```
60+
61+
> [!WARNING]
62+
>
63+
> Using `flutter-version-file` requires [`yq`][https://github.com/mikefarah/yq],
64+
> which is not pre-installed in `windows` images. Install it yourself.
2565

2666
```yaml
2767
steps:
@@ -34,7 +74,7 @@ steps:
3474
- run: flutter --version
3575
```
3676

37-
Use latest release for particular version and/or channel:
77+
### Use latest release for particular version and/or channel
3878

3979
```yaml
4080
steps:
@@ -43,12 +83,12 @@ steps:
4383
- name: Set up Flutter
4484
uses: subosito/flutter-action@v2
4585
with:
46-
flutter-version: 1.22.x
4786
channel: dev
87+
flutter-version: 1.22.x
4888
- run: flutter --version
4989
```
5090

51-
Use particular version on any channel:
91+
### Use particular version on any channel
5292

5393
```yaml
5494
steps:
@@ -57,12 +97,12 @@ steps:
5797
- name: Set up Flutter
5898
uses: subosito/flutter-action@v2
5999
with:
60-
flutter-version: 3.x
61100
channel: any
101+
flutter-version: 3.x
62102
- run: flutter --version
63103
```
64104

65-
Use particular git reference on master channel:
105+
### Use particular git reference on master channel
66106

67107
```yaml
68108
steps:
@@ -71,8 +111,8 @@ steps:
71111
- name: Set up Flutter
72112
uses: subosito/flutter-action@v2
73113
with:
74-
flutter-version: 5b12b74 # tag, commit or branch
75114
channel: master
115+
flutter-version: 5b12b74 # tag, commit or branch
76116
- run: flutter --version
77117
```
78118

@@ -94,7 +134,11 @@ steps:
94134
- run: flutter build appbundle
95135
```
96136

97-
Build for **iOS** (macOS runners only):
137+
### Build for iOS
138+
139+
> [!NOTE]
140+
>
141+
> Building for iOS requires a macOS runner.
98142

99143
```yaml
100144
jobs:
@@ -112,7 +156,7 @@ jobs:
112156
- run: flutter build ios --release --no-codesign
113157
```
114158

115-
Build for the **web**:
159+
### Build for the web
116160

117161
```yaml
118162
steps:
@@ -121,13 +165,13 @@ steps:
121165
- name: Set up Flutter
122166
uses: subosito/flutter-action@v2
123167
with:
124-
channel: "stable"
168+
channel: stable
125169
- run: flutter pub get
126170
- run: flutter test
127171
- run: flutter build web
128172
```
129173

130-
Build for **Windows**:
174+
### Build for Windows
131175

132176
```yaml
133177
jobs:
@@ -143,7 +187,7 @@ jobs:
143187
- run: flutter build windows
144188
```
145189

146-
Build for **Linux** desktop:
190+
### Build for Linux desktop
147191

148192
```yaml
149193
jobs:
@@ -162,7 +206,11 @@ jobs:
162206
- run: flutter build linux
163207
```
164208

165-
Build for **macOS** desktop:
209+
### Build for macOS desktop
210+
211+
> [!NOTE]
212+
>
213+
> Building for macOS requires a macOS runner.
166214

167215
```yaml
168216
jobs:
@@ -174,7 +222,7 @@ jobs:
174222
- name: Set up Flutter
175223
uses: subosito/flutter-action@v2
176224
with:
177-
channel: "stable"
225+
channel: stable
178226
- run: flutter build macos
179227
```
180228

@@ -220,13 +268,14 @@ steps:
220268
id: flutter-action
221269
with:
222270
channel: stable
223-
- run: |
271+
- name: Print outputs
272+
shell: bash
273+
run: |
224274
echo CACHE-PATH=${{ steps.flutter-action.outputs.CACHE-PATH }}
225275
echo CACHE-KEY=${{ steps.flutter-action.outputs.CACHE-KEY }}
226276
echo CHANNEL=${{ steps.flutter-action.outputs.CHANNEL }}
227277
echo VERSION=${{ steps.flutter-action.outputs.VERSION }}
228278
echo ARCHITECTURE=${{ steps.flutter-action.outputs.ARCHITECTURE }}
229279
echo PUB-CACHE-PATH=${{ steps.flutter-action.outputs.PUB-CACHE-PATH }}
230280
echo PUB-CACHE-KEY=${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}
231-
shell: bash
232281
```

action.yaml

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,44 @@ branding:
66
color: blue
77

88
inputs:
9-
flutter-version:
10-
description: The Flutter version to make available on the path
11-
required: false
12-
default: any
139
channel:
1410
description: The Flutter build release channel
1511
required: false
1612
default: stable
13+
flutter-version:
14+
description: The Flutter version to make available on the path
15+
required: false
16+
default: ""
17+
flutter-version-file:
18+
description: The pubspec.yaml file with exact Flutter version defined
19+
required: false
20+
default: ""
21+
architecture:
22+
description: The architecture of Flutter SDK executable (x64 or arm64)
23+
required: false
24+
default: "${{ runner.arch }}"
1725
cache:
1826
description: Cache the Flutter SDK
1927
required: false
2028
default: "false"
2129
cache-key:
2230
description: Identifier for the Flutter SDK cache
2331
required: false
24-
default: "flutter-:os:-:channel:-:version:-:arch:-:hash:"
25-
pub-cache-key:
26-
description: Identifier for the Dart .pub-cache cache
27-
required: false
28-
default: "flutter-pub:os:-:channel:-:version:-:arch:-:hash:"
32+
default: ""
2933
cache-path:
3034
description: Flutter SDK cache path
3135
required: false
32-
default: "${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:"
36+
default: ""
37+
pub-cache-key:
38+
description: Identifier for the Dart .pub-cache cache
39+
required: false
40+
default: ""
3341
pub-cache-path:
3442
description: Flutter pub cache path
3543
required: false
3644
default: default
37-
architecture:
38-
description: The architecture of Flutter SDK executable (x64 or arm64)
39-
required: false
40-
default: "${{ runner.arch }}"
4145

4246
outputs:
43-
CACHE-KEY:
44-
value: "${{ steps.flutter-action.outputs.CACHE-KEY }}"
45-
description: Key used to cache the Flutter SDK
46-
CACHE-PATH:
47-
value: "${{ steps.flutter-action.outputs.CACHE-PATH }}"
48-
description: Path to Flutter SDK
4947
CHANNEL:
5048
value: "${{ steps.flutter-action.outputs.CHANNEL }}"
5149
description: The selected Flutter release channel
@@ -55,6 +53,12 @@ outputs:
5553
ARCHITECTURE:
5654
value: "${{ steps.flutter-action.outputs.ARCHITECTURE }}"
5755
description: The selected Flutter CPU architecture
56+
CACHE-KEY:
57+
value: "${{ steps.flutter-action.outputs.CACHE-KEY }}"
58+
description: Key used to cache the Flutter SDK
59+
CACHE-PATH:
60+
value: "${{ steps.flutter-action.outputs.CACHE-PATH }}"
61+
description: Path to Flutter SDK
5862
PUB-CACHE-KEY:
5963
value: "${{ steps.flutter-action.outputs.PUB-CACHE-KEY }}"
6064
description: Key used to cache the pub dependencies
@@ -74,12 +78,13 @@ runs:
7478
shell: bash
7579
run: |
7680
$GITHUB_ACTION_PATH/setup.sh -p \
77-
-c '${{ inputs.cache-path }}' \
78-
-k '${{ inputs.cache-key }}' \
79-
-d '${{ inputs.pub-cache-path }}' \
80-
-l '${{ inputs.pub-cache-key }}' \
8181
-n '${{ inputs.flutter-version }}' \
82+
-f '${{ inputs.flutter-version-file }}' \
8283
-a '${{ inputs.architecture }}' \
84+
-k '${{ inputs.cache-key }}' \
85+
-c '${{ inputs.cache-path }}' \
86+
-l '${{ inputs.pub-cache-key }}' \
87+
-d '${{ inputs.pub-cache-path }}' \
8388
${{ inputs.channel }}
8489
8590
- name: Cache Flutter
@@ -105,7 +110,7 @@ runs:
105110
shell: bash
106111
run: |
107112
$GITHUB_ACTION_PATH/setup.sh \
108-
-c '${{ steps.flutter-action.outputs.CACHE-PATH }}' \
109113
-n '${{ steps.flutter-action.outputs.VERSION }}' \
110114
-a '${{ steps.flutter-action.outputs.ARCHITECTURE }}' \
115+
-c '${{ steps.flutter-action.outputs.CACHE-PATH }}' \
111116
${{ steps.flutter-action.outputs.CHANNEL }}

0 commit comments

Comments
 (0)