Skip to content

Commit c301639

Browse files
committed
Use wasm modules from artifact
1 parent f3edd04 commit c301639

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

.github/actions/prepare/action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ description: Prepare CI environment
44
runs:
55
using: composite
66
steps:
7-
- uses: actions/checkout@v4
87
- name: Install Flutter
98
uses: subosito/flutter-action@v2
109
with:
@@ -20,4 +19,6 @@ runs:
2019
run: flutter pub global activate melos
2120
- name: Install dependencies
2221
shell: sh
22+
env:
23+
IS_IN_POWERSYNC_CI: 1
2324
run: melos prepare

.github/workflows/check.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ on:
1111
jobs:
1212
setup:
1313
uses: ./.github/workflows/prepare_wasm.yml
14-
14+
1515
build:
1616
runs-on: ubuntu-latest
1717
needs: [setup]
1818
steps:
19+
- uses: actions/checkout@v4
1920
- uses: ./.github/actions/prepare
2021
- name: Check formatting
2122
run: melos format:check:packages
@@ -28,6 +29,7 @@ jobs:
2829
runs-on: ubuntu-latest
2930
needs: [setup]
3031
steps:
32+
- uses: actions/checkout@v4
3133
- uses: ./.github/actions/prepare
3234
- name: Check pana score
3335
run: |
@@ -38,6 +40,7 @@ jobs:
3840
runs-on: ubuntu-latest
3941
needs: [setup]
4042
steps:
43+
- uses: actions/checkout@v4
4144
- uses: ./.github/actions/prepare
4245
- name: Run flutter tests
4346
run: melos test
@@ -48,6 +51,7 @@ jobs:
4851
runs-on: ubuntu-latest
4952
needs: [setup]
5053
steps:
54+
- uses: actions/checkout@v4
5155
- uses: ./.github/actions/prepare
5256
- name: Check formatting
5357
run: melos format:check:demos

.github/workflows/prepare_wasm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
id: cache_build
1515
with:
1616
path: packages/sqlite3_wasm_build/dist/
17-
key: ${{ runner.os }}-${{ hashFiles('packages/sqlite3_wasm_build/build.sh') }}
17+
key: wasm-${{ runner.os }}-${{ hashFiles('packages/sqlite3_wasm_build/build.sh') }}
1818

1919
- name: Setup Homebrew
2020
if: steps.cache_build.outputs.cache-hit != 'true'

packages/powersync_core/lib/src/setup_web.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:collection/collection.dart';
44
import 'package:pub_semver/pub_semver.dart';
55
import 'package:pubspec_parse/pubspec_parse.dart';
66
import 'package:args/args.dart';
7+
import 'package:path/path.dart' as p;
78

89
Future<void> downloadWebAssets(List<String> arguments,
910
{bool encryption = false}) async {
@@ -46,6 +47,11 @@ Future<void> downloadWebAssets(List<String> arguments,
4647
exit(1);
4748
}
4849

50+
if (Platform.environment.containsKey('IS_IN_POWERSYNC_CI')) {
51+
print('IS_IN_POWERSYNC_CI env variable is set, copying from local build');
52+
return _copyPrecompiled(Directory.current, wasmFileName);
53+
}
54+
4955
try {
5056
final httpClient = HttpClient();
5157

@@ -177,3 +183,25 @@ Future<void> downloadFile(
177183
'Failed to download file: ${response.statusCode} ${response.reasonPhrase}');
178184
}
179185
}
186+
187+
Future<void> _copyPrecompiled(Directory project, String wasmFile) async {
188+
// Keep going up until we see the melos.yaml file indicating the workspace
189+
// root.
190+
var dir = project;
191+
while (!await File(p.join(dir.path, 'melos.yaml')).exists()) {
192+
print('Looking for melos workspace in $dir');
193+
final parent = dir.parent;
194+
if (p.equals(parent.path, dir.path)) {
195+
throw 'Melos workspace not found';
196+
}
197+
198+
dir = parent;
199+
}
200+
201+
// In the CI, an earlier step will have put these files into the prepared
202+
// sqlite3_wasm_build package.
203+
final destination = p.join(project.path, 'web');
204+
final wasmSource = p.join(dir.path, 'packages', 'sqlite3_wasm_build', 'dist');
205+
print('Copying $wasmFile from $wasmSource to $destination');
206+
await File(p.join(wasmSource, wasmFile)).copy(p.join(destination, wasmFile));
207+
}

packages/powersync_core/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies:
2828
args: ^2.6.0
2929
pub_semver: ^2.0.0
3030
pubspec_parse: ^1.3.0
31+
path: ^1.8.0
3132

3233
dev_dependencies:
3334
lints: ^5.1.1
@@ -37,7 +38,6 @@ dev_dependencies:
3738
shelf_router: ^1.1.4
3839
shelf_static: ^1.1.2
3940
stream_channel: ^2.1.2
40-
path: ^1.8.3
4141

4242
platforms:
4343
android:

0 commit comments

Comments
 (0)