Skip to content

Commit

Permalink
Fixed issue with regerx
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Sep 20, 2023
1 parent 3eb1de2 commit 4b6aa44
Show file tree
Hide file tree
Showing 11 changed files with 1,335 additions and 35 deletions.
1 change: 1 addition & 0 deletions .github/actions/prepare/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ inputs:
runs:
using: "composite"
steps:

- name: Setup Dart
uses: dart-lang/setup-dart@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ runs:
shell: bash

- name: Run tests
run: dart test
run: dart test --coverage=coverage
shell: bash
12 changes: 12 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
PUB_CREDENTIALS: ${{ secrets.PUB_CREDENTIALS }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare environment
uses: ./.github/actions/prepare

Expand All @@ -34,6 +37,9 @@ jobs:
env:
CHOCOLATEY_TOKEN: ${{ secrets.CHOCOLATEY_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare environment
uses: ./.github/actions/prepare

Expand All @@ -49,6 +55,9 @@ jobs:
GITHUB_TOKEN: ${{ secrets.HOMEBREW_FVM_GH_TOKEN }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare environment
uses: ./.github/actions/prepare

Expand All @@ -60,6 +69,9 @@ jobs:
runs-on: ubuntu-latest
needs: release
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare environment
uses: ./.github/actions/prepare

Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ concurrency:

jobs:
test:
name: Initial test
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -32,11 +32,9 @@ jobs:
with:
sdk-version: ${{ github.event.inputs.sdk-version }}

- run: grind test

- name: Run tests
run: dart test --coverage=coverage
shell: bash
uses: ./.github/actions/test


- name: Generate coverage reports
run: grind coverage
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Files and directories created by pub
.dart_tool/
.packages
# Remove the following pattern if you wish to check in your lock file
pubspec.lock

# Do not version the sdk versions
versions/
.DS_Store
Expand Down
45 changes: 29 additions & 16 deletions lib/src/utils/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,40 +112,53 @@ class FlutterVersionOutput {
// Engine • revision a9d88a4d18
// Tools • Dart 2.13.0
FlutterVersionOutput extractFlutterVersionOutput(String content) {
final filteredContent = _extractFlutterInfoBlock(content);
final flutterRegex = RegExp(r'Flutter (\S+)');
final channelRegex = RegExp(r'channel (\w+)');
final channelRegex = RegExp(r' channel (\w+)');
final dartRegex = RegExp(r'Dart (\S+)');
final dartBuildRegex = RegExp(r'Dart (\S+) \(build (\S+)\)');

final flutterMatch = flutterRegex.firstMatch(content);
final channelMatch = channelRegex.firstMatch(content);
final dartMatch = dartRegex.firstMatch(content);
final dartBuildMatch = dartBuildRegex.firstMatch(content);
final flutterMatch = flutterRegex.firstMatch(filteredContent);
final channelMatch = channelRegex.firstMatch(filteredContent);
final dartMatch = dartRegex.firstMatch(filteredContent);
final dartBuildMatch = dartBuildRegex.firstMatch(filteredContent);

if (flutterMatch == null || dartMatch == null) {
throw FormatException(
'Unable to parse Flutter or Dart version from the provided content.');
'Unable to parse Flutter or Dart version from the provided content.',
);
}

final dartVersion = dartMatch.group(1);

print('Content \n$content');
print('channel match');
print(channelMatch?.group(0));
final channel = channelMatch?.group(1);

print('\n Group 1 \n');
print(channelMatch?.group(1));
if (channel == null || !isFlutterChannel(channel)) {
throw FormatException(
'Unable to parse Flutter channel from the provided content.',
);
}

final output = FlutterVersionOutput(
return FlutterVersionOutput(
flutterVersion: flutterMatch.group(1),
channel: channelMatch?.group(1),
channel: channel,
dartVersion: dartVersion,
dartBuildVersion: dartBuildMatch?.group(2) ?? dartVersion,
);
}

print('output');
print(output.toString());
return output;
String _extractFlutterInfoBlock(String content) {
// This regex searches for the line that starts with 'Flutter' and captures all lines after it
// until it hits a line that doesn't follow the expected pattern.
final regex = RegExp(r'Flutter [\S\s]+?(?=\n[^\s]*\s+[^•]*$|$)');

final match = regex.firstMatch(content);

if (match != null) {
return match.group(0)!;
} else {
throw FormatException('Unable to extract the Flutter version block.');
}
}

String extractDartVersionOutput(String input) {
Expand Down
Loading

0 comments on commit 4b6aa44

Please sign in to comment.