Skip to content

Commit 6eff774

Browse files
committed
update
1 parent ef105e1 commit 6eff774

12 files changed

+310
-169
lines changed

.github/_README.md

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,72 @@
1-
# Workflow for Managing Pub.dev Packages
1+
# pub.dev_package_workflow
2+
3+
This repository provides a powerful and streamlined set of GitHub Actions workflows designed to automate the entire lifecycle of your Dart and Flutter packages—from version bumping and changelog generation to publishing on pub.dev and deploying examples to GitHub Pages.
4+
5+
---
6+
7+
## 🚀 Core Features
8+
9+
- **Automated Version Bumping:** Automatically update `CHANGELOG.md`, `README.md`, and other files when you're ready to release.
10+
- **Git Tagging:** Automatically create and push Git tags for new versions.
11+
- **Flexible Publishing Triggers:** Publish packages automatically via special commit messages or by creating a release in the GitHub UI.
12+
- **Example App Deployment:** An optional workflow to build and deploy a Flutter web example to GitHub Pages.
213

314
## Workflows
415

5-
**This repository contains GitHub Actions workflows that simplify the management of your pub.dev packages:**
16+
This project contains three key GitHub Actions workflows.
17+
18+
### 1. `process-package.yml`
19+
20+
This is the primary workflow for managing releases directly from your commit messages. It triggers on every push to your `main` branch.
21+
22+
- **Standard Commits:** For any normal commit message, the workflow does nothing.
23+
- **Prepare a Release (`+`):** If your commit message starts with a single plus sign (e.g., `+Added new feature`), the workflow will:
24+
- Run `dart format` and `dart fix --apply`.
25+
- Update your `CHANGELOG.md` with the commit message.
26+
- Generate a standardized `README.md` from a central template.
27+
- Commit these automated changes with the message `ci: bump version to v[version]`.
28+
- Create and push a Git tag for the new version.
29+
- **Prepare and Publish (`++`):** If your commit message starts with two plus signs (e.g., `++Major performance improvements`), the workflow will do **everything above** and then automatically **publish the package to pub.dev** if properly configured. See https://dart.dev/tools/pub/automated-publishing.
30+
31+
### 2. `publish.yml`
32+
33+
This workflow provides a manual trigger for publishing. It activates **only** when you create a new release in the GitHub UI. This is perfect for when you want to review changes on the `main` branch before deciding to publish.
634

7-
- 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.
8-
- The `publish.yaml` workflow activates upon the creation of a new release, automatically handling the package's publication to pub.dev.
35+
### 3. `deploy-example.yml` (Optional)
936

10-
## Setup Instructions
37+
If your project contains a Flutter web example in a `hosted_example` directory, this workflow will automatically build it and deploy it to GitHub Pages on every push to the `main` branch. This is great for providing live demos of your package.
1138

12-
**1. Navigate to your project:**
39+
---
40+
41+
## 🛠️ Setup Instructions
42+
43+
Setting up these workflows in your own package repository is simple.
44+
45+
**1. Navigate to Your Project's Root Directory**
46+
47+
Open your terminal and `cd` into the root of your Dart or Flutter package.
1348

1449
```zsh
15-
cd your_project
50+
cd /path/to/your_project
1651
```
1752

18-
**2. Clone this repo into a `.github/` folder:**
53+
**2. Clone this Workflow Repository**
54+
55+
Clone this repository directly into a `.github` folder. This will create `.github/workflows` and `.github/scripts` for you.
1956

2057
```zsh
2158
git clone https://github.com/dev-cetera/pub.dev_package_workflow.git .github
2259
```
2360

24-
**3. Remove the `/.git` folder to include it to your project:**
61+
**3. Remove the Nested `.git` Directory**
2562

26-
_On macOS and Linux:_
63+
To make these workflow files part of your own project's Git history, you must delete the nested `.git` directory that was just cloned.
2764

28-
```zsh
29-
rm -rf .github/.git/
30-
```
65+
**4. Configure `pub.dev` for Automated Publishing**
3166

32-
_On Windows:_
67+
For the `publish.yml` workflow to work, you must authorize GitHub Actions on `pub.dev`.
3368

34-
```cmd
35-
rmdir /s /q .github/.git/
36-
```
69+
- Go to your package's page on `pub.dev` and click the **Admin** tab.
70+
- Under **Automated publishing**, click **Enable publishing from GitHub Actions**.
71+
- Set the **Repository** to your `username/repository_name`.
72+
- Set the **Tag pattern** to `v{{version}}`.

.github/scripts/update_changelog.dart

Lines changed: 1 addition & 1 deletion
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 comitMesssage = args.length > 1 ? args[1].replaceFirst('+', '') : '';
19+
final comitMesssage = args.length > 1 ? args[1].replaceFirst(RegExp(r'^\++'), '') : '';
2020
final changelogPath = 'CHANGELOG.md';
2121
final file = File(changelogPath);
2222
if (!file.existsSync()) {

.github/scripts/update_readme.dart

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
import 'dart:io';
14+
15+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
16+
17+
void main(List<String> args) {
18+
if (args.length < 3) {
19+
print('Usage: dart run update_readme.dart <template_path> <package_name> <package_version>');
20+
exit(1);
21+
}
22+
23+
final templatePath = args[0];
24+
final packageName = args[1];
25+
final packageVersion = args[2];
26+
27+
// These paths are relative to where the script is run (the project root).
28+
final localContentPath = '_README_CONTENT.md';
29+
final finalReadmePath = 'README.md';
30+
31+
// --- 1. Load the master template file from the path provided by the CI ---
32+
final templateFile = File(templatePath);
33+
if (!templateFile.existsSync()) {
34+
print('ERROR: Master README template not found at $templatePath');
35+
exit(1);
36+
}
37+
final readmeTemplate = templateFile.readAsStringSync();
38+
39+
// --- 2. Load the local content file ---
40+
final localContentFile = File(localContentPath);
41+
if (!localContentFile.existsSync()) {
42+
print('INFO: No _README_CONTENT.md found for $packageName. Cannot generate README.');
43+
// Exit gracefully if there's no content to inject for this package.
44+
exit(0);
45+
}
46+
final localReadmeContent = localContentFile.readAsStringSync();
47+
48+
// --- 3. Perform all replacements ---
49+
var finalContent = readmeTemplate.replaceAll('{{{PACKAGE}}}', packageName);
50+
finalContent = finalContent.replaceAll('{{{VERSION}}}', packageVersion);
51+
finalContent = finalContent.replaceAll('{{{_README_CONTENT}}}', localReadmeContent);
52+
53+
// --- 4. Write the new README.md file ---
54+
final finalReadmeFile = File(finalReadmePath);
55+
finalReadmeFile.writeAsStringSync(finalContent);
56+
57+
print('SUCCESS: README.md for $packageName v$packageVersion has been updated.');
58+
}

.github/workflows/deploy.yml_REMOVE_TO_ENABLE renamed to .github/workflows/deploy-examplet.yml_REMOVE_TO_ENABLE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
1111
##.title~
1212

13-
name: Deploy hosted_example to GitHub Pages
13+
name: Deploy Example on Commit
1414

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

.github/workflows/prepare.yml

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)