Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
robmllze committed Aug 3, 2024
0 parents commit d45227d
Show file tree
Hide file tree
Showing 35 changed files with 1,691 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/_README.md
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/
```


128 changes: 128 additions & 0 deletions .github/scripts/update_changelog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//.title
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. SSee MIT LICENSE
// file in the 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.releasedAt.compareTo(a.releasedAt);
})).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';
}
}
65 changes: 65 additions & 0 deletions .github/workflows/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
##.title
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
##
## Dart/Flutter (DF) Packages by DevCetra.com & contributors.
##
## SSee MIT LICENSE file in the root directory.
##
## For more about publishing, see: https://dart.dev/tools/pub/automated-publishing
##
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
##.title~

name: Prepare for release

## -----------------------------------------------------------------------------

on:
push:
branches:
- main

## -----------------------------------------------------------------------------

jobs:
update-changelog:
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"
shell: bash

- 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 release for version ${{ steps.get_version.outputs.extracted_version }}"
git push
28 changes: 28 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
##.title
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
##
## Dart/Flutter (DF) Packages by DevCetra.com & contributors. SSee MIT LICENSE
## file in the 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
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
##.title
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
##
## Dart/Flutter (DF) Packages by DevCetra.com & contributors. See MIT LICENSE
## file in the root directory.
##
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
##.title~

**/___generators/
**/.dart_tool/
**/.DS_Store
**/build/
**/pubspec.lock
**/.github/.git
15 changes: 15 additions & 0 deletions .vscode/tasks.json
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"
},
]
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
##
89 changes: 89 additions & 0 deletions DEVELOPER_NOTES.md
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
```
Loading

0 comments on commit d45227d

Please sign in to comment.