Skip to content

Commit 81bef28

Browse files
committed
update
1 parent 9014bf9 commit 81bef28

File tree

7 files changed

+187
-50
lines changed

7 files changed

+187
-50
lines changed

.github/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/.DS_Store

.github/_README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ cd your_project
1818
**2. Clone this repo into a `.github/` folder:**
1919

2020
```zsh
21-
git clone https://github.com/robmllze/pub.dev_package_workflow.git .github
21+
git clone https://github.com/dev-cetera/pub.dev_package_workflow.git .github
2222
```
2323

2424
**3. Remove the `/.git` folder to include it to your project:**
25-
26-
*On macOS and Linux:*
25+
26+
_On macOS and Linux:_
27+
2728
```zsh
2829
rm -rf .github/.git/
2930
```
3031

31-
*On Windows:*
32+
_On Windows:_
33+
3234
```cmd
3335
rmdir /s /q .github/.git/
3436
```
35-
36-

.github/scripts/update_changelog.dart

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'dart:io';
1616

1717
void main(List<String> args) {
1818
final version = args.isNotEmpty ? args[0] : '0.1.0';
19-
final newReleaseNotes = args.length > 1 ? args[1] : 'Initial commit';
19+
final comitMesssage = args.length > 1 ? args[1].replaceFirst('+', '') : '';
2020
final changelogPath = 'CHANGELOG.md';
2121
final file = File(changelogPath);
2222
if (!file.existsSync()) {
@@ -29,19 +29,19 @@ void main(List<String> args) {
2929
final versionExist = sections.where((e) => e.version == version).isNotEmpty;
3030
if (versionExist) {
3131
sections.where((e) => e.version == version).forEach((e) {
32-
e.addUpdate(newReleaseNotes);
32+
e.addUpdate(comitMesssage);
3333
});
3434
} else {
3535
sections.add(
3636
_VersionSection(
3737
version: version,
3838
releasedAt: DateTime.now().toUtc(),
39-
updates: {newReleaseNotes},
39+
updates: {comitMesssage},
4040
),
4141
);
4242
}
4343
contents = '# Changelog\n\n${(sections.toList()..sort((a, b) {
44-
return b.releasedAt.compareTo(a.releasedAt);
44+
return compareVersions(b.version, a.version);
4545
})).map((e) => e.toString()).join('\n')}';
4646

4747
file.writeAsStringSync(contents);
@@ -71,19 +71,16 @@ Set<_VersionSection> extractSections(String contents) {
7171
.where((e) => e.isNotEmpty);
7272
for (var line in old) {
7373
if (line.contains('Released @')) {
74-
final temp = line.split('Released @').last.trim();
75-
releasedAt = DateTime.tryParse(temp) ?? releasedAt;
74+
releasedAt = parseReleaseDate(line);
7675
} else {
7776
updates.add(line);
7877
}
7978
}
80-
results.add(
81-
_VersionSection(
82-
version: version,
83-
releasedAt: releasedAt,
84-
updates: updates,
85-
),
86-
);
79+
results.add(_VersionSection(
80+
version: version,
81+
releasedAt: releasedAt,
82+
updates: updates,
83+
));
8784
}
8885

8986
return results;
@@ -107,16 +104,16 @@ class _VersionSection {
107104
_VersionSection({
108105
required this.version,
109106
required this.releasedAt,
110-
this.updates = const {},
111-
});
107+
Set<String>? updates,
108+
}) : this.updates = updates ?? {};
112109

113110
//
114111
//
115112
//
116113

117114
void addUpdate(String update) {
118-
this.updates.add(update);
119-
this.releasedAt = DateTime.now().toUtc();
115+
updates.add(update);
116+
releasedAt = DateTime.now().toUtc();
120117
}
121118

122119
//
@@ -129,3 +126,45 @@ class _VersionSection {
129126
return '## [$version]\n\n- Released @ ${releasedAt.month}/${releasedAt.year} (UTC)\n$updatesString\n';
130127
}
131128
}
129+
130+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
131+
132+
int compareVersions(String version1, String version2) {
133+
List<int> parseVersion(String version) {
134+
// Split by the '+' first to handle the build number
135+
final parts = version.split('+');
136+
final versionParts = parts[0].split('.').map(int.tryParse).map((e) => e ?? 0).toList();
137+
// Add the build number as the last part (if it exists)
138+
if (parts.length > 1) {
139+
versionParts.add(int.tryParse(parts[1]) ?? 0);
140+
}
141+
return versionParts;
142+
}
143+
144+
final v1 = parseVersion(version1);
145+
final v2 = parseVersion(version2);
146+
final maxLength = v1.length > v2.length ? v1.length : v2.length;
147+
for (var i = 0; i < maxLength; i++) {
148+
final part1 = i < v1.length ? v1[i] : 0;
149+
final part2 = i < v2.length ? v2[i] : 0;
150+
if (part1 > part2) return 1;
151+
if (part1 < part2) return -1;
152+
}
153+
return 0;
154+
}
155+
156+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
157+
158+
DateTime parseReleaseDate(String line) {
159+
if (line.contains('Released @')) {
160+
final temp = line.split('Released @').last.trim().replaceAll(' (UTC)', '');
161+
final parts = temp.split('/');
162+
if (parts.length == 2) {
163+
final month = int.tryParse(parts[0]) ?? 1;
164+
final year = int.tryParse(parts[1]) ?? DateTime.now().year;
165+
return DateTime.utc(year, month);
166+
}
167+
}
168+
169+
return DateTime.now().toUtc();
170+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
##.title
2+
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
3+
##
4+
## Dart/Flutter (DF) Packages by dev-cetera.com & contributors. The use of this
5+
## source code is governed by an MIT-style license described in the LICENSE
6+
## file located in this project's root directory.
7+
##
8+
## See: https://opensource.org/license/mit
9+
##
10+
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
11+
##.title~
12+
13+
name: Deploy hosted_example to GitHub Pages
14+
15+
## -----------------------------------------------------------------------------
16+
17+
on:
18+
push:
19+
branches:
20+
- main
21+
22+
## -----------------------------------------------------------------------------
23+
24+
jobs:
25+
build-and-deploy:
26+
runs-on: ubuntu-latest
27+
steps:
28+
# Checkout the code from the repository
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
32+
# Set up Flutter
33+
- name: Set up Flutter
34+
uses: subosito/flutter-action@v2
35+
with:
36+
channel: "stable"
37+
flutter-version: "3.x"
38+
39+
# Install all project dependencies
40+
- name: Install dependencies
41+
run: flutter pub get
42+
working-directory: ./hosted_example
43+
44+
# Enable Flutter web support
45+
- name: Enable Flutter web support
46+
run: flutter config --enable-web
47+
working-directory: ./hosted_example
48+
49+
# Build the web app in /hosted_example/
50+
- name: Build web app in /hosted_example/
51+
run: flutter build web --release --base-href "/${{ github.event.repository.name }}/"
52+
working-directory: ./hosted_example
53+
54+
# Necessary
55+
- name: Create .nojekyll
56+
run: touch hosted_example/build/web/.nojekyll
57+
58+
# Necessary
59+
- name: Create 404.html for SPA routing
60+
run: cp hosted_example/build/web/index.html hosted_example/build/web/404.html
61+
62+
# Deploy the app to GitHub Pages
63+
- name: Deploy to GitHub Pages
64+
uses: peaceiris/actions-gh-pages@v4
65+
with:
66+
github_token: ${{ secrets.GITHUB_TOKEN }}
67+
publish_dir: ./hosted_example/build/web
68+
keep_files: false

.github/workflows/prepare.yml

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
##.title
22
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
33
##
4-
## Dart/Flutter (DF) Packages by dev-cetera.com & contributors.
4+
## Dart/Flutter (DF) Packages by dev-cetera.com & contributors. The use of this
5+
## source code is governed by an MIT-style license described in the LICENSE
6+
## file located in this project's root directory.
57
##
6-
## See MIT LICENSE file in the root directory.
7-
##
8-
## For more about publishing, see: https://dart.dev/tools/pub/automated-publishing
8+
## See: https://opensource.org/license/mit
99
##
1010
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
1111
##.title~
1212

13-
name: Prepare for release
13+
name: Prepare version
1414

1515
## -----------------------------------------------------------------------------
1616

@@ -22,44 +22,73 @@ on:
2222
## -----------------------------------------------------------------------------
2323

2424
jobs:
25-
update-changelog:
25+
prepare:
2626
runs-on: ubuntu-latest
2727
steps:
28+
# Checkout the code from the repository
2829
- name: Checkout code
2930
uses: actions/checkout@v3
3031

32+
# Get the latest commit message
33+
- name: Get commit messages
34+
id: get_commits
35+
run: |
36+
COMMIT_MESSAGES=$(git log --format=%B -n 1 HEAD)
37+
echo "::set-output name=COMMIT_MESSAGES::${COMMIT_MESSAGES}"
38+
39+
# Check if the commit message starts with '+'
40+
- name: Check commit message
41+
id: check_message
42+
run: |
43+
if echo "${{ steps.get_commits.outputs.COMMIT_MESSAGES }}" | grep -q "^+"; then
44+
echo "::set-output name=PROCEED::true"
45+
else
46+
echo "::set-output name=PROCEED::false"
47+
fi
48+
49+
# Debug environment variables
50+
- name: Debug environment variables
51+
run: |
52+
echo "PROCEED=${{ steps.check_message.outputs.PROCEED }}"
53+
echo "COMMIT_MESSAGES=${{ steps.get_commits.outputs.COMMIT_MESSAGES }}"
54+
55+
# Set up Dart if the commit message check passed
3156
- name: Set up Dart
57+
if: ${{ steps.check_message.outputs.PROCEED == 'true' }}
3258
uses: dart-lang/setup-dart@v1.2
3359

60+
# Format Dart code if the commit message check passed
3461
- name: Format Dart code
62+
if: ${{ steps.check_message.outputs.PROCEED == 'true' }}
3563
run: dart format .
3664

65+
# Apply Dart fixes if the commit message check passed
3766
- name: Apply Dart fixes
67+
if: ${{ steps.check_message.outputs.PROCEED == 'true' }}
3868
run: dart fix --apply
3969

70+
# Extract the version from pubspec.yaml if the commit message check passed
4071
- name: Extract version from pubspec.yaml
72+
if: ${{ steps.check_message.outputs.PROCEED == 'true' }}
4173
id: get_version
4274
run: |
4375
VERSION=$(grep "version:" pubspec.yaml | sed 's/version: //')
44-
echo "Extracted version: $VERSION"
45-
echo "::set-output name=extracted_version::$VERSION"
46-
47-
- name: Get commit messages
48-
id: get_commits
49-
run: |
50-
COMMIT_MESSAGES=$(git log --format=%B -n 1 HEAD)
51-
echo "::set-output name=messages::${COMMIT_MESSAGES}"
76+
echo "Version extracted from pubspec.yaml: $VERSION"
77+
echo "::set-output name=PUBSPEC_VERSION::${VERSION}"
5278
79+
# Update CHANGELOG.md if the commit message check passed
5380
- name: Update CHANGELOG.md
81+
if: ${{ steps.check_message.outputs.PROCEED == 'true' }}
5482
run: |
55-
RELEASE_NOTES="${{ steps.get_commits.outputs.messages }}"
56-
dart run .github/scripts/update_changelog.dart "${{ steps.get_version.outputs.extracted_version }}" "$RELEASE_NOTES"
57-
shell: bash
83+
RELEASE_NOTES="${{ steps.get_commits.outputs.COMMIT_MESSAGES }}"
84+
dart run .github/scripts/update_changelog.dart "${{ steps.get_version.outputs.PUBSPEC_VERSION }}" "$RELEASE_NOTES"
5885
86+
# Commit and push changes if the commit message check passed
5987
- name: Commit and push changes
88+
if: ${{ steps.check_message.outputs.PROCEED == 'true' }}
6089
run: |
6190
git config user.name github-actions
6291
git config user.email github-actions@github.com
6392
git add .
64-
git commit -m "Prepare release for version ${{ steps.get_version.outputs.extracted_version }}"
65-
git push
93+
git commit -m "Prepare version ${{ steps.get_version.outputs.PUBSPEC_VERSION }}"
94+
git push

.github/workflows/publish.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
##.title
22
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
33
##
4-
## Dart/Flutter (DF) Packages by dev-cetera.com & contributors. See MIT LICENSE
5-
## file in the root directory.
4+
## Dart/Flutter (DF) Packages by dev-cetera.com & contributors. The use of this
5+
## source code is governed by an MIT-style license described in the LICENSE
6+
## file located in this project's root directory.
67
##
7-
## A workflow that publishes a Dart package to pub.dev. For more about
8-
## publishing, see: https://dart.dev/tools/pub/automated-publishing
8+
## See: https://opensource.org/license/mit
99
##
1010
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
1111
##.title~
@@ -24,5 +24,5 @@ on:
2424
jobs:
2525
publish:
2626
permissions:
27-
id-token: write # Required for authentication using OIDC
28-
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
27+
id-token: write
28+
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
name: df_gen_core
1414
description: A package that provides core utilities for practical code generation.
15-
version: 0.6.10
15+
version: 0.6.11
1616
homepage: https://dev-cetera.com/
1717
repository: https://github.com/robmllze/df_gen_core
1818
funding:
@@ -29,7 +29,7 @@ dependencies:
2929
df_collection: ^0.9.2
3030
df_config: ^0.7.2
3131
df_log: ^0.3.11
32-
df_safer_dart: ^0.13.14
32+
df_safer_dart: ^0.14.10
3333
df_string: ^0.2.4
3434
df_type: ^0.12.3
3535
analyzer: ^6.11.0

0 commit comments

Comments
 (0)