Skip to content

Commit f16b483

Browse files
authored
✨ Add option to commit version change (#49)
2 parents 52297e6 + 0dace7b commit f16b483

File tree

14 files changed

+9407
-93
lines changed

14 files changed

+9407
-93
lines changed

.github/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: example_project
22
description: Ein Beispielprojekt für die Action
33
environment:
4-
sdk: '0.19.0'
4+
sdk: 3.1.0
55
dependencies:
66
flutter:
77
sdk: flutter

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ jobs:
3232
uses: ./
3333
with:
3434
pubspec_path: '.github/pubspec.yaml'
35+
commit_changes: 'true'
36+
gh_app_id: ${{ secrets.GH_APP_ID }}
37+
gh_private_key: ${{ secrets.GH_PRIVATE_KEY }}
38+
gh_installation_id: ${{ secrets.GH_INSTALLATION_ID }}
3539

3640
- name: Install dependencies
3741
working-directory: .github

.github/workflows/linter.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ jobs:
5858
VALIDATE_CHECKOV: false
5959
VALIDATE_BIOME_LINT: false
6060
VALIDATE_BIOME_FORMAT: false
61+
VALIDATE_MARKDOWN: false

README.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@
66
[![CodeQL](https://github.com/actions/typescript-action/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/actions/typescript-action/actions/workflows/codeql-analysis.yml)
77
[![Coverage](./badges/coverage.svg)](./badges/coverage.svg)
88

9-
> [!NOTE] The current version of this action only supports pinning the exact
10-
> Dart SDK version (e.g., `sdk: 3.1.0`). It does not yet support version ranges
11-
> (e.g., `sdk: '>=3.1.0 <4.0.0'`).
12-
13-
**flutter-dart-sync** is a GitHub Action that automatically updates the Dart SDK
14-
version in your `pubspec.yaml` to match the Dart version bundled with the
15-
installed Flutter SDK. This ensures that your project's Dart SDK constraint is
16-
always in sync with the Flutter version used in your CI environment.
9+
> [!NOTE] This action currently pins the Dart SDK to the exact version bundled
10+
> with the installed Flutter SDK (for example: `environment: sdk: "3.1.0"`). It
11+
> does not generate or maintain version ranges (for example:
12+
> `">=3.1.0 <4.0.0"`). You can auto commit the changes using the GitHub App
13+
> integration if desired.
1714
1815
## Inputs
1916

20-
| Name | Description | Required | Default |
21-
| ------------------------------- | --------------------------------------------------------------- | -------- | ---------------- |
22-
| `pubspec_path` | Path to the `pubspec.yaml` file. | `true` | `./pubspec.yaml` |
23-
| `fail_if_flutter_not_installed` | Whether to fail the action if the Flutter SDK is not installed. | `false` | `false` |
17+
| Name | Description | Required | Default |
18+
| ------------------------------- | --------------------------------------------------------------------------------------- | --------------------------------------- | ---------------- |
19+
| `pubspec_path` | Path to the `pubspec.yaml` file. | `true` | `./pubspec.yaml` |
20+
| `fail_if_flutter_not_installed` | Whether to fail the action if the Flutter SDK is not installed. | `false` | `false` |
21+
| `commit_changes` | If `true`, attempt to commit the updated `pubspec.yaml` using GitHub App. | `false` | `false` |
22+
| `commit_message` | Commit message to use when committing changes (required if `commit_changes` is `true`). | `📌 Sync Dart SDK version with Flutter` | `` |
23+
| `gh_app_id` | GitHub App ID (required for committing via the GitHub App flow). | `false` | `` |
24+
| `gh_installation_id` | GitHub App installation ID (required for committing via the GitHub App). | `false` | `` |
25+
| `gh_private_key` | GitHub App private key (PEM) used to authenticate the App. | `false` | `` |
2426

2527
## Usage
2628

@@ -48,17 +50,26 @@ jobs:
4850
flutter-version: '3.16.0' # Example version
4951

5052
- name: Sync Dart SDK version with Flutter
51-
uses: IamPekka058/flutter-dart-sync@v1 # Replace with the correct version
53+
uses: IamPekka058/flutter-dart-sync@v1
5254
with:
5355
pubspec_path: './pubspec.yaml'
5456
fail_if_flutter_not_installed: true
5557

5658
# Add subsequent steps like flutter pub get, build, test, etc.
5759
- name: Install Dependencies
5860
run: flutter pub get
61+
```
5962
60-
- name: Run Tests
61-
run: flutter test
63+
```yaml
64+
- name: Sync Dart and commit via GitHub App
65+
uses: IamPekka058/flutter-dart-sync@v1
66+
with:
67+
pubspec_path: './pubspec.yaml'
68+
commit_changes: true
69+
commit_message: 'chore: sync Dart SDK with Flutter'
70+
gh_app_id: ${{ secrets.GH_APP_ID }}
71+
gh_installation_id: ${{ secrets.GH_INSTALLATION_ID }}
72+
gh_private_key: ${{ secrets.GH_PRIVATE_KEY }}
6273
```
6374
6475
## License

__tests__/main.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ jest.unstable_mockModule('@actions/core', () => ({
1616
}))
1717
jest.unstable_mockModule('../src/fileHandler.ts', () => ({
1818
getPubspecDartSdkVersion: jest.fn(),
19-
updatePubspecDartSdkVersion: jest.fn()
19+
updatePubspecDartSdkVersion: jest.fn(),
20+
getPubspecFile: jest.fn()
21+
}))
22+
23+
// Some modules import the file with a .js extension (e.g. './fileHandler.js')
24+
// when running under ESM. Mock that specifier as well so imports are intercepted.
25+
jest.unstable_mockModule('../src/fileHandler.js', () => ({
26+
getPubspecDartSdkVersion: jest.fn(),
27+
updatePubspecDartSdkVersion: jest.fn(),
28+
getPubspecFile: jest.fn()
2029
}))
2130

2231
// Dynamically import the modules after mocks are set up

action.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,29 @@ inputs:
1818
'Whether to fail the action if Flutter is not installed (default: false)'
1919
required: false
2020
default: false
21+
commit_changes:
22+
description:
23+
'Whether to commit the changes to pubspec.yaml (default: false)'
24+
required: false
25+
default: false
26+
commit_message:
27+
description:
28+
'Commit message to use when committing changes (default: "chore: sync Dart
29+
SDK version with Flutter")'
30+
required: false
31+
default: '📌 Sync Dart SDK version with Flutter'
32+
gh_app_id:
33+
description: 'GitHub App ID'
34+
required: false
35+
default: ''
36+
gh_private_key:
37+
description: 'Private key (PEM) of the GitHub App'
38+
required: false
39+
default: ''
40+
gh_installation_id:
41+
description: 'Installation ID of the GitHub App'
42+
required: false
43+
default: ''
2144

2245
runs:
2346
using: node24

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)