-
Notifications
You must be signed in to change notification settings - Fork 17
Convert the scripts to Dart #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gspencergoog
merged 6 commits into
gemini-cli-extensions:main
from
gspencergoog:convert_scripts
Jan 14, 2026
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4c16d2f
Convert the scripts to Dart
gspencergoog e7c8815
Update scripts/lib/src/update_local_command.dart
gspencergoog 4dfe39c
Fix arch handling
gspencergoog 40c21be
Review Changes
gspencergoog fa55852
Merge branch 'main' into convert_scripts
gspencergoog f7f046e
Remove extra arg parsing
gspencergoog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // 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:release_scripts/src/build_release_command.dart'; | ||
| import 'package:release_scripts/src/utils.dart'; | ||
|
|
||
| Future<void> main(List<String> args) async { | ||
| await runScript((context) async { | ||
| await BuildReleaseCommand(context).run(); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // 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:release_scripts/src/bump_version_command.dart'; | ||
| import 'package:release_scripts/src/utils.dart'; | ||
|
|
||
| Future<void> main(List<String> args) async { | ||
| await runScript((context) async { | ||
| if (args.isEmpty) { | ||
| throw ExitException('Usage: bump_version <new_version>'); | ||
| } | ||
| await BumpVersionCommand(context, args[0]).run(); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // 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:release_scripts/src/update_local_command.dart'; | ||
| import 'package:release_scripts/src/utils.dart'; | ||
|
|
||
| Future<void> main(List<String> args) async { | ||
| await runScript((context) async { | ||
| await UpdateLocalCommand(context).run(); | ||
| }); | ||
| } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| 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. | ||
| Future<void> 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 githubRef = platform.environment['GITHUB_REF'] ?? 'refs/tags/HEAD'; | ||
| String tagName = githubRef.replaceFirst('refs/tags/', ''); | ||
| if (tagName.isEmpty) tagName = 'HEAD'; | ||
gspencergoog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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 { | ||
| print('Archive written to $archiveName'); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // 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<void> run() async { | ||
| if (newVersion.isEmpty) { | ||
| throw ExitException('Usage: bump_version <new_version>'); | ||
| } | ||
|
|
||
| final repoRoot = findRepoRoot(context); | ||
| final repoPath = repoRoot.path; | ||
|
|
||
| _updateExtensionJson(repoPath); | ||
| _updateChangelog(repoPath); | ||
|
|
||
| print('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<String, dynamic> json; | ||
| try { | ||
| json = jsonDecode(content) as Map<String, dynamic>; | ||
| } 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, insert after the main title `# Title`. | ||
| // 3. Otherwise, prepend to file. | ||
gspencergoog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.