-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2344bae
commit af21aea
Showing
10 changed files
with
183 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,13 +1,20 @@ | ||
name: "Test Step" | ||
description: "Tests the project" | ||
name: "Run tests" | ||
description: "Grind tasks for testing" | ||
|
||
inputs: | ||
with-coverage: | ||
description: "Generate coverage reports" | ||
required: false | ||
default: "false" | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Generate git cache | ||
run: ./bin/fvm.dart install master | ||
- name: Run tests | ||
run: dart pub run grinder test | ||
shell: bash | ||
|
||
- name: Run tests | ||
run: dart pub global run grinder:grinder test | ||
shell: bash | ||
- name: Generate coverage report | ||
run: dart pub run grinder coverage | ||
shell: bash | ||
if: ${{ inputs.with-coverage == 'true' }} |
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -34,4 +34,6 @@ dev_dependencies: | |
grinder: ^0.9.4 | ||
test: ^1.24.4 | ||
lints: ^2.1.1 | ||
crypto: ^3.0.3 | ||
http: ^1.1.0 | ||
|
This file contains 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,23 @@ | ||
class Fvm < Formula | ||
desc "Flutter Version Management: A CLI to manage Flutter SDK versions" | ||
homepage "https://github.com/leoafarias/fvm" | ||
version "{{VERSION}}" | ||
|
||
on_macos do | ||
if Hardware::CPU.arm? | ||
url "{{MACOS_ARM64_URL}}" | ||
sha256 "{{MACOS_ARM64_SHA256}}" | ||
else | ||
url "{{MACOS_X64_URL}}" | ||
sha256 "{{MACOS_X64_SHA256}}" | ||
end | ||
end | ||
|
||
def install | ||
bin.install "fvm" | ||
end | ||
|
||
test do | ||
assert_match "FVM #{version}", shell_output("#{bin}/fvm --version").strip | ||
end | ||
end |
This file contains 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 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,95 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:crypto/crypto.dart'; | ||
import 'package:fvm/src/utils/http.dart'; | ||
import 'package:grinder/grinder.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:path/path.dart' as path; | ||
|
||
import 'grind.dart'; | ||
|
||
GrinderTask homebrewTask() => GrinderTask( | ||
'homebrew-formula', | ||
taskFunction: _homebrewFormula, | ||
); | ||
|
||
Future<void> _homebrewFormula() async { | ||
final githubToken = Platform.environment['GITHUB_TOKEN'] ?? ''; | ||
final args = context.invocation.arguments; | ||
final versionArg = args.getOption('version'); | ||
|
||
if (versionArg == null) { | ||
throw Exception('Version is required'); | ||
} | ||
|
||
final url = Uri.parse( | ||
'https://api.github.com/repos/$owner/$repo/releases/tags/$versionArg'); | ||
final headers = { | ||
if (githubToken.isNotEmpty) 'Authorization': 'token $githubToken', | ||
'Accept': 'application/vnd.github.v3+json', | ||
}; | ||
|
||
final response = await fetch(url.toString(), headers: headers); | ||
|
||
final Map<String, dynamic> release = json.decode(response); | ||
final List<dynamic> assets = release['assets']; | ||
final Map<String, dynamic> assetData = {}; | ||
|
||
for (final asset in assets) { | ||
final assetUrl = Uri.parse(asset['browser_download_url']); | ||
final filename = path.basename(assetUrl.path); | ||
|
||
if (!filename.contains('macos-x64') && !filename.contains('macos-arm64')) { | ||
continue; | ||
} | ||
|
||
final sha256Hash = await _downloadFile(assetUrl, filename, headers); | ||
|
||
if (sha256Hash.isNotEmpty) { | ||
assetData[filename] = { | ||
'url': asset['browser_download_url'], | ||
'sha256': sha256Hash, | ||
}; | ||
} | ||
} | ||
|
||
final template = File('tool/fvm.template.rb').readAsStringSync(); | ||
|
||
final macosX64 = assetData['fvm-$versionArg-macos-x64.tar.gz']; | ||
final macosArm64 = assetData['fvm-$versionArg-macos-arm64.tar.gz']; | ||
|
||
final formula = template | ||
.replaceAll('{{VERSION}}', versionArg) | ||
.replaceAll('{{MACOS_X64_URL}}', macosX64['url']) | ||
.replaceAll('{{MACOS_X64_SHA256}}', macosX64['sha256']) | ||
.replaceAll('{{MACOS_ARM64_URL}}', macosArm64['url']) | ||
.replaceAll( | ||
'{{MACOS_ARM64_SHA256}}', | ||
macosArm64['sha256'], | ||
); | ||
|
||
final file = File('fvm.rb'); | ||
file.writeAsStringSync(formula); | ||
} | ||
|
||
Future<String> _downloadFile( | ||
Uri url, | ||
String filename, | ||
Map<String, String> headers, | ||
) async { | ||
final response = await http.get(url, headers: headers); | ||
if (response.statusCode == 200) { | ||
final bytes = response.bodyBytes; | ||
await File(filename).writeAsBytes(bytes); | ||
print('Downloaded: $filename'); | ||
|
||
// Calculate SHA-256 hash | ||
final sha256Hash = sha256.convert(bytes).toString(); | ||
print('SHA-256 Hash: $sha256Hash'); | ||
return sha256Hash; | ||
} else { | ||
print('Failed to download $filename: ${response.statusCode}'); | ||
return ''; | ||
} | ||
} |