Skip to content

Commit

Permalink
feat: precache
Browse files Browse the repository at this point in the history
  • Loading branch information
wrbl606 committed Jul 12, 2024
1 parent 3305985 commit ebdce31
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/run.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
on:
push:
branches:
- main
- development
pull_request:
branches:
- main
- development

jobs:
test-install:
Expand Down
41 changes: 37 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Copy and paste the following snippet into your action's `.yml` file.

```yaml
- name: Install Flutter
uses: monterail/flutter-action@v1
uses: monterail/flutter-action@v2
```
## Usage
Expand All @@ -21,7 +21,7 @@ With Flutter SDK for GitHub Actions you can do the following:
```yaml
steps:
- uses: monterail/flutter-action@v1
- uses: monterail/flutter-action@v2
- run: flutter build ...
```
Expand All @@ -32,6 +32,7 @@ steps:
| Name | Description | Default |
| --- | --- | --- |
| `channel` | Flutter [channel](https://github.com/flutter/flutter/wiki/Flutter-build-release-channels) | `stable` |
| `precache` | `flutter precache` arguments list, see [recipe](#precache-web-and-android-build-tools) | no-op |

## Recipes

Expand All @@ -56,7 +57,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: monterail/flutter-action@v1
- uses: monterail/flutter-action@v2
- run: flutter pub get
- uses: invertase/github-action-dart-analyzer@v3
with:
Expand Down Expand Up @@ -86,7 +87,39 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: monterail/flutter-action@v1
- uses: monterail/flutter-action@v2
- run: flutter pub get
- run: flutter build web
- uses: actions/upload-artifact@v4
with:
name: web-app
path: build/web
```

</details>

### Precache web and Android build tools

By default Flutter will fetch the tools necessary to build specific platforms after `flutter build` command is ran. The process can be sped up with precaching specific platforms at Flutter installation stage.

<details>

```yaml
name: Setup Flutter for web and Android builds
on:
push:
branches:
- main
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: monterail/flutter-action@v2
with:
precache: "--web --android"
- run: flutter pub get
- run: flutter build web
- uses: actions/upload-artifact@v4
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ inputs:
precache:
description: 'Comma-separated platforms list to precache'
required: false
default: ''
default: 'no'
runs:
using: 'composite'
steps:
- run: chmod +x $GITHUB_ACTION_PATH/install-flutter-sdk.sh
shell: bash
- run: $GITHUB_ACTION_PATH/install-flutter-sdk.sh -c ${{ inputs.channel }} -p ${{ inputs.precache }}
- run: $GITHUB_ACTION_PATH/install-flutter-sdk.sh -c ${{ inputs.channel }} -p "${{ inputs.precache }}"
shell: bash
5 changes: 3 additions & 2 deletions install-flutter-sdk.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

CHANNEL="stable"
PRECACHE="no"
while getopts 'c:p:' param; do
case $param in
c) CHANNEL="$OPTARG" ;;
Expand All @@ -18,6 +19,6 @@ git clone -b "$CHANNEL" https://github.com/flutter/flutter.git "$FLUTTER_PATH"
echo "$LOCALAPPDATA\Pub\Cache\bin" # Windows
} >> "$GITHUB_PATH"

if [ -z ${PRECACHE+x} ]; then
flutter precache $PRECACHE
if [[ $PRECACHE != "no" ]]; then
$FLUTTER_PATH/bin/flutter precache $PRECACHE
fi

0 comments on commit ebdce31

Please sign in to comment.