diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ab2d484..3a56159 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,17 +25,15 @@ jobs: - name: Setup Dart uses: dart-lang/setup-dart@v1 - - name: Create archive (macOS, Linux) - if: matrix.os == 'macos-latest' || matrix.os == 'ubuntu-latest' + - name: Create archive run: | - bash ./scripts/build_release.sh - shell: bash - - - name: Create archive (Windows) - if: matrix.os == 'windows-latest' - run: | - ./scripts/build_release.ps1 - shell: pwsh + cd scripts + dart pub get + cd .. + dart run scripts/bin/build_release.dart + env: + GITHUB_MATRIX_OS: ${{ matrix.os }} + RUNNER_ARCH: ${{ runner.arch }} - name: Upload artifact uses: actions/upload-artifact@v4 diff --git a/scripts/bin/build_release.dart b/scripts/bin/build_release.dart new file mode 100644 index 0000000..fb1cf6b --- /dev/null +++ b/scripts/bin/build_release.dart @@ -0,0 +1,32 @@ +// Copyright 2025 The Flutter Authors. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:args/args.dart'; +import 'package:release_scripts/src/build_release_command.dart'; +import 'package:release_scripts/src/utils.dart'; + +Future main(List args) async { + await runScript((context) async { + final parser = ArgParser(); + parser.addFlag( + 'help', + abbr: 'h', + negatable: false, + help: 'Print this usage information.', + ); + final argResults = parser.parse(args); + + if (argResults.flag('help')) { + print('Usage: build_release'); + print(parser.usage); + return; + } else if (argResults.rest.isNotEmpty) { + throw ExitException( + 'Unexpected arguments: ${argResults.rest.join(' ')}\nUsage: build_release', + ); + } + + await BuildReleaseCommand(context).run(); + }); +} diff --git a/scripts/bin/bump_version.dart b/scripts/bin/bump_version.dart new file mode 100644 index 0000000..7c09f8d --- /dev/null +++ b/scripts/bin/bump_version.dart @@ -0,0 +1,30 @@ +// Copyright 2025 The Flutter Authors. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:args/args.dart'; +import 'package:release_scripts/src/bump_version_command.dart'; +import 'package:release_scripts/src/utils.dart'; + +Future main(List args) async { + await runScript((context) async { + final parser = ArgParser(); + parser.addFlag( + 'help', + abbr: 'h', + negatable: false, + help: 'Print this usage information.', + ); + final argResults = parser.parse(args); + + if (argResults.flag('help') || argResults.rest.isEmpty) { + print('Usage: bump_version '); + print(parser.usage); + if (argResults.rest.isEmpty && !argResults.flag('help')) { + throw ExitException('No version provided.'); + } + return; + } + await BumpVersionCommand(context, argResults.rest.first).run(); + }); +} diff --git a/scripts/bin/update_local.dart b/scripts/bin/update_local.dart new file mode 100644 index 0000000..6dd661a --- /dev/null +++ b/scripts/bin/update_local.dart @@ -0,0 +1,32 @@ +// Copyright 2025 The Flutter Authors. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:args/args.dart'; +import 'package:release_scripts/src/update_local_command.dart'; +import 'package:release_scripts/src/utils.dart'; + +Future main(List args) async { + await runScript((context) async { + final parser = ArgParser(); + parser.addFlag( + 'help', + abbr: 'h', + negatable: false, + help: 'Print this usage information.', + ); + final argResults = parser.parse(args); + + if (argResults.flag('help')) { + print('Usage: update_local'); + print(parser.usage); + return; + } else if (argResults.rest.isNotEmpty) { + throw ExitException( + 'Unexpected arguments: ${argResults.rest.join(' ')}\nUsage: update_local', + ); + } + + await UpdateLocalCommand(context).run(); + }); +} diff --git a/scripts/build_release.ps1 b/scripts/build_release.ps1 deleted file mode 100644 index bc83b48..0000000 --- a/scripts/build_release.ps1 +++ /dev/null @@ -1,7 +0,0 @@ -if (-not $env:GITHUB_REF) { $env:GITHUB_REF = "refs/tags/HEAD" } -$tagName = $env:GITHUB_REF.Substring($env:GITHUB_REF.LastIndexOf("/") + 1) -$archiveName = "win32.flutter.zip" - -git archive --format=zip -o $archiveName $tagName gemini-extension.json commands/ LICENSE README.md flutter.md - -echo "ARCHIVE_NAME=$archiveName" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append diff --git a/scripts/build_release.sh b/scripts/build_release.sh deleted file mode 100755 index da1e019..0000000 --- a/scripts/build_release.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -unset CD_PATH - -# Get the directory where the script is located. -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# The root of the repository. -REPO_ROOT="$(dirname "$SCRIPT_DIR")" - -cd "$REPO_ROOT" - -GITHUB_REF=${GITHUB_REF:-refs/tags/HEAD} -tag_name=${GITHUB_REF#refs/tags/} -os=$(uname -s | tr '[:upper:]' '[:lower:]') - -if [[ $os == 'darwin' ]]; then - arch=$(uname -m | tr '[:upper:]' '[:lower:]') -else - arch='x64' -fi - -archive_name="$os.$arch.flutter.tar" -rm -f "$archive_name" - -# Create the archive of the extension sources that are in the git ref. -git archive --format=tar -o "$archive_name" "$tag_name" \ - gemini-extension.json \ - commands/ \ - LICENSE \ - README.md \ - flutter.md - -gzip --force "$archive_name" -archive_name="${archive_name}.gz" - -if [[ -n $GITHUB_ENV ]]; then - echo "ARCHIVE_NAME=$archive_name" >> $GITHUB_ENV -else - echo "Archive written to $archive_name" -fi \ No newline at end of file diff --git a/scripts/bump_version.sh b/scripts/bump_version.sh deleted file mode 100755 index 904c58f..0000000 --- a/scripts/bump_version.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash - -# Bumps the version number to the given version number. - -set -e - -if [ "$#" -ne 1 ]; then - echo "Usage: $0 " - exit 1 -fi - -NEW_VERSION="$1" - -# Get the absolute path to the directory containing this script. -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -REPO_ROOT="$(dirname "$SCRIPT_DIR")" - -# Update gemini-extension.json -jq --arg version "$NEW_VERSION" '.version = $version' "$REPO_ROOT/gemini-extension.json" > "$REPO_ROOT/gemini-extension.json.tmp" && command mv -f "$REPO_ROOT/gemini-extension.json.tmp" "$REPO_ROOT/gemini-extension.json" - -# Check and update CHANGELOG.md -CHANGELOG_FILE="$REPO_ROOT/CHANGELOG.md" -if ! grep -q "## $NEW_VERSION" "$CHANGELOG_FILE"; then - echo "Adding version $NEW_VERSION to $CHANGELOG_FILE" - TEMP_FILE=$(mktemp) - { - echo "## $NEW_VERSION" - echo "" - echo "- TODO: Describe the changes in this version." - echo "" - cat "$CHANGELOG_FILE" - } > "$TEMP_FILE" - mv "$TEMP_FILE" "$CHANGELOG_FILE" -fi - -echo "Version bumped to $NEW_VERSION" \ No newline at end of file diff --git a/scripts/lib/src/build_release_command.dart b/scripts/lib/src/build_release_command.dart new file mode 100644 index 0000000..87159d3 --- /dev/null +++ b/scripts/lib/src/build_release_command.dart @@ -0,0 +1,103 @@ +import 'package:file/file.dart'; + +import 'utils.dart'; + +/// A command that builds a release archive for the Flutter extension. +/// +/// This command: +/// 1. Detects the current OS and architecture (or uses GITHUB_MATRIX_OS if set). +/// 2. Identifies the repository root. +/// 3. Creates a `.tar.gz` (Linux/macOS) or `.zip` (Windows) archive of the +/// extension source. +/// 4. Sets the `ARCHIVE_NAME` environment variable for GitHub Actions. +class BuildReleaseCommand { + /// The script execution context. + final ScriptContext context; + + /// Creates a [BuildReleaseCommand] with the given [context]. + BuildReleaseCommand(this.context); + + /// Executes the build release process. + /// + /// Returns the path to the created archive. + Future run() async { + final fs = context.fs; + final platform = context.platform; + + final platformInfo = await getPlatformInfo(context); + final os = platformInfo.os; + final arch = platformInfo.arch; + final ext = platformInfo.ext; + + final archiveName = '$os.$arch.flutter.$ext'; + + // Find the repository root by looking for 'gemini-extension.json'. + final repoRoot = findRepoRoot(context); + final repoPath = repoRoot.path; + print('Repository root: $repoPath'); + + String tagName = (platform.environment['GITHUB_REF'] ?? 'refs/tags/HEAD'); + if (tagName.startsWith('refs/tags/')) { + tagName = tagName.substring('refs/tags/'.length); + } + if (tagName.isEmpty) tagName = 'HEAD'; + + if (fs.isFileSync(fs.path.join(repoPath, archiveName))) { + fs.file(fs.path.join(repoPath, archiveName)).deleteSync(); + } + + print('Creating archive $archiveName from $tagName...'); + + final filesToArchive = [ + 'gemini-extension.json', + 'commands/', + 'LICENSE', + 'README.md', + 'flutter.md', + ]; + + if (os == 'windows') { + await runProcess(context, + [ + 'git', + 'archive', + '--format=zip', + '-o', + archiveName, + tagName, + ...filesToArchive + ], + workingDirectory: repoPath); + } else { + final tarName = '$os.$arch.flutter.tar'; + await runProcess(context, + [ + 'git', + 'archive', + '--format=tar', + '-o', + tarName, + tagName, + ...filesToArchive + ], + workingDirectory: repoPath); + + await runProcess(context, [ + 'gzip', + '--force', + tarName, + ], workingDirectory: repoPath); + } + + // Set output env var for GitHub Actions. + final githubEnv = platform.environment['GITHUB_ENV']; + if (githubEnv != null && fs.isFileSync(githubEnv)) { + fs.file(githubEnv).writeAsStringSync('ARCHIVE_NAME=$archiveName\n', + mode: FileMode.append); + } else { + context.stdout.writeln('Archive written to $archiveName'); + } + + return fs.path.join(repoPath, archiveName); + } +} diff --git a/scripts/lib/src/bump_version_command.dart b/scripts/lib/src/bump_version_command.dart new file mode 100644 index 0000000..26dddde --- /dev/null +++ b/scripts/lib/src/bump_version_command.dart @@ -0,0 +1,114 @@ +// Copyright 2025 The Flutter Authors. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:convert'; + +import 'utils.dart'; + +/// A command that updates the extension version. +/// +/// This command: +/// 1. Updates the "version" field in `gemini-extension.json`. +/// 2. Prepends a new version section to `CHANGELOG.md`. +class BumpVersionCommand { + /// The script execution context. + final ScriptContext context; + + /// The new version string (e.g., "1.0.1"). + final String newVersion; + + /// Creates a [BumpVersionCommand] with the given [context] and [newVersion]. + BumpVersionCommand(this.context, this.newVersion); + + /// Executes the version bump process. + Future run() async { + if (newVersion.isEmpty) { + throw ExitException('Usage: bump_version '); + } + + final repoRoot = findRepoRoot(context); + final repoPath = repoRoot.path; + + _updateExtensionJson(repoPath); + _updateChangelog(repoPath); + + context.stdout.writeln('Version bumped to $newVersion'); + } + + void _updateExtensionJson(String repoPath) { + final fs = context.fs; + final jsonFile = fs.file(fs.path.join(repoPath, 'gemini-extension.json')); + + if (!jsonFile.existsSync()) { + throw ExitException( + 'gemini-extension.json not found at ${jsonFile.path}', + ); + } + + final String content = jsonFile.readAsStringSync(); + final Map json; + try { + json = jsonDecode(content) as Map; + } on FormatException catch (e) { + throw ExitException( + 'Failed to parse gemini-extension.json: ${e.message}', + ); + } + + if (!json.containsKey('version')) { + throw ExitException( + 'Could not find "version" field in gemini-extension.json', + ); + } + + json['version'] = newVersion; + + // Use an encoder with indentation for readability and add a trailing newline. + const encoder = JsonEncoder.withIndent(' '); + jsonFile.writeAsStringSync('${encoder.convert(json)}\n'); + } + + void _updateChangelog(String repoPath) { + final fs = context.fs; + final changelogFile = fs.file(fs.path.join(repoPath, 'CHANGELOG.md')); + + if (!changelogFile.existsSync()) { + print('Warning: CHANGELOG.md not found.'); + return; + } + + final changelogContent = changelogFile.readAsStringSync(); + if (changelogContent.contains('## $newVersion')) { + // Version already exists, no need to add again. + return; + } + + print('Adding version $newVersion to CHANGELOG.md'); + + final newSection = + '## $newVersion\n\n- TODO: Describe the changes in this version.\n\n'; + + int insertIndex = 0; + + // Strategy: + // 1. Insert before the first `## Version` header. + // 2. If no version headers, prepend to file. + final firstHeaderMatch = RegExp( + r'^##\s', + multiLine: true, + ).firstMatch(changelogContent); + + if (firstHeaderMatch != null) { + insertIndex = firstHeaderMatch.start; + changelogFile.writeAsStringSync( + changelogContent.substring(0, insertIndex) + + newSection + + changelogContent.substring(insertIndex), + ); + } else { + // No existing version headers, so prepend to the file. + changelogFile.writeAsStringSync(newSection + changelogContent); + } + } +} diff --git a/scripts/lib/src/update_local_command.dart b/scripts/lib/src/update_local_command.dart new file mode 100644 index 0000000..ebc452f --- /dev/null +++ b/scripts/lib/src/update_local_command.dart @@ -0,0 +1,70 @@ +// Copyright 2025 The Flutter Authors. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'build_release_command.dart'; +import 'utils.dart'; + +/// A command that updates the local installation of the extension. +/// +/// This command: +/// 1. Builds the release archive using [BuildReleaseCommand]. +/// 2. Clears the local installation directory at `~/.gemini/extensions/flutter`. +/// 3. Extracts the new archive into the installation directory. +class UpdateLocalCommand { + /// The script execution context. + final ScriptContext context; + + /// Creates an [UpdateLocalCommand] with the given [context]. + UpdateLocalCommand(this.context); + + /// Executes the update process. + Future run() async { + // 1. Build release + print('Building the release...'); + final archivePath = await BuildReleaseCommand(context).run(); + + final fs = context.fs; + final platform = context.platform; + + // 2. Clear and install + final home = platform.environment['HOME'] ?? platform.environment['USERPROFILE']; + if (home == null || home.isEmpty) { + throw ExitException( + 'Could not determine home directory. Please set HOME or USERPROFILE.'); + } + final installDir = fs.path.join( + home, + '.gemini', + 'extensions', + 'flutter', + ); + + print('Clearing the installation directory ($installDir)...'); + + final installDirectory = fs.directory(installDir); + if (installDirectory.existsSync()) { + installDirectory.deleteSync(recursive: true); + } + installDirectory.createSync(recursive: true); + + // 3. Extract + print('Extracting the archive...'); + + if (!fs.isFileSync(archivePath)) { + throw ExitException('Archive not found at $archivePath after build.'); + } + + if (platform.isWindows) { + await runProcess(context, [ + 'powershell', + '-command', + 'Expand-Archive -Path "$archivePath" -DestinationPath "$installDir" -Force' + ]); + } else { + await runProcess(context, ['tar', '-xzf', archivePath, '-C', installDir]); + } + + context.stdout.writeln('Installation complete.'); + } +} diff --git a/scripts/lib/src/utils.dart b/scripts/lib/src/utils.dart new file mode 100644 index 0000000..6f04237 --- /dev/null +++ b/scripts/lib/src/utils.dart @@ -0,0 +1,215 @@ +// Copyright 2025 The Flutter Authors. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Shared utilities for the Flutter extension scripts. +/// +/// This library provides a standard [ScriptContext] for dependency injection +/// and a [runScript] runner for consistent error handling. +library; + +import 'dart:io' as io; + +import 'package:file/file.dart'; +import 'package:file/local.dart'; +import 'package:platform/platform.dart'; +import 'package:process/process.dart'; + +/// An exception that indicates a controlled exit with a specific message and code. +/// +/// This exception is caught by [runScript] to exit the process gracefully +/// without printing a stack trace. +class ExitException implements Exception { + /// The error message to display to the user. + final String message; + + /// The exit code to return to the shell (default is 1). + final int exitCode; + + /// Creates a new [ExitException] with the given [message] and optional [exitCode]. + ExitException(this.message, {this.exitCode = 1}); + + @override + String toString() => message; +} + +/// Provides the runtime context (filesystem, platform, process manager) for scripts. +/// +/// This class enables dependency injection for easier testing by allowing +/// mock implementations of [FileSystem], [Platform], and [ProcessManager] to be +/// passed in. +class ScriptContext { + /// The file system interface. + final FileSystem fs; + + /// The platform interface (for environment variables, OS detection, etc.). + final Platform platform; + + /// The process manager for spawning subprocesses. + final ProcessManager pm; + + /// The standard output sink. + final io.IOSink stdout; + + /// The standard error sink. + final io.IOSink stderr; + + /// Creates a new [ScriptContext]. + /// + /// Dependencies default to their local implementations ([LocalFileSystem], + /// [LocalPlatform], [LocalProcessManager], [io.stdout], [io.stderr]) if not provided. + ScriptContext({ + FileSystem? fs, + Platform? platform, + ProcessManager? pm, + io.IOSink? stdout, + io.IOSink? stderr, + }) : fs = fs ?? const LocalFileSystem(), + platform = platform ?? const LocalPlatform(), + pm = pm ?? const LocalProcessManager(), + stdout = stdout ?? io.stdout, + stderr = stderr ?? io.stderr; +} + +/// Runs the [callback] with the given [context], handling [ExitException]s. +/// +/// If the [callback] throws an [ExitException], this function prints the +/// exception's message to stderr and exits the process with the specified +/// exit code. Unexpected exceptions print the error and stack trace and exit +/// with code 1. +Future runScript( + Future Function(ScriptContext context) callback, { + ScriptContext? context, +}) async { + try { + await callback(context ?? ScriptContext()); + } on ExitException catch (e) { + if (e.message.isNotEmpty) { + io.stderr.writeln(e.message); + } + io.exit(e.exitCode); + } catch (e, stack) { + io.stderr.writeln('Unexpected error: $e\n$stack'); + io.exit(1); + } +} + +/// Finds the repository root by looking for `gemini-extension.json`. +/// +/// Throws an [ExitException] if the repository root cannot be found. +Directory findRepoRoot(ScriptContext context) { + final fs = context.fs; + Directory? repoRoot = fs.currentDirectory; + + while (repoRoot != null) { + if (fs.isFileSync(fs.path.join(repoRoot.path, 'gemini-extension.json'))) { + return repoRoot; + } + if (repoRoot.path == repoRoot.parent.path) { + break; + } + repoRoot = repoRoot.parent; + } + + throw ExitException( + 'Could not find repository root (looked for gemini-extension.json)', + ); +} + +/// Information about the platform and the archive extension. +typedef PlatformInfo = ({String os, String arch, String ext}); + +/// Determines the target platform information. +/// +/// Checks `GITHUB_MATRIX_OS` first, then falls back to the current platform. +Future getPlatformInfo(ScriptContext context) async { + final platform = context.platform; + + String os; + String arch; + + final githubMatrixOs = platform.environment['GITHUB_MATRIX_OS']; + if (githubMatrixOs != null && githubMatrixOs.isNotEmpty) { + if (githubMatrixOs.startsWith('macos')) { + os = 'darwin'; + } else if (githubMatrixOs.startsWith('windows')) { + os = 'windows'; + } else if (githubMatrixOs.startsWith('ubuntu')) { + os = 'linux'; + } else { + throw ExitException('Unknown GITHUB_MATRIX_OS: $githubMatrixOs'); + } + + if (os == 'windows') { + arch = platform.environment['RUNNER_ARCH']?.toLowerCase() ?? 'x64'; + } else { + var runnerArch = platform.environment['RUNNER_ARCH']; + if (runnerArch != null && runnerArch.isNotEmpty) { + arch = runnerArch.toLowerCase(); + } else { + var unameM = await captureProcessOutput(context, ['uname', '-m']); + arch = unameM.trim().toLowerCase(); + } + } + } else { + os = platform.operatingSystem; + if (os == 'macos') { + os = 'darwin'; + } + + if (os == 'darwin' || os == 'linux') { + var unameM = await captureProcessOutput(context, ['uname', '-m']); + arch = unameM.trim().toLowerCase(); + } else if (os == 'windows') { + arch = 'x64'; + } else { + throw ExitException('Unknown OS: $os'); + } + } + + final ext = os == 'windows' ? 'zip' : 'tar.gz'; + return (os: os, arch: arch, ext: ext); +} + +/// Runs a command and streams its output to stdout/stderr. +Future runProcess( + ScriptContext context, + List command, { + String? workingDirectory, +}) async { + final pm = context.pm; + final process = await pm.start(command, workingDirectory: workingDirectory); + + // Pipe process output to main process output + process.stdout + .transform(io.systemEncoding.decoder) + .listen(context.stdout.write); + process.stderr + .transform(io.systemEncoding.decoder) + .listen(context.stderr.write); + + final exitCode = await process.exitCode; + if (exitCode != 0) { + throw ExitException( + 'Command failed with exit code $exitCode: ${command.join(" ")}', + ); + } +} + +/// Runs a command and returns its stdout trimmed. +Future captureProcessOutput( + ScriptContext context, + List command, { + String? workingDirectory, +}) async { + final result = await context.pm.run( + command, + workingDirectory: workingDirectory, + ); + if (result.exitCode != 0) { + throw ExitException( + 'Command failed: ${command.join(" ")}\nStderr: ${result.stderr}', + ); + } + return (result.stdout as String).trim(); +} diff --git a/scripts/pubspec.lock b/scripts/pubspec.lock new file mode 100644 index 0000000..207ccec --- /dev/null +++ b/scripts/pubspec.lock @@ -0,0 +1,397 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: "5b7468c326d2f8a4f630056404ca0d291ade42918f4a3c6233618e724f39da8e" + url: "https://pub.dev" + source: hosted + version: "92.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + sha256: "70e4b1ef8003c64793a9e268a551a82869a8a96f39deb73dea28084b0e8bf75e" + url: "https://pub.dev" + source: hosted + version: "9.0.0" + args: + dependency: "direct main" + description: + name: args + sha256: d0481093c50b1da8910eb0bb301626d4d8eb7284aa739614d2b394ee09e3ea04 + url: "https://pub.dev" + source: hosted + version: "2.7.0" + async: + dependency: transitive + description: + name: async + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" + url: "https://pub.dev" + source: hosted + version: "2.13.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + cli_config: + dependency: transitive + description: + name: cli_config + sha256: ac20a183a07002b700f0c25e61b7ee46b23c309d76ab7b7640a028f18e4d99ec + url: "https://pub.dev" + source: hosted + version: "0.2.0" + collection: + dependency: transitive + description: + name: collection + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" + url: "https://pub.dev" + source: hosted + version: "1.19.1" + convert: + dependency: transitive + description: + name: convert + sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68 + url: "https://pub.dev" + source: hosted + version: "3.1.2" + coverage: + dependency: transitive + description: + name: coverage + sha256: "5da775aa218eaf2151c721b16c01c7676fbfdd99cebba2bf64e8b807a28ff94d" + url: "https://pub.dev" + source: hosted + version: "1.15.0" + crypto: + dependency: transitive + description: + name: crypto + sha256: c8ea0233063ba03258fbcf2ca4d6dadfefe14f02fab57702265467a19f27fadf + url: "https://pub.dev" + source: hosted + version: "3.0.7" + file: + dependency: "direct main" + description: + name: file + sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4 + url: "https://pub.dev" + source: hosted + version: "7.0.1" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694 + url: "https://pub.dev" + source: hosted + version: "4.0.0" + glob: + dependency: transitive + description: + name: glob + sha256: c3f1ee72c96f8f78935e18aa8cecced9ab132419e8625dc187e1c2408efc20de + url: "https://pub.dev" + source: hosted + version: "2.1.3" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + sha256: aa6199f908078bb1c5efb8d8638d4ae191aac11b311132c3ef48ce352fb52ef8 + url: "https://pub.dev" + source: hosted + version: "3.2.2" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571" + url: "https://pub.dev" + source: hosted + version: "4.1.2" + io: + dependency: transitive + description: + name: io + sha256: dfd5a80599cf0165756e3181807ed3e77daf6dd4137caaad72d0b7931597650b + url: "https://pub.dev" + source: hosted + version: "1.0.5" + logging: + dependency: transitive + description: + name: logging + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 + url: "https://pub.dev" + source: hosted + version: "1.3.0" + matcher: + dependency: transitive + description: + name: matcher + sha256: "12956d0ad8390bbcc63ca2e1469c0619946ccb52809807067a7020d57e647aa6" + url: "https://pub.dev" + source: hosted + version: "0.12.18" + meta: + dependency: transitive + description: + name: meta + sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + url: "https://pub.dev" + source: hosted + version: "1.17.0" + mime: + dependency: transitive + description: + name: mime + sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6" + url: "https://pub.dev" + source: hosted + version: "2.0.0" + node_preamble: + dependency: transitive + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" + package_config: + dependency: transitive + description: + name: package_config + sha256: f096c55ebb7deb7e384101542bfba8c52696c1b56fca2eb62827989ef2353bbc + url: "https://pub.dev" + source: hosted + version: "2.2.0" + path: + dependency: "direct main" + description: + name: path + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + platform: + dependency: "direct main" + description: + name: platform + sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984" + url: "https://pub.dev" + source: hosted + version: "3.1.6" + pool: + dependency: transitive + description: + name: pool + sha256: "978783255c543aa3586a1b3c21f6e9d720eb315376a915872c61ef8b5c20177d" + url: "https://pub.dev" + source: hosted + version: "1.5.2" + process: + dependency: "direct main" + description: + name: process + sha256: c6248e4526673988586e8c00bb22a49210c258dc91df5227d5da9748ecf79744 + url: "https://pub.dev" + source: hosted + version: "5.0.5" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "5bfcf68ca79ef689f8990d1160781b4bad40a3bd5e5218ad4076ddb7f4081585" + url: "https://pub.dev" + source: hosted + version: "2.2.0" + shelf: + dependency: transitive + description: + name: shelf + sha256: e7dd780a7ffb623c57850b33f43309312fc863fb6aa3d276a754bb299839ef12 + url: "https://pub.dev" + source: hosted + version: "1.4.2" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: transitive + description: + name: shelf_static + sha256: c87c3875f91262785dade62d135760c2c69cb217ac759485334c5857ad89f6e3 + url: "https://pub.dev" + source: hosted + version: "1.1.3" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + sha256: "3632775c8e90d6c9712f883e633716432a27758216dfb61bd86a8321c0580925" + url: "https://pub.dev" + source: hosted + version: "3.0.0" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + sha256: c0713a43e323c3302c2abe2a1cc89aa057a387101ebd280371d6a6c9fa68516b + url: "https://pub.dev" + source: hosted + version: "2.1.2" + source_maps: + dependency: transitive + description: + name: source_maps + sha256: "190222579a448b03896e0ca6eca5998fa810fda630c1d65e2f78b3f638f54812" + url: "https://pub.dev" + source: hosted + version: "0.10.13" + source_span: + dependency: transitive + description: + name: source_span + sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" + url: "https://pub.dev" + source: hosted + version: "1.10.1" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1" + url: "https://pub.dev" + source: hosted + version: "1.12.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" + url: "https://pub.dev" + source: hosted + version: "1.4.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" + url: "https://pub.dev" + source: hosted + version: "1.2.2" + test: + dependency: "direct dev" + description: + name: test + sha256: "77cc98ea27006c84e71a7356cf3daf9ddbde2d91d84f77dbfe64cf0e4d9611ae" + url: "https://pub.dev" + source: hosted + version: "1.28.0" + test_api: + dependency: transitive + description: + name: test_api + sha256: "19a78f63e83d3a61f00826d09bc2f60e191bf3504183c001262be6ac75589fb8" + url: "https://pub.dev" + source: hosted + version: "0.7.8" + test_core: + dependency: transitive + description: + name: test_core + sha256: f1072617a6657e5fc09662e721307f7fb009b4ed89b19f47175d11d5254a62d4 + url: "https://pub.dev" + source: hosted + version: "0.6.14" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: "45caa6c5917fa127b5dbcfbd1fa60b14e583afdc08bfc96dda38886ca252eb60" + url: "https://pub.dev" + source: hosted + version: "15.0.2" + watcher: + dependency: transitive + description: + name: watcher + sha256: f52385d4f73589977c80797e60fe51014f7f2b957b5e9a62c3f6ada439889249 + url: "https://pub.dev" + source: hosted + version: "1.2.0" + web: + dependency: transitive + description: + name: web + sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + web_socket: + dependency: transitive + description: + name: web_socket + sha256: "34d64019aa8e36bf9842ac014bb5d2f5586ca73df5e4d9bf5c936975cae6982c" + url: "https://pub.dev" + source: hosted + version: "1.0.1" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: d645757fb0f4773d602444000a8131ff5d48c9e47adfe9772652dd1a4f2d45c8 + url: "https://pub.dev" + source: hosted + version: "3.0.3" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + yaml: + dependency: transitive + description: + name: yaml + sha256: b9da305ac7c39faa3f030eccd175340f968459dae4af175130b3fc47e40d76ce + url: "https://pub.dev" + source: hosted + version: "3.1.3" +sdks: + dart: ">=3.9.0 <4.0.0" diff --git a/scripts/pubspec.yaml b/scripts/pubspec.yaml new file mode 100644 index 0000000..10e9d82 --- /dev/null +++ b/scripts/pubspec.yaml @@ -0,0 +1,21 @@ +# Copyright 2025 The Flutter Authors. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +name: release_scripts +description: Scripts for maintaining the flutter gemini extension. +version: 1.0.0 +publish_to: none + +environment: + sdk: ">=3.9.0 <4.0.0" + +dependencies: + args: ^2.4.2 + file: ^7.0.0 + path: ^1.8.3 + platform: ^3.1.0 + process: ^5.0.0 + +dev_dependencies: + test: ^1.24.6 diff --git a/scripts/test/scripts_test.dart b/scripts/test/scripts_test.dart new file mode 100644 index 0000000..25332e6 --- /dev/null +++ b/scripts/test/scripts_test.dart @@ -0,0 +1,485 @@ +// Copyright 2025 The Flutter Authors. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:convert'; +import 'dart:io'; + +import 'package:file/file.dart'; +import 'package:file/memory.dart'; +import 'package:platform/platform.dart'; +import 'package:process/process.dart'; +import 'package:release_scripts/src/build_release_command.dart'; +import 'package:release_scripts/src/bump_version_command.dart'; +import 'package:release_scripts/src/update_local_command.dart'; +import 'package:release_scripts/src/utils.dart'; +import 'package:test/test.dart'; + +void main() { + group('BuildReleaseCommand', () { + late BuildReleaseCommand command; + late MockProcessManager pm; + late MemoryFileSystem fs; + late FakePlatform platform; + late FakeIOSink stdout; + late FakeIOSink stderr; + + setUp(() { + fs = MemoryFileSystem(style: FileSystemStyle.posix); + pm = MockProcessManager(fs: fs); + platform = FakePlatform( + operatingSystem: 'linux', + environment: {'HOME': '/home/user'}, + ); + stdout = FakeIOSink(); + stderr = FakeIOSink(); + final context = ScriptContext( + fs: fs, + pm: pm, + platform: platform, + stdout: stdout, + stderr: stderr, + ); + command = BuildReleaseCommand(context); + + // Setup repo root + fs.directory('/repo').createSync(); + fs.file('/repo/gemini-extension.json').createSync(); + fs.currentDirectory = '/repo'; + }); + + test('builds release archive successfully', () async { + final archivePath = await command.run(); + + expect(archivePath, '/repo/linux.arm64.flutter.tar.gz'); + expect( + stdout.toString(), + contains('Archive written to linux.arm64.flutter.tar.gz'), + ); + + expect( + pm.executedCommands, + containsAll([ + 'git archive --format=tar -o linux.arm64.flutter.tar HEAD gemini-extension.json commands/ LICENSE README.md flutter.md', + 'gzip --force linux.arm64.flutter.tar', + ]), + ); + }); + + test('parses tagName from GITHUB_REF', () async { + platform.environment['GITHUB_REF'] = 'refs/tags/v1.2.3'; + + final archivePath = await command.run(); + + expect(archivePath, '/repo/linux.arm64.flutter.tar.gz'); + // Verify correct tag was used in git archive command + expect( + pm.executedCommands.any( + (cmd) => + cmd.contains('git archive') && + cmd.contains('v1.2.3') && + !cmd.contains('--prefix'), + ), + isTrue, + reason: 'Should use tag name v1.2.3 from GITHUB_REF without prefix', + ); + }); + + test('detects architecture dynamically on Linux (arm64)', () async { + // Mock uname -m response handled in MockProcessManager + + final archivePath = await command.run(); + + expect(archivePath, '/repo/linux.arm64.flutter.tar.gz'); + expect(pm.executedCommands, contains('uname -m')); + }); + + test('builds release with RUNNER_ARCH env var', () async { + platform.environment['GITHUB_MATRIX_OS'] = 'ubuntu-latest'; + platform.environment['RUNNER_ARCH'] = 'ARM64'; + + final archivePath = await command.run(); + + expect(archivePath, '/repo/linux.arm64.flutter.tar.gz'); + }); + + test('builds release archive successfully on Windows', () async { + // Re-initialize for Windows + fs = MemoryFileSystem(style: FileSystemStyle.windows); + pm = MockProcessManager(fs: fs); + platform = FakePlatform( + operatingSystem: 'windows', + environment: {'USERPROFILE': r'C:\Users\user'}, + ); + stdout = FakeIOSink(); + stderr = FakeIOSink(); + + // Setup repo + fs.directory(r'C:\repo').createSync(recursive: true); + fs.file(r'C:\repo\gemini-extension.json').createSync(); + fs.currentDirectory = r'C:\repo'; + + final context = ScriptContext( + fs: fs, + pm: pm, + platform: platform, + stdout: stdout, + stderr: stderr, + ); + command = BuildReleaseCommand(context); + + final archivePath = await command.run(); + + expect(archivePath, r'C:\repo\windows.x64.flutter.zip'); + expect( + pm.executedCommands, + containsAll([ + 'git archive --format=zip -o windows.x64.flutter.zip HEAD gemini-extension.json commands/ LICENSE README.md flutter.md', + ]), + ); + }); + }); + + group('BumpVersionCommand', () { + late BumpVersionCommand command; + late MockProcessManager pm; + late MemoryFileSystem fs; + late FakePlatform platform; + late FakeIOSink stdout; + late FakeIOSink stderr; + + setUp(() { + fs = MemoryFileSystem(); + pm = MockProcessManager(); + platform = FakePlatform(); + stdout = FakeIOSink(); + stderr = FakeIOSink(); + final context = ScriptContext( + fs: fs, + pm: pm, + platform: platform, + stdout: stdout, + stderr: stderr, + ); + command = BumpVersionCommand(context, '1.0.1'); + + // Setup repo and files + fs.directory('/repo').createSync(); + fs + .file('/repo/gemini-extension.json') + .writeAsStringSync('{"version": "1.0.0"}'); + fs + .file('/repo/CHANGELOG.md') + .writeAsStringSync('# Changelog\n\n## 1.0.0\n\nNotes'); + fs.currentDirectory = '/repo'; + }); + + test('updates version in files', () async { + await command.run(); + + final jsonContent = json.decode( + fs.file('/repo/gemini-extension.json').readAsStringSync(), + ); + expect(jsonContent['version'], '1.0.1'); + + final changelog = fs.file('/repo/CHANGELOG.md').readAsStringSync(); + expect(changelog, contains('## 1.0.1')); + expect(changelog, contains('TODO: Describe the changes')); + + expect(stdout.toString(), contains('Version bumped to 1.0.1')); + }); + }); + + group('UpdateLocalCommand', () { + late UpdateLocalCommand command; + late MockProcessManager pm; + late MemoryFileSystem fs; + late FakePlatform platform; + late FakeIOSink stdout; + late FakeIOSink stderr; + + setUp(() { + fs = MemoryFileSystem(style: FileSystemStyle.posix); + pm = MockProcessManager(fs: fs); + platform = FakePlatform( + operatingSystem: 'linux', + environment: {'HOME': '/home/user'}, + ); + stdout = FakeIOSink(); + stderr = FakeIOSink(); + final context = ScriptContext( + fs: fs, + pm: pm, + platform: platform, + stdout: stdout, + stderr: stderr, + ); + command = UpdateLocalCommand(context); + + fs.directory('/repo').createSync(); + fs.file('/repo/gemini-extension.json').createSync(); + fs.currentDirectory = '/repo'; + }); + + test('updates local installation', () async { + await command.run(); + + expect( + fs.directory('/home/user/.gemini/extensions/flutter').existsSync(), + isTrue, + ); + expect( + pm.executedCommands, + contains( + 'tar -xzf /repo/linux.arm64.flutter.tar.gz -C /home/user/.gemini/extensions/flutter', + ), + ); + + expect(stdout.toString(), contains('Installation complete.')); + }); + + test('updates local installation on Windows', () async { + // Re-initialize for Windows + fs = MemoryFileSystem(style: FileSystemStyle.windows); + pm = MockProcessManager(fs: fs); + platform = FakePlatform( + operatingSystem: 'windows', + environment: {'USERPROFILE': r'C:\Users\user'}, + ); + stdout = FakeIOSink(); + stderr = FakeIOSink(); + + // Setup repo + fs.directory(r'C:\repo').createSync(recursive: true); + fs.file(r'C:\repo\gemini-extension.json').createSync(); + fs.currentDirectory = r'C:\repo'; + + final context = ScriptContext( + fs: fs, + pm: pm, + platform: platform, + stdout: stdout, + stderr: stderr, + ); + command = UpdateLocalCommand(context); + + await command.run(); + + expect( + fs.directory(r'C:\Users\user\.gemini\extensions\flutter').existsSync(), + isTrue, + reason: 'Installation directory should exist', + ); + + // Check executed commands contain powershell + expect( + pm.executedCommands.any( + (cmd) => cmd.contains('powershell') && cmd.contains('Expand-Archive'), + ), + isTrue, + reason: 'Should use PowerShell Expand-Archive', + ); + }); + }); +} + +class FakeIOSink implements IOSink { + final StringBuffer buffer = StringBuffer(); + + @override + Encoding encoding = systemEncoding; + + @override + void add(List data) { + buffer.write(String.fromCharCodes(data)); + } + + @override + void write(Object? object) { + buffer.write(object); + } + + @override + void writeln([Object? object = ""]) { + buffer.writeln(object); + } + + @override + void writeAll(Iterable objects, [String separator = ""]) { + buffer.writeAll(objects, separator); + } + + @override + void writeCharCode(int charCode) { + buffer.writeCharCode(charCode); + } + + @override + Future addStream(Stream> stream) async { + await for (final data in stream) { + add(data); + } + } + + @override + Future flush() async {} + + @override + Future close() async {} + + @override + Future get done => Future.value(); + + @override + void addError(Object error, [StackTrace? stackTrace]) {} + + @override + String toString() => buffer.toString(); +} + +class MockProcessManager implements ProcessManager { + final List executedCommands = []; + final FileSystem? fs; + + MockProcessManager({this.fs}); + + @override + Future start( + List command, { + String? workingDirectory, + Map? environment, + bool includeParentEnvironment = true, + bool runInShell = false, + ProcessStartMode mode = ProcessStartMode.normal, + }) async { + executedCommands.add(command.map((e) => e.toString()).join(' ')); + _handleSideEffects(command, workingDirectory); + return _MockProcess(); + } + + @override + Future run( + List command, { + String? workingDirectory, + Map? environment, + bool includeParentEnvironment = true, + bool runInShell = false, + Encoding? stdoutEncoding = systemEncoding, + Encoding? stderrEncoding = systemEncoding, + }) async { + final cmdStr = command.map((e) => e.toString()).join(' '); + executedCommands.add(cmdStr); + _handleSideEffects(command, workingDirectory); + + // Return appropriate responses directly based on command content + if (cmdStr.contains('uname -m')) { + return ProcessResult(0, 0, 'arm64', ''); + } + return ProcessResult(0, 0, '', ''); + } + + void _handleSideEffects(List command, String? workingDirectory) { + if (fs == null) return; + + // Detect git archive -o output_file + if (command.contains('git') && + command.contains('archive') && + command.contains('-o')) { + final outputIndex = command.indexOf('-o'); + if (outputIndex != -1 && outputIndex + 1 < command.length) { + final outputFile = command[outputIndex + 1] as String; + final dir = workingDirectory ?? fs!.currentDirectory.path; + final path = fs!.path.join(dir, outputFile); + // Create dummy file + if (fs!.isFileSync(path)) fs!.file(path).deleteSync(); + fs!.file(path).createSync(recursive: true); + } + } + // Handle gzip which replaces .tar with .tar.gz (if we were using gzip command) + if (command.contains('gzip')) { + final tarName = command.last as String; + if (tarName.endsWith('.tar')) { + final dir = workingDirectory ?? fs!.currentDirectory.path; + final tarPath = fs!.path.join(dir, tarName); + final gzPath = '$tarPath.gz'; + if (fs!.isFileSync(tarPath)) { + fs!.file(gzPath).createSync(); + fs!.file(tarPath).deleteSync(); + } + } + } + // Handle PowerShell Expand-Archive + if (command.contains('powershell')) { + dynamic cmdArg; + for (final element in command) { + if (element.toString().contains('Expand-Archive')) { + cmdArg = element; + break; + } + } + if (cmdArg != null) { + // Parse destination path roughly + // Expand-Archive -Path "..." -DestinationPath "..." -Force + final match = RegExp( + r'-DestinationPath "([^"]+)"', + ).firstMatch(cmdArg.toString()); + if (match != null) { + final destDir = match.group(1)!; + // Ensure we treat the path as appropriate for the style (Windows) + // But MockProcessManager.fs style is dynamic. + // destination path usually passed clean from UpdateLocalCommand. + if (!fs!.directory(destDir).existsSync()) { + fs!.directory(destDir).createSync(recursive: true); + } + } + } + } + } + + + + @override + ProcessResult runSync( + List command, { + String? workingDirectory, + Map? environment, + bool includeParentEnvironment = true, + bool runInShell = false, + Encoding? stdoutEncoding = systemEncoding, + Encoding? stderrEncoding = systemEncoding, + }) { + final cmdStr = command.map((e) => e.toString()).join(' '); + executedCommands.add(cmdStr); + if (cmdStr.contains('uname -m')) { + return ProcessResult(0, 0, 'arm64', ''); + } + return ProcessResult(0, 0, '', ''); + } + + @override + bool canRun(dynamic executable, {String? workingDirectory}) => true; + + @override + bool killPid(int pid, [ProcessSignal signal = ProcessSignal.sigterm]) => true; +} + +class _MockProcess implements Process { + @override + Future get exitCode => Future.value(0); + + @override + Stream> get stdout => Stream.empty(); + + @override + Stream> get stderr => Stream.empty(); + + @override + IOSink get stdin => IOSink(StreamController()); + + @override + bool kill([ProcessSignal signal = ProcessSignal.sigterm]) => true; + + @override + int get pid => 0; +} diff --git a/scripts/update_local.sh b/scripts/update_local.sh deleted file mode 100755 index ea1c120..0000000 --- a/scripts/update_local.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -set -e - -unset CD_PATH - -# Get the directory where the script is located. -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# The root of the repository. -REPO_ROOT="$(dirname "$SCRIPT_DIR")" - -cd "$REPO_ROOT" - -# The name of the archive that will be produced. -os=$(uname -s | tr '[:upper:]' '[:lower:]') -if [[ $os == 'darwin' ]]; then - arch=$(uname -m | tr '[:upper:]' '[:lower:]') -else - arch='x64' -fi - -ARCHIVE_NAME="$os.$arch.flutter.tar.gz" - -# The directory where the extension will be installed. -INSTALL_DIR="$HOME/.gemini/extensions/flutter" - -# Run the build script. -echo "Building the release..." -"$SCRIPT_DIR/build_release.sh" - -# Remove all non-dot files from the install directory. -echo "Clearing the installation directory..." -if [ -d "$INSTALL_DIR" ]; then - rm -rf "$INSTALL_DIR"/* -else - mkdir -p "$INSTALL_DIR" -fi - -# Extract the archive to the install directory. -echo "Extracting the archive..." -tar -xzf "$REPO_ROOT/$ARCHIVE_NAME" -C "$INSTALL_DIR" - -echo "Installation complete." \ No newline at end of file