Skip to content

Commit

Permalink
Use wasm modules from artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Feb 6, 2025
1 parent 7db3948 commit 7c6062e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .github/actions/prepare/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ description: Prepare CI environment
runs:
using: composite
steps:
- uses: actions/checkout@v4
- name: Install Flutter
uses: subosito/flutter-action@v2
with:
Expand All @@ -20,4 +19,6 @@ runs:
run: flutter pub global activate melos
- name: Install dependencies
shell: sh
env:
IS_IN_POWERSYNC_CI: 1
run: melos prepare
6 changes: 5 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ on:
jobs:
setup:
uses: ./.github/workflows/prepare_wasm.yml

build:
runs-on: ubuntu-latest
needs: [setup]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- name: Check formatting
run: melos format:check:packages
Expand All @@ -28,6 +29,7 @@ jobs:
runs-on: ubuntu-latest
needs: [setup]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- name: Check pana score
run: |
Expand All @@ -38,6 +40,7 @@ jobs:
runs-on: ubuntu-latest
needs: [setup]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- name: Run flutter tests
run: melos test
Expand All @@ -48,6 +51,7 @@ jobs:
runs-on: ubuntu-latest
needs: [setup]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- name: Check formatting
run: melos format:check:demos
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prepare_wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
id: cache_build
with:
path: packages/sqlite3_wasm_build/dist/
key: ${{ runner.os }}-${{ hashFiles('packages/sqlite3_wasm_build/build.sh') }}
key: wasm-${{ runner.os }}-${{ hashFiles('packages/sqlite3_wasm_build/build.sh') }}

- name: Setup Homebrew
if: steps.cache_build.outputs.cache-hit != 'true'
Expand Down
28 changes: 28 additions & 0 deletions packages/powersync_core/lib/src/setup_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:collection/collection.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:args/args.dart';
import 'package:path/path.dart' as p;

Future<void> downloadWebAssets(List<String> arguments,
{bool encryption = false}) async {
Expand Down Expand Up @@ -46,6 +47,11 @@ Future<void> downloadWebAssets(List<String> arguments,
exit(1);
}

if (Platform.environment.containsKey('IS_IN_POWERSYNC_CI')) {
print('IS_IN_POWERSYNC_CI env variable is set, copying from local build');
return _copyPrecompiled(Directory.current, wasmFileName);
}

try {
final httpClient = HttpClient();

Expand Down Expand Up @@ -177,3 +183,25 @@ Future<void> downloadFile(
'Failed to download file: ${response.statusCode} ${response.reasonPhrase}');
}
}

Future<void> _copyPrecompiled(Directory project, String wasmFile) async {
// Keep going up until we see the melos.yaml file indicating the workspace
// root.
var dir = project;
while (!await File(p.join(dir.path, 'melos.yaml')).exists()) {
print('Looking for melos workspace in $dir');
final parent = dir.parent;
if (p.equals(parent.path, dir.path)) {
throw 'Melos workspace not found';
}

dir = parent;
}

// In the CI, an earlier step will have put these files into the prepared
// sqlite3_wasm_build package.
final destination = p.join(project.path, 'web');
final wasmSource = p.join(dir.path, 'packages', 'sqlite3_wasm_build', 'dist');
print('Copying $wasmFile from $wasmSource to $destination');
await File(p.join(wasmSource, wasmFile)).copy(p.join(destination, wasmFile));
}
2 changes: 1 addition & 1 deletion packages/powersync_core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies:
args: ^2.6.0
pub_semver: ^2.0.0
pubspec_parse: ^1.3.0
path: ^1.8.0

dev_dependencies:
lints: ^5.1.1
Expand All @@ -37,7 +38,6 @@ dev_dependencies:
shelf_router: ^1.1.4
shelf_static: ^1.1.2
stream_channel: ^2.1.2
path: ^1.8.3

platforms:
android:
Expand Down

0 comments on commit 7c6062e

Please sign in to comment.