Skip to content

Commit

Permalink
Github composite action for setting up flutter on runner (#1710)
Browse files Browse the repository at this point in the history
* Use workflow_dispatch

* source ~/.profile to update paths after install of puro

* Update $GITHUB_PATH

* Checkout first

* Add cache + simplify puro install

* use --global, no melos setup, and some cleanup

* .puro != ~/.puro

* export $PUB_CACHE and $PURO_ROOT

* Don't source ~/.profile. Set env variables explicitly

* Tweak cache key

* Support windows

* Convert setup-runner from workflow to action

* Blunt hack to get windows working

* Skip stuff on partial (or exact) cache-hit

* Switch from run_id to hashFiles

* Use runPubGetOffline

* Populate pub-cache explicitly on cache miss, as melos bootstrap no longer does

* Update cSpell.words

* Use for: compile for web

* Remove inverted save cache condition (Debug code)

* Update CHANGELOG

* Ensure caches are cycled atleast once a week
  • Loading branch information
nielsenko authored Jun 7, 2024
1 parent 889e434 commit 9eabca2
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 164 deletions.
94 changes: 94 additions & 0 deletions .github/actions/setup-runner/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Setup runner
description: Setup the runner with the necessary tools and dependencies.

inputs:
flutter-version:
description: Flutter version to use.
default: stable
cache-key:
description: Cache key to use for restoring and saving the cache.
default: ${{ hashFiles('**/pubspec.yaml') }}

runs:
using: "composite"
steps:
- name: Setup environment
# By forcing puro (and hence the pub-cache) onto the same drive as the checkout,
# we can avoid symlink issue between local and network drives on windows.
id: setup
shell: bash
run: |
export PURO_ROOT=$(dirname $GITHUB_WORKSPACE)/puro
mkdir -p $PURO_ROOT
echo $PURO_ROOT/bin >> $GITHUB_PATH
echo $PURO_ROOT/shared/pub_cache/bin/ >> $GITHUB_PATH
echo $PURO_ROOT/envs/default/flutter/bin/ >> $GITHUB_PATH
echo PURO_ROOT=$PURO_ROOT >> $GITHUB_ENV
echo PUB_CACHE=$PURO_ROOT/shared/pub_cache >> $GITHUB_ENV
echo MELOS_SDK_PATH=$PURO_ROOT/envs/default/flutter/ >> $GITHUB_ENV
echo "week = $(date +'%Y-%U')" >> $GITHUB_OUTPUT
- name: Restore cache
# TODO: Avoid skipping restore on Windows
# (see https://github.com/pingbird/puro/issues/87)
if: runner.os != 'Windows'
id: restore
uses: actions/cache/restore@v4
with:
path: ${{ env.PURO_ROOT }}
key: setup-runner-${{ runner.os }}-${{ runner.arch }}-${{ steps.setup.outputs.week }}-${{ inputs.cache-key }}
restore-keys: setup-runner-${{ runner.os }}-${{ runner.arch }}-

- name: Install puro (posix)
# See https://puro.dev/
# Skip on any cache hit (partial or full)
if: runner.os != 'Windows' && steps.restore.outputs.cache-matched-key == ''
shell: bash
run: curl -sS -o- https://puro.dev/install.sh | PURO_VERSION="1.4.6" bash

- name: Install puro (windows)
# We always install on windows, as we currently don't restore a cache (see TODO above)
if: runner.os == 'Windows' && steps.restore.outputs.cache-matched-key == ''
shell: pwsh
run: >-
Invoke-WebRequest
-Uri "https://puro.dev/builds/1.4.6/windows-x64/puro.exe"
-OutFile "$Env:PURO_ROOT";
&"$Env:PURO_ROOT\puro.exe" install-puro --promote
- name: Upgrade puro and flutter
shell: bash
run: |
puro upgrade-puro
puro use --global ${{ inputs.flutter-version }}
puro upgrade ${{ inputs.flutter-version }}
puro gc
- name: Activate melos
if: steps.restore.outputs.cache-matched-key == ''
shell: bash
run: puro pub global run melos --version || puro pub global activate melos

- name: Pub get
# We need to run `flutter pub get` first, to ensure the pub-cache is populated,
# if we don't have an exact cache hit.
if: steps.restore.outputs.cache-hit != 'true'
shell: bash
run: puro pub global run melos exec -- flutter pub get

- name: Melos bootstrap
shell: bash
run: puro pub global run melos bootstrap

- name: Save cache
# Saving on feature branches will only benefit reruns, so we don't bother.
# Feature branches inherit the cache from the main branch anyway.
# This saves on cache storage.
if: github.ref == 'refs/heads/main' && steps.restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ env.PURO_ROOT }}
key: ${{ steps.restore.outputs.cache-primary-key }}
54 changes: 10 additions & 44 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -321,33 +321,23 @@ jobs:
with:
submodules: "recursive"

- name: Setup runner
uses: ./.github/actions/setup-runner

- name: Bump ulimit
run: |
ulimit -n
ulimit -n 10240
- name: Enable ccache
run: echo "PATH=/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" >> $GITHUB_ENV
run: echo "/usr/lib/ccache:/usr/local/opt/ccache/libexec" >> $GITHUB_PATH

- name: Fetch artifacts
uses: actions/download-artifact@v4
with:
name: librealm-ios
path: packages/realm_dart/binary/ios

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: "stable"

- name: Setup Melos
run: |
dart pub global activate melos
dart pub global run melos bootstrap
- name: Install dependencies
run: dart pub get

- name: Launch Simulator
uses: futureware-tech/simulator-action@v3
with:
Expand Down Expand Up @@ -431,18 +421,8 @@ jobs:
name: librealm-android
path: packages/realm_dart/binary/android

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: "stable"

- name: Setup Melos
run: |
dart pub global activate melos
dart pub global run melos bootstrap
- name: Install dependencies
run: dart pub get
- name: Setup Runner
uses: ./.github/actions/setup-runner

# Hack to free up space on the runner to ensure we have enough diskspace to run the emulator
- name: Remove unnecessary files (dotnet, etc.)
Expand Down Expand Up @@ -526,15 +506,8 @@ jobs:
with:
submodules: "recursive"

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: "stable"

- name: Setup Melos
run: |
dart pub global activate melos
dart pub global run melos bootstrap
- name: Setup Runner
uses: ./.github/actions/setup-runner

- name: Delete generated files in realm_dart
run: |
Expand Down Expand Up @@ -629,15 +602,8 @@ jobs:
with:
submodules: "recursive"

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: "stable"

- name: Setup Melos
run: |
dart pub global activate melos
dart pub global run melos bootstrap
- name: Setup Runner
uses: ./.github/actions/setup-runner

- name: Compile to wasm
run: flutter build web --wasm -t integration_test/all_tests.dart
Expand Down
13 changes: 3 additions & 10 deletions .github/workflows/dart-desktop-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,8 @@ jobs:
name: librealm-${{ steps.runner_os_lowercase.outputs.os }}
path: packages/realm_dart/binary/${{ steps.runner_os_lowercase.outputs.os }}

- name: Setup Dart SDK
uses: dart-lang/setup-dart@main
with:
sdk: stable

- name: Setup Melos
run: |
dart pub global activate melos
melos bootstrap --no-flutter
melos setup
- name: Setup Runner
uses: ./.github/actions/setup-runner

- name: Bump ulimit on macos
run: |
Expand All @@ -85,6 +77,7 @@ jobs:
if: inputs.runner == 'ubuntu-latest'
run: |
sudo apt-get install lcov
melos setup
melos coverage:convert
melos coverage:gather
melos coverage:groom
Expand Down
15 changes: 2 additions & 13 deletions .github/workflows/deploy-baas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,8 @@ jobs:
with:
submodules: false

- name: Setup Dart SDK
uses: dart-lang/setup-dart@main
with:
sdk: stable
architecture: 'x64'

- name: Setup Melos
run: |
dart pub global activate melos
dart pub global run melos bootstrap --no-flutter
- name: Install dependencies
run: dart pub get
- name: Setup Runner
uses: ./.github/actions/setup-runner

- name: Deploy cluster and apps
run: dart run realm_dart deploy-apps --baasaas-api-key ${{ secrets.BAASAAS_API_KEY }} --differentiator ${{ inputs.differentiator }}
15 changes: 2 additions & 13 deletions .github/workflows/flutter-desktop-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,8 @@ jobs:
name: librealm-${{ steps.runner_os_lowercase.outputs.os }}
path: packages/realm_dart/binary/${{ steps.runner_os_lowercase.outputs.os }}

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: 'stable'
architecture: ${{ inputs.arch }}

- name: Setup Melos
run: |
dart pub global activate melos
dart pub global run melos bootstrap
- name: Install dependencies
run: dart pub get
- name: Setup Runner
uses: ./.github/actions/setup-runner

- name: Bump ulimit
run: |
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,8 @@ jobs:
version: ${{ inputs.version }}
version-suffix: ''

- name : Setup Dart SDK
uses: dart-lang/setup-dart@main
with:
sdk: stable
architecture: 'x64'

- name: Setup Melos
run: dart pub global activate melos
- name: Setup Runner
uses: ./.github/actions/setup-runner

- name: Update pubspec.yaml files
run: REALM_VERSION=${{ steps.update-changelog.outputs.new-version }} melos run update:version:realm
Expand Down
22 changes: 4 additions & 18 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,8 @@ jobs:
echo "version=$pkgVersion$pkgSuffix" >> $GITHUB_OUTPUT
shell: bash

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: 'stable'

- name: Setup Melos
run: |
dart pub global activate melos
dart pub global run melos bootstrap
- name: Setup Runner
uses: ./.github/actions/setup-runner

- name: Download all artifacts
uses: dawidd6/action-download-artifact@71072fbb1229e1317f1a8de6b04206afb461bd67 # 3.1.2
Expand Down Expand Up @@ -161,15 +154,8 @@ jobs:
name: release-bundle
path: release

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: 'stable'

- name: Setup Melos
run: |
dart pub global activate melos
dart pub global run melos bootstrap
- name: Setup Runner
uses: ./.github/actions/setup-runner

# realm_flutter has symlinks to native binaries which should not be packaged
- name: Cleanup symlinks
Expand Down
39 changes: 0 additions & 39 deletions .github/workflows/setup-runner.yml

This file was deleted.

15 changes: 2 additions & 13 deletions .github/workflows/terminate-baas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,8 @@ jobs:
with:
submodules: false

- name: Setup Dart SDK
uses: dart-lang/setup-dart@main
with:
sdk: stable
architecture: 'x64'

- name: Setup Melos
run: |
dart pub global activate melos
dart pub global run melos bootstrap --no-flutter
- name: Install dependencies
run: dart pub get
- name: Setup Runner
uses: ./.github/actions/setup-runner

- name: Terminate baas
run: dart run realm_dart delete-apps --baasaas-api-key ${{ secrets.BAASAAS_API_KEY }} --differentiator ${{ inputs.differentiator }}
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"nodoc",
"nullptr",
"posix",
"puro",
"pwsh",
"riscv",
"sublist",
"sublists",
Expand Down
Loading

0 comments on commit 9eabca2

Please sign in to comment.