Dev Tips: Automating Publish a Dart Package

Posted by nepaul on 2022-12-14

Four steps to publish a package

  1. Prepare an account that can publish the package (recommended use a verified account - 🔗Advantages of using a verified publisher)

  2. A package that meets the criteria for release.(eg. 🔗svg_to_font ).
    You can run dart pub publish --dry-run under the package’s Root path to verify it before publishing and fix the result accordingly.

  3. dart pub publish: The first publish is done interactively on the command line and is mainly used to verify that the user and it will generate the corresponding tokens.

    Click to show details 👉
  4. Transfer packages that have not been sent to pub.dev from your account to an authenticated account (Details 👉🔗 Publishing packages | Dart).

    Click to show svg_to_font 👉

🎉 At this point, you have completed the entire process of manually publishing a package.

Automated publishing via GitHub Actions

Mainly using Dart and Flutter Package Publisher

  1. Add a new file, .github/workflows/publish.yml to the root directory

  2. File content reference svg_to_font

  3. Get PUB_ACCESS_TOKEN and PUB_REFRESH_TOKEN
    According to Dart and Flutter Package Publisher, it is likely that you will not get them.

    Click to show Dart and Flutter Package Publisher Doc 👉

    Check the source code of dart cli, for example, macOS, the correct address is ~/Library/Application Support/dart/pub-credentials.json

  4. Configure GitHub Actions secrets (Address: https://github.com/<REPLACE Your Repo>/settings/secrets/actions

  5. Take this article’s repository as an example, and type a tag that starts with the letter “v” and it will automatically publish


Comments: