Skip to content

Commit 9fce5d3

Browse files
Jochum van der Ploegrenancaraujoscarletteliza
authored
feat: add publish scripts (#111)
* feat: add publish scripts * feat: add publish scripts * Update README.md Co-authored-by: Scarlett Eliza <[email protected]> * Update README.md Co-authored-by: Scarlett Eliza <[email protected]> * Update README.md Co-authored-by: Scarlett Eliza <[email protected]> * feat: add publish scripts * feat: add publish scripts --------- Co-authored-by: Renan <[email protected]> Co-authored-by: Scarlett Eliza <[email protected]>
1 parent 462b9d2 commit 9fce5d3

File tree

4 files changed

+244
-1
lines changed

4 files changed

+244
-1
lines changed

.github/cspell.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
}
1616
],
1717
"useGitignore": true,
18-
"words": ["endtemplate"]
18+
"words": ["endtemplate", "APPDATA"]
1919
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Dart Pub Publish Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
dart_sdk:
7+
required: false
8+
type: string
9+
default: "stable"
10+
working_directory:
11+
required: false
12+
type: string
13+
default: "."
14+
runs_on:
15+
required: false
16+
type: string
17+
default: "ubuntu-latest"
18+
pub_credentials:
19+
required: true
20+
type: string
21+
22+
jobs:
23+
publish:
24+
defaults:
25+
run:
26+
working-directory: ${{inputs.working_directory}}
27+
28+
runs-on: ${{inputs.runs_on}}
29+
30+
steps:
31+
- name: 📚 Git Checkout
32+
uses: actions/checkout@v3
33+
34+
- name: 🎯 Setup Dart
35+
uses: dart-lang/setup-dart@v1
36+
with:
37+
sdk: ${{inputs.dart_sdk}}
38+
39+
- name: 📦 Install Dependencies
40+
run: dart pub get
41+
42+
- name: 🔐 Setup Pub Credentials
43+
run: |
44+
mkdir -p $XDG_CONFIG_HOME/dart
45+
echo '${{inputs.pub_credentials}}' > "$XDG_CONFIG_HOME/dart/pub-credentials.json"
46+
47+
- name: 🌵 Dry Run
48+
run: dart pub publish --dry-run
49+
50+
- name: 📢 Publish
51+
run: dart pub publish -f
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Dart Pub Publish Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
flutter_channel:
7+
required: false
8+
type: string
9+
default: "stable"
10+
flutter_version:
11+
required: false
12+
type: string
13+
default: ""
14+
working_directory:
15+
required: false
16+
type: string
17+
default: "."
18+
runs_on:
19+
required: false
20+
type: string
21+
default: "ubuntu-latest"
22+
pub_credentials:
23+
required: true
24+
type: string
25+
26+
jobs:
27+
publish:
28+
defaults:
29+
run:
30+
working-directory: ${{inputs.working_directory}}
31+
32+
runs-on: ${{inputs.runs_on}}
33+
34+
steps:
35+
- name: 📚 Git Checkout
36+
uses: actions/checkout@v3
37+
38+
- name: 🐦 Setup Flutter
39+
uses: subosito/flutter-action@v2
40+
with:
41+
flutter-version: ${{inputs.flutter_version}}
42+
channel: ${{inputs.flutter_channel}}
43+
cache: true
44+
45+
- name: 📦 Install Dependencies
46+
run: flutter pub get
47+
48+
- name: 🔐 Setup Pub Credentials
49+
run: |
50+
mkdir -p $XDG_CONFIG_HOME/dart
51+
echo '${{inputs.pub_credentials}}' > "$XDG_CONFIG_HOME/dart/pub-credentials.json"
52+
53+
- name: 🌵 Dry Run
54+
run: flutter pub publish --dry-run
55+
56+
- name: 📢 Publish
57+
run: flutter pub publish -f

README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/pana.yml@v1
3131

3232
# A reusable workflow for running a spell check
3333
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/spell_check.yml@v1
34+
35+
# A reusable workflow for publishing flutter packages
36+
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_pub_publish.yml@v1
37+
38+
# A reusable workflow for publishing dart packages
39+
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_pub_publish.yml@v1
3440
```
3541
3642
For a more detailed guide, including tips and tricks, check out [our blog][very_good_workflows_blog_link].
@@ -386,6 +392,134 @@ jobs:
386392
working_directory: examples/my_project
387393
```
388394

395+
## Flutter Pub Publish Workflow
396+
397+
### Steps
398+
399+
The Flutter Pub Publish workflow consists of the following steps:
400+
401+
1. Install dependencies
402+
2. Setup pub credentials
403+
3. Dry run
404+
4. Publish
405+
406+
### Inputs
407+
408+
#### `flutter_channel`
409+
410+
**Optional** The Flutter release channel to use (e.g. `stable`).
411+
412+
**Default** `"stable"`
413+
414+
#### `flutter_version`
415+
416+
**Optional** The Flutter SDK version to use (e.g. `2.8.1`).
417+
418+
**Default** `""`
419+
420+
#### `working_directory`
421+
422+
**Optional** The path to the root of the Flutter package.
423+
424+
**Default** `"."`
425+
426+
#### `runs_on`
427+
428+
**Optional** An optional operating system on which to run the workflow.
429+
430+
**Default** `"ubuntu-latest"`
431+
432+
#### `pub_credentials`
433+
434+
**Required** The pub credentials needed for publishing. This can be retrieved by reading out your `pub-credentials.json` on your system after you ran a `flutter pub login`. The location of the file is different per operating system:
435+
436+
| OS | Path |
437+
| ------- | ----------------------------------------------------------------------------------------- |
438+
| Linux | `$XDG_CONFIG_HOME/dart/pub-credentials.json` or `$HOME/.config/dart/pub-credentials.json` |
439+
| macOS | `~/Library/Application\ Support/dart/pub-credentials.json` |
440+
| Windows | `%APPDATA%/dart/pub-credentials.json` |
441+
442+
### Example Usage
443+
444+
We recommend using [GitHub Secrets][github_actions_secrets_docs] for safely storing and reading the credentials.
445+
446+
```yaml
447+
name: My Flutter Pub Publish Workflow
448+
449+
on:
450+
push:
451+
tags:
452+
- 'my_flutter_package-v*.*.*'
453+
454+
jobs:
455+
build:
456+
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_pub_publish.yml@v1
457+
with:
458+
flutter_channel: "stable"
459+
flutter_version: "2.8.1"
460+
working_directory: "packages/my_flutter_package"
461+
pub_credentials: ${{ secrets.PUB_CREDENTIALS }}
462+
```
463+
464+
## Dart Pub Publish Workflow
465+
466+
### Steps
467+
468+
The Dart Pub Publish workflow consists of the following steps:
469+
470+
1. Install dependencies
471+
2. Setup pub credentials
472+
3. Dry run
473+
4. Publish
474+
475+
### Inputs
476+
477+
#### `dart_sdk`
478+
479+
**Optional** Which Dart SDK version to use. It can be a version (e.g. `2.12.0`) or a channel (e.g. `stable`):
480+
481+
**Default** `"stable"`
482+
483+
#### `working_directory`
484+
485+
**Optional** The path to the root of the Dart package.
486+
487+
**Default** `"."`
488+
489+
#### `runs_on`
490+
491+
**Optional** An optional operating system on which to run the workflow.
492+
493+
**Default** `"ubuntu-latest"`
494+
495+
#### `pub_credentials`
496+
497+
**Required** The pub credentials needed for publishing. This can be retrieved by reading out your `pub-credentials.json` on your system after you ran a `dart pub login`, the location of the file is different per operating system:
498+
499+
| OS | Path |
500+
| ------- | ----------------------------------------------------------------------------------------- |
501+
| Linux | `$XDG_CONFIG_HOME/dart/pub-credentials.json` or `$HOME/.config/dart/pub-credentials.json` |
502+
| macOS | `~/Library/Application\ Support/dart/pub-credentials.json` |
503+
| Windows | `%APPDATA%/dart/pub-credentials.json` |
504+
505+
### Example Usage
506+
507+
We recommend using [GitHub Secrets][github_actions_secrets_docs] for safely storing and reading the credentials.
508+
509+
```yaml
510+
name: My Dart Pub Publish Workflow
511+
512+
on: pull_request
513+
514+
jobs:
515+
build:
516+
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_pub_publish.yml@v1
517+
with:
518+
dart_sdk: "stable"
519+
working_directory: "packages/my_dart_package"
520+
pub_credentials: ${{ secrets.PUB_CREDENTIALS }}
521+
```
522+
389523
[ci_badge]: https://github.com/VeryGoodOpenSource/very_good_workflows/actions/workflows/ci.yml/badge.svg
390524
[ci_link]: https://github.com/VeryGoodOpenSource/very_good_workflows/actions
391525
[github_workflows_link]: https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions
@@ -399,3 +533,4 @@ jobs:
399533
[very_good_workflows_blog_link]: https://verygood.ventures/blog/configuring-workflows-for-your-flutter-projects?utm_source=github&utm_medium=readme&utm_campaign=workflows_readme
400534
[commitizen]: https://github.com/commitizen/conventional-commit-types
401535
[coverage]: https://pub.dev/packages/coverage
536+
[github_actions_secrets_docs]: https://docs.github.com/en/rest/actions/secrets

0 commit comments

Comments
 (0)