Optimize your Dart & Flutter package development workflow with the dart_package GitHub Action.
This action helps you streamline your development process cycle by automating in-depth package analysis, running tests, tracking code-coverage with Codecov, as well as hassle-free publishing on pub.dev, saving you time and effort.
In order to upload Coverage reports to Codecov or/and to publish a package on pub.dev we need to set up the corresponding tokens as secrets in our GitHub repository.
You can find here more information about secrets & environment variables.
Your secrets in your GitHub repository should look like that:
The unique repository upload token is found on the settings page of your project. You need write access to view this token.
For GitHub repositories the token will be found in https://codecov.io/github/<owner>/<repo>/settings
.
You can acquire your pub-credentials.json
simply by running the command dart pub login
and logging in to pub.dev
with your Gmail account via a browser.
The pub-credentials.json
will be generated in the default dart config folder in your system.
You can find it depending on your OS in the following directories:
On Linux (see XDG specification)
- If
$XDG_CONFIG_HOME
is defined:$XDG_CONFIG_HOME/dart/pub-credentials.json
- else
$HOME/.config/dart/pub-credentials.json
- If
On MacOS (see developer.apple.com)
~/Library/Application Support/dart/pub-credentials.json
On Windows
%APPDATA%/dart/pub-credentials.json
Read more:
- https://pub.dev/documentation/cli_pkg/latest/cli_pkg/pubCredentials.html
- https://github.com/dart-lang/pub/issues/2999#issuecomment-908350917
Please notice that the
pub-credentials.json
needs to be encoded into a base64 string before adding it to your repository secrets.You can easily encode it using the following command:
base64 ./pub-credentials.json > output.txt
Name | Description | Required | Default |
---|---|---|---|
working_directory | Specify the working directory where the workflow will run. | false | “.” |
sdk | Specify which SDK to use (dart, flutter). | false | “dart” |
dart_sdk | Specify the Dart SDK version that will be used. This input will be ignored if sdk is set to flutter . | false | “3.4.4” |
flutter_sdk | Specify the Flutter SDK version that will be used. This input will be ignored if sdk is set to dart . | false | “3.22.3” |
analyze_directories | Specify the directories where dart analyze will run. | false | “lib test” |
line_length | The line length to use with dart format. | false | “120” |
concurrency | Controls the number of test suites that runs concurrently, meaning that multiple tests in independent suites or platforms can run at the same time. | false | “4” |
skip_tests | Flag that defines whether to skip tests. | false | “false” |
coverage | Flag that defines whether to run tests with coverage. | false | “false” |
codecov | Flag that defines whether to upload coverage reports to Codecov.Requires the codecov_token . | false | “false” |
codecov_token | The token that will be used to upload coverage reports to Codecov.Requires the codecov flag to be set to true. | false | “” |
publish | Flag that defines whether to publish the Dart package on pub.dev. | false | “false” |
pubdev_token | The token that will be used to publish the Dart package to pub.dev. | false | “” |
pana_threshold | Set a threshold in pana‘s analysis report.The exit code will indicate if (max – granted points) <= threshold. | false | “19” |
You can try the dart_package GitHub Action using the workflows in the examples folder.
# .github/workflows/pr.yml
# This workflow runs on every pull-request to ensure Dart package quality.
name: PR Workflow
on:
workflow_dispatch:
pull_request:
types: [opened, reopened, synchronize]
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
jobs:
build:
defaults:
run:
working-directory: .
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- uses: nikosportolos/dart_package@v0.2.2
# .github/workflows/merge.yml
# This workflow runs when merging code to the main branch.
name: Merge Workflow
on:
workflow_dispatch:
push:
branches:
- main
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
jobs:
build:
defaults:
run:
working-directory: .
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- uses: nikosportolos/dart_package@v0.2.2
with:
coverage: true
codecov: true
codecov_token: ${{ secrets.CODECOV_TOKEN }}
# .github/workflows/publish.yml
# This workflow runs when publishing a Dart package on pub.dev.
name: Publish Workflow
on:
workflow_dispatch:
release:
types: [published]
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
jobs:
build:
defaults:
run:
working-directory: .
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- uses: nikosportolos/dart_package@v0.2.2
with:
coverage: true
codecov: true
codecov_token: ${{ secrets.CODECOV_TOKEN }}
publish: true
pubdev_token: ${{ secrets.PUBDEV_TOKEN }}
# .github/workflows/flutter.yml
# This workflow runs on every pull-request to ensure Flutter package quality.
name: Flutter Workflow
on:
workflow_dispatch:
pull_request:
types: [opened, reopened, synchronize]
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
jobs:
build:
defaults:
run:
working-directory: .
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- uses: nikosportolos/dart_package@v0.2.2
sdK: flutter
flutter-sdk: 3.22.3
Check the changelog to learn what’s new in dart_package.
Check the contribution guide if you want to help with dart_package.