Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions .github/workflows/publish_companion_pubdev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
run: |
set -euo pipefail
package_status="$(
curl -sS -o "$RUNNER_TEMP/pubdev-package.json" -w '%{http_code}' \
curl -sS --max-time 30 -o "$RUNNER_TEMP/pubdev-package.json" -w '%{http_code}' \
"https://pub.dev/api/packages/$PACKAGE_NAME"
)"
case "$package_status" in
Expand All @@ -85,7 +85,7 @@ jobs:
esac

version_status="$(
curl -sS -o "$RUNNER_TEMP/pubdev-version.json" -w '%{http_code}' \
curl -sS --max-time 30 -o "$RUNNER_TEMP/pubdev-version.json" -w '%{http_code}' \
"https://pub.dev/api/packages/$PACKAGE_NAME/versions/$PACKAGE_VERSION"
)"
case "$version_status" in
Expand Down Expand Up @@ -127,9 +127,24 @@ jobs:
--exclude='pubspec_overrides.yaml' \
"$PACKAGE_PATH/" "$RUNNER_TEMP/pub-package/"

# pub.dev serves the package listing with max-age=120, so pub can
# briefly miss the core release_on_prep_merge.yml just saw there.
- name: Install dependencies
if: steps.publish.outputs.should_publish == 'true'
run: flutter pub get
run: |
set -euo pipefail
attempts=3
for attempt in $(seq 1 "$attempts"); do
if flutter pub get; then
exit 0
fi
if [[ "$attempt" -lt "$attempts" ]]; then
echo "flutter pub get failed ($attempt/$attempts); retrying in 60 seconds in case the pub.dev listing is stale." >&2
sleep 60
fi
done
echo "flutter pub get failed $attempts times." >&2
exit 1
working-directory: ${{ runner.temp }}/pub-package

- name: Publish - dry run
Expand Down
26 changes: 23 additions & 3 deletions .github/workflows/release_on_prep_merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ jobs:
echo "Unsupported release version: $version" >&2
exit 1
fi
# No companion constraint `>=M.m.0 <M.(m+1).0` admits a prerelease
# of M.m.0, and the build hook pairs such a core with the previous
# minor's companions, so a prerelease core cannot ship beside them.
if [[ "${version%%+*}" == *-* ]]; then
echo "Release automation publishes only stable core versions, but pubspec.yaml is the prerelease $version. No tags were pushed; release a stable version from a new release-prep PR." >&2
exit 1
fi

first_heading="$(awk '/^## / {print; exit}' CHANGELOG.md)"
if [[ "$first_heading" != "## $version" ]]; then
Expand Down Expand Up @@ -177,6 +184,7 @@ jobs:
wait_for_pub_version() {
local package_name="$1"
local package_version="$2"
local recovery="$3"
local package_url="https://pub.dev/api/packages/$package_name"
local attempts="$PUBDEV_WAIT_ATTEMPTS"
local interval_seconds="$PUBDEV_WAIT_INTERVAL_SECONDS"
Expand All @@ -192,6 +200,7 @@ jobs:
done

echo "$package_name $package_version did not appear on pub.dev." >&2
echo "$recovery" >&2
exit 1
}

Expand All @@ -218,7 +227,8 @@ jobs:
else
push_tag "$CORE_TAG"
fi
wait_for_pub_version "llamadart" "$CORE_VERSION"
wait_for_pub_version "llamadart" "$CORE_VERSION" \
"If the publish_pubdev.yml run for $CORE_TAG failed, rerun it, wait for llamadart $CORE_VERSION on pub.dev, then rerun this workflow."

companion_paths=(
packages/llamadart_llama_cpp_flutter
Expand All @@ -240,15 +250,25 @@ jobs:
fi

companion_tag="$package_name-v$package_version"
if git ls-remote --exit-code --tags origin "refs/tags/$companion_tag" >/dev/null 2>&1; then
companion_tag_sha="$(
git ls-remote --tags origin "refs/tags/$companion_tag" "refs/tags/$companion_tag^{}" |
awk 'END {print $1}'
)"
if [[ -n "$companion_tag_sha" ]]; then
if [[ "$companion_tag_sha" != "$RELEASE_SHA" ]]; then
echo "$companion_tag already exists at $companion_tag_sha, not $RELEASE_SHA, and $package_name $package_version is missing on pub.dev." >&2
echo "Rerunning that tag's publish_companion_pubdev.yml run would publish the other commit's $package_path, so this commit cannot publish $package_name $package_version: release it from a new release-prep PR that bumps the core version and $package_name's patch version." >&2
exit 1
fi
echo "$companion_tag already exists, but $package_name $package_version is missing on pub.dev." >&2
echo "If its publish_companion_pubdev.yml run failed transiently, rerun that run, wait for $package_name $package_version on pub.dev, then rerun this workflow." >&2
echo "If the cause is in the repository, this commit cannot publish $package_name $package_version: fix it in a new release-prep PR that bumps the core version and $package_name's patch version." >&2
exit 1
fi

push_tag "$companion_tag"
wait_for_pub_version "$package_name" "$package_version"
wait_for_pub_version "$package_name" "$package_version" \
"If the publish_companion_pubdev.yml run for $companion_tag failed, confirm pub.dev automated publishing is enabled for $package_name with tag pattern $package_name-v{{version}}, rerun that run, wait for $package_name $package_version on pub.dev, then rerun this workflow."
done

wait_for_github_release "$CORE_TAG"
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ StableDiffusionRuntimeStatus probeStableDiffusionRuntime({
/// lacks, and the Vulkan loader. On iOS and macOS the advice also names the
/// `llamadart_stable_diffusion_flutter` companion, which links the runtime
/// into the process through Swift Package Manager instead of the hook.
/// [isFlutterTestHost] (default: `FLUTTER_TEST` is set) marks a host
/// [isFlutterTestHost] (default: [isFlutterTestEnvironment]) marks a host
/// `flutter test` run, which never links that companion.
LlamaUnsupportedException stableDiffusionLoadFailure({
required String platform,
required ArgumentError error,
List<String> Function(List<String> names) missingWindowsLibraries =
findMissingWindowsLibraries,
bool Function() isFlutterTestHost = _isFlutterTestHost,
bool Function() isFlutterTestHost = isFlutterTestEnvironment,
}) {
final detail = '${error.message ?? error}';
final isApple = platform.startsWith('ios-') || platform.startsWith('macos-');
Expand Down Expand Up @@ -312,7 +312,10 @@ const List<String> _windowsVisualCppRuntimeLibraries = [
'vcruntime140_1.dll',
];

bool _isFlutterTestHost() => Platform.environment['FLUTTER_TEST'] == 'true';
/// Whether [environment] (default: this process's) is a host `flutter test`
/// run, which sets `FLUTTER_TEST` to `true`.
bool isFlutterTestEnvironment([Map<String, String>? environment]) =>
(environment ?? Platform.environment)['FLUTTER_TEST'] == 'true';

String _abiLabel(Abi abi) => abi.toString().replaceAll('_', '-');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,53 @@ void main() {
);
});

test('detects a flutter test host from FLUTTER_TEST', () {
expect(isFlutterTestEnvironment({'FLUTTER_TEST': 'true'}), isTrue);
expect(isFlutterTestEnvironment({'FLUTTER_TEST': 'false'}), isFalse);
expect(isFlutterTestEnvironment({'FLUTTER_TESTS': 'true'}), isFalse);
expect(isFlutterTestEnvironment(const {}), isFalse);
expect(
isFlutterTestEnvironment(),
Platform.environment['FLUTTER_TEST'] == 'true',
);
});

test('reads FLUTTER_TEST from the process by default', () {
final dir = Directory.systemTemp.createTempSync('sd_flutter_test_host_');
addTearDown(() => dir.deleteSync(recursive: true));
final script = File('${dir.path}/load_failure.dart')
..writeAsStringSync('''
import 'package:llamadart/src/backends/stable_diffusion/stable_diffusion_runtime_io.dart';

void main() {
print(stableDiffusionLoadFailure(
platform: 'ios-arm64',
error: ArgumentError("Failed to lookup symbol 'sd_version'"),
).message);
}
''');
final packages = File('.dart_tool/package_config.json').absolute.path;

String messageWith(String flutterTest) {
final result = Process.runSync(
Platform.resolvedExecutable,
['--packages=$packages', script.path],
environment: {'FLUTTER_TEST': flutterTest},
);
expect(result.exitCode, 0, reason: '${result.stderr}');
return '${result.stdout}';
}

expect(
messageWith('true'),
contains('not linked into the flutter test host on ios-arm64'),
);
expect(
messageWith('false'),
contains('not linked into the process on ios-arm64'),
);
});

group('Windows error 126', () {
final error126 = ArgumentError(
"Couldn't resolve native function 'sd_version' in "
Expand Down
Loading
Loading