Skip to content

Commit

Permalink
Merge pull request #2 from monterail/precache
Browse files Browse the repository at this point in the history
feat: precache
  • Loading branch information
wrbl606 authored Jul 12, 2024
2 parents 9ec210c + 345209a commit 7680908
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 9 deletions.
27 changes: 25 additions & 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 All @@ -18,3 +17,27 @@ jobs:
- uses: ./
- run: flutter --version
- run: dart pub global activate git_helper && git_helper -h
test-beta-install:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: ./
with:
channel: 'beta'
- run: flutter --version
- run: dart pub global activate git_helper && git_helper -h
test-precache:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: ./
with:
precache: '--web'
- run: flutter --version
- run: dart pub global activate git_helper && git_helper -h
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
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 'Install Flutter SDK'
description: 'Dart and Flutter CLIs available for your GitHub Action'
author: 'Marcin Wróblewski'
author: 'Marcin Wróblewski, Monterail Sp. z o.o. (monterail.com)'
branding:
color: 'white'
icon: 'download'
Expand All @@ -9,10 +9,14 @@ inputs:
description: 'Desired Flutter channel'
required: false
default: 'stable'
precache:
description: 'Comma-separated platforms list to precache'
required: false
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 }}
- run: $GITHUB_ACTION_PATH/install-flutter-sdk.sh -c ${{ inputs.channel }} -p "${{ inputs.precache }}"
shell: bash
8 changes: 7 additions & 1 deletion install-flutter-sdk.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/bash

CHANNEL="stable"
while getopts 'v:c:' param; do
PRECACHE="no"
while getopts 'c:p:' param; do
case $param in
c) CHANNEL="$OPTARG" ;;
p) PRECACHE="$OPTARG" ;;
esac
done

Expand All @@ -16,3 +18,7 @@ git clone -b "$CHANNEL" https://github.com/flutter/flutter.git "$FLUTTER_PATH"
echo "$HOME/.pub-cache/bin" # POSIX
echo "$LOCALAPPDATA\Pub\Cache\bin" # Windows
} >> "$GITHUB_PATH"

if [[ $PRECACHE != "no" ]]; then
$FLUTTER_PATH/bin/flutter precache $PRECACHE
fi

0 comments on commit 7680908

Please sign in to comment.