-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit c39fc1d
Showing
26 changed files
with
1,209 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Workflow for Managing Pub.dev Packages | ||
|
||
## Workflows | ||
|
||
**This repository contains GitHub Actions workflows that simplify the management of your pub.dev packages:** | ||
|
||
- The `prepare.yaml` workflow triggers on every push to the main branch. It automatically updates the CHANGELOG.md, formats the Dart code, and applies Dart fixes with each push. | ||
- The `publish.yaml` workflow activates upon the creation of a new release, automatically handling the package's publication to pub.dev. | ||
|
||
## Setup Instructions | ||
|
||
**1. Navigate to your project:** | ||
|
||
```zsh | ||
cd your_project | ||
``` | ||
|
||
**2. Clone this repo into a `.github/` folder:** | ||
|
||
```zsh | ||
git clone https://github.com/robmllze/pub.dev_package_workflow.git .github | ||
``` | ||
|
||
**3. Remove the `/.git` folder to include it to your project:** | ||
|
||
*On macOS and Linux:* | ||
```zsh | ||
rm -rf .github/.git/ | ||
``` | ||
|
||
*On Windows:* | ||
```cmd | ||
rmdir /s /q .github/.git/ | ||
``` | ||
|
||
|
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,128 @@ | ||
//.title | ||
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ | ||
// | ||
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. See LICENSE file | ||
// in root directory. | ||
// | ||
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ | ||
//.title~ | ||
|
||
import 'dart:io'; | ||
|
||
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ | ||
|
||
void main(List<String> args) { | ||
final version = args.isNotEmpty ? args[0] : '0.1.0'; | ||
final newReleaseNotes = args.length > 1 ? args[1] : 'Initial commit'; | ||
final changelogPath = 'CHANGELOG.md'; | ||
final file = File(changelogPath); | ||
if (!file.existsSync()) { | ||
print('$changelogPath does not exist.'); | ||
exit(1); | ||
} | ||
var contents = file.readAsStringSync(); | ||
contents = contents.replaceAll('# Changelog', '').trim(); | ||
final sections = extractSections(contents); | ||
final versionExist = sections.where((e) => e.version == version).isNotEmpty; | ||
if (versionExist) { | ||
sections.where((e) => e.version == version).forEach((e) { | ||
e.addUpdate(newReleaseNotes); | ||
}); | ||
} else { | ||
sections.add( | ||
_VersionSection( | ||
version: version, | ||
releasedAt: DateTime.now().toUtc(), | ||
updates: {newReleaseNotes}, | ||
), | ||
); | ||
} | ||
contents = '# Changelog\n\n${(sections.toList()..sort((a, b) { | ||
return b.version.compareTo(a.version); | ||
})).map((e) => e.toString()).join('\n')}'; | ||
|
||
file.writeAsStringSync(contents); | ||
print('Changelog updated with version $version.'); | ||
} | ||
|
||
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ | ||
|
||
Set<_VersionSection> extractSections(String contents) { | ||
final headerPattern = RegExp(r'## \[\d+\.\d+\.\d+(\+\d+)?\]'); | ||
final allVersionMatches = headerPattern.allMatches(contents).toList(); | ||
final results = <_VersionSection>{}; | ||
for (var i = 0; i < allVersionMatches.length; i++) { | ||
final start = allVersionMatches[i].end; | ||
final end = i + 1 < allVersionMatches.length ? allVersionMatches[i + 1].start : contents.length; | ||
final sectionContents = contents.substring(start, end).trim(); | ||
final lines = sectionContents.split('\n').where((line) => line.isNotEmpty).toList(); | ||
final version = | ||
allVersionMatches[i].group(0)!.substring(4, allVersionMatches[i].group(0)!.length - 1); | ||
var releasedAt = DateTime.now().toUtc(); | ||
final updates = <String>{}; | ||
final old = lines | ||
.map((e) => e.trim()) | ||
.where((e) => e.isNotEmpty) | ||
.map((e) => e.startsWith('-') ? e.substring(1) : e) | ||
.map((e) => e.trim()) | ||
.where((e) => e.isNotEmpty); | ||
for (var line in old) { | ||
if (line.contains('Released @')) { | ||
final temp = line.split('Released @').last.trim(); | ||
releasedAt = DateTime.tryParse(temp) ?? releasedAt; | ||
} else { | ||
updates.add(line); | ||
} | ||
} | ||
results.add( | ||
_VersionSection( | ||
version: version, | ||
releasedAt: releasedAt, | ||
updates: updates, | ||
), | ||
); | ||
} | ||
|
||
return results; | ||
} | ||
|
||
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ | ||
|
||
class _VersionSection { | ||
// | ||
// | ||
// | ||
|
||
String version; | ||
DateTime releasedAt; | ||
Set<String> updates; | ||
|
||
// | ||
// | ||
// | ||
|
||
_VersionSection({ | ||
required this.version, | ||
required this.releasedAt, | ||
this.updates = const {}, | ||
}); | ||
|
||
// | ||
// | ||
// | ||
|
||
void addUpdate(String update) { | ||
this.updates.add(update); | ||
this.releasedAt = DateTime.now().toUtc(); | ||
} | ||
|
||
// | ||
// | ||
// | ||
|
||
@override | ||
String toString() { | ||
final updatesString = updates.map((update) => '- $update').join('\n'); | ||
return '## [$version]\n\n- Released @ ${releasedAt.month}/${releasedAt.year} (UTC)\n$updatesString\n'; | ||
} | ||
} |
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,63 @@ | ||
##.title | ||
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ | ||
## | ||
## Dart/Flutter (DF) Packages by DevCetra.com & contributors. ee LICENSE file | ||
## in root directory. | ||
## | ||
## For more about publishing, see: https://dart.dev/tools/pub/automated-publishing | ||
## | ||
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ | ||
##.title~ | ||
|
||
name: Prepare version | ||
|
||
## ----------------------------------------------------------------------------- | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
## ----------------------------------------------------------------------------- | ||
|
||
jobs: | ||
prepare: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Dart | ||
uses: dart-lang/setup-dart@v1.2 | ||
|
||
- name: Format Dart code | ||
run: dart format . | ||
|
||
- name: Apply Dart fixes | ||
run: dart fix --apply | ||
|
||
- name: Extract version from pubspec.yaml | ||
id: get_version | ||
run: | | ||
VERSION=$(grep "version:" pubspec.yaml | sed 's/version: //') | ||
echo "Extracted version: $VERSION" | ||
echo "::set-output name=extracted_version::$VERSION" | ||
- name: Get commit messages | ||
id: get_commits | ||
run: | | ||
COMMIT_MESSAGES=$(git log --format=%B -n 1 HEAD) | ||
echo "::set-output name=messages::${COMMIT_MESSAGES}" | ||
- name: Update CHANGELOG.md | ||
run: | | ||
RELEASE_NOTES="${{ steps.get_commits.outputs.messages }}" | ||
dart run .github/scripts/update_changelog.dart "${{ steps.get_version.outputs.extracted_version }}" "$RELEASE_NOTES" | ||
- name: Commit and push changes | ||
run: | | ||
git config user.name github-actions | ||
git config user.email github-actions@github.com | ||
git add . | ||
git commit -m "Prepare version ${{ steps.get_version.outputs.extracted_version }}" | ||
git push |
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,28 @@ | ||
##.title | ||
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ | ||
## | ||
## Dart/Flutter (DF) Packages by DevCetra.com & contributors. See MIT LICENSE | ||
## file in root directory. | ||
## | ||
## A workflow that publishes a Dart package to pub.dev. For more about | ||
## publishing, see: https://dart.dev/tools/pub/automated-publishing | ||
## | ||
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ | ||
##.title~ | ||
|
||
name: Publish to pub.dev | ||
|
||
## ----------------------------------------------------------------------------- | ||
|
||
on: | ||
push: | ||
tags: | ||
- "v[0-9]+.[0-9]+.[0-9]+*" | ||
|
||
## ----------------------------------------------------------------------------- | ||
|
||
jobs: | ||
publish: | ||
permissions: | ||
id-token: write # Required for authentication using OIDC | ||
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1 |
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,15 @@ | ||
##.title | ||
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ | ||
## | ||
## Dart/Flutter (DF) Packages by DevCetra.com & contributors. See LICENSE file | ||
## in root directory. | ||
## | ||
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ | ||
##.title~ | ||
|
||
**/___generators/ | ||
**/.dart_tool/ | ||
**/.DS_Store | ||
**/build/ | ||
**/pubspec.lock | ||
**/.github/.git |
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,15 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "▶️ Refetch workflow", | ||
"type": "shell", | ||
"command": "rm -rf .github && git clone https://github.com/robmllze/pub.dev_package_workflow.git .github && rm -rf .github/.git/" | ||
}, | ||
{ | ||
"label": "▶️ Publish to pub.dev", | ||
"type": "shell", | ||
"command": "dart pub publish" | ||
}, | ||
] | ||
} |
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,6 @@ | ||
# Changelog | ||
|
||
## [0.1.0] | ||
|
||
- Released @ 8/2024 (UTC) | ||
- Initial release |
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,89 @@ | ||
# Developer Notes | ||
|
||
## Commmit Tag Descriptions | ||
|
||
- `feat`: New feature or enhancement | ||
- `fix`: Bug fix or issue resolution | ||
- `chore`: Routine tasks or maintenance | ||
- `refactor`: Code improvements (no functionality change) | ||
- `docs`: Documentation updates | ||
- `style`: Code style or formatting changes | ||
- `test`: Tests additions or modifications | ||
- `build`: Build system or external dependencies changes | ||
- `perf`: Performance improvements | ||
- `ci`: Continuous integration configuration changes | ||
- `revert`: Revert a previous commit | ||
- `security`: Security-related changes or fixes | ||
- `release`: Marks a release or version update | ||
|
||
## Enabling GitHub Workflow | ||
|
||
https://github.com/robmllze/YOUR_PROJECT_NAME/settings/actions | ||
|
||
## Public Repo Setup | ||
|
||
```sh | ||
brew install gh | ||
gh auth login | ||
git init | ||
git add . | ||
git commit -m "Initial commit" | ||
gh repo create YOUR_PROJECT_NAME --public | ||
git remote add origin https://github.com/robmllze/YOUR_PROJECT_NAME.git | ||
git push -u origin main | ||
``` | ||
|
||
## Publishing | ||
|
||
1. Make your changes. | ||
1. Run `dart analyze` to check for errors. | ||
1. Run `dart fix --apply` to apply fixes. | ||
1. Run `dart format .` to format the code. | ||
1. Update the version number in `pubspec.yaml`. | ||
1. Update the version number in `CHANGELOG.md`. | ||
1. Run `dart pub publish --dry-run` to check for errors. | ||
1. Run `dart pub publish` to publish the package. | ||
|
||
## macOS and Linux | ||
|
||
### Fetching Generators | ||
|
||
```bash | ||
rm -rf ___generators/ | ||
git clone https://github.com/robmllze/___generators.git | ||
dart pub get -C ___generators | ||
``` | ||
|
||
### Adding the Workflow | ||
|
||
```bash | ||
rm -rf .github/ | ||
git clone https://github.com/robmllze/pub.dev_package_workflow.git .github | ||
rm -rf .github/.git | ||
``` | ||
|
||
### Deleting .DS_Store files | ||
|
||
```bash | ||
cd your/project/path | ||
find . -name '.DS_Store' -type f -delete | ||
``` | ||
|
||
## Windows | ||
|
||
### Fetching Generators | ||
|
||
```bash | ||
rmdir /s /q ___generators/ | ||
git clone https://github.com/robmllze/___generators.git | ||
dart pub get -C ___generators | ||
rmdir /s /q ___generators/.git | ||
``` | ||
|
||
### Adding the Workflow | ||
|
||
```bash | ||
rmdir /s /q .github/ | ||
git clone https://github.com/robmllze/pub.dev_package_workflow.git .github | ||
rmdir /s /q .github/.git | ||
``` |
Oops, something went wrong.