From 6cdcfa511214d24e9a9d5d75ba31380360e40d86 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Mon, 6 Jan 2025 10:38:56 +0100 Subject: [PATCH] cleanup and check hash --- .github/workflows/download_asset.yaml | 14 ++------------ .../example/build/download_asset/README.md | 3 ++- .../example/build/download_asset/hook/build.dart | 10 ++++++++++ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/download_asset.yaml b/.github/workflows/download_asset.yaml index 7b00cbbe0..f3391ba92 100644 --- a/.github/workflows/download_asset.yaml +++ b/.github/workflows/download_asset.yaml @@ -45,6 +45,7 @@ jobs: - run: dart pub get + # Keep this list consistent with pkgs/native_assets_cli/example/build/download_asset/lib/src/hook_helpers/target_versions.dart - name: Build Linux host if: matrix.os == 'ubuntu' run: | @@ -86,7 +87,7 @@ jobs: pkgs/native_assets_cli/example/build/download_asset/.dart_tool/download_asset/**/*.so if-no-files-found: error - check: + release: needs: build runs-on: ubuntu-latest @@ -108,17 +109,6 @@ jobs: - name: Display structure of downloaded assets run: ls -R .dart_tool/download_asset/ - # - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 - # with: - # sdk: stable - - # - run: dart pub get - - # - name: Check hashes of released artifacts - # run: | - # dart tool/generate_asset_hashes.dart - # git diff --exit-code - - name: Release uses: softprops/action-gh-release@e7a8f85e1c67a31e6ed99a94b41bd0b71bbee6b8 if: startsWith(github.ref, 'refs/tags/download_asset-prebuild-assets') diff --git a/pkgs/native_assets_cli/example/build/download_asset/README.md b/pkgs/native_assets_cli/example/build/download_asset/README.md index b69e66dcc..0652769d9 100644 --- a/pkgs/native_assets_cli/example/build/download_asset/README.md +++ b/pkgs/native_assets_cli/example/build/download_asset/README.md @@ -9,6 +9,7 @@ Run tests with `dart --enable-experiment=native-assets test`. A typical layout of a package which downloads assets: +* `tool/build.dart` prebuilts assets and is exercised from a GitHub workflow. +* A [github workflow](../../../../../.github/workflows/native.yaml) that builds assets. * `hook/build.dart` downloads the prebuilt assets. * `lib/` contains Dart code which uses the assets. -* `tool/build.dart` prebuilts assets and is exercised from the GitHub CI. diff --git a/pkgs/native_assets_cli/example/build/download_asset/hook/build.dart b/pkgs/native_assets_cli/example/build/download_asset/hook/build.dart index cc75eb2ef..5b8087dbd 100644 --- a/pkgs/native_assets_cli/example/build/download_asset/hook/build.dart +++ b/pkgs/native_assets_cli/example/build/download_asset/hook/build.dart @@ -6,6 +6,7 @@ import 'dart:io'; import 'package:download_asset/src/hook_helpers/c_build.dart'; import 'package:download_asset/src/hook_helpers/download.dart'; +import 'package:download_asset/src/hook_helpers/hashes.dart'; import 'package:native_assets_cli/code_assets_builder.dart'; import 'package:native_assets_cli/native_assets_cli.dart'; @@ -30,6 +31,15 @@ void main(List args) async { iOSSdk, outputDirectory, ); + final fileHash = await hashAsset(file); + final expectedHash = assetHashes[createTargetName( + targetOS.name, + targetArchitecture.name, + iOSSdk?.type, + )]; + if (fileHash != expectedHash) { + throw Exception('File $file was not downloaded correctly.'); + } output.codeAssets.add(CodeAsset( package: config.packageName, name: 'native_add.dart',