preface

I have published several plugin for Flutter and have been manually updating them. Updating plug-ins manually is a bit cumbersome and often fails (requires kexue to access the web), so we looked at how to use Github Actions to automatically publish plug-ins to pub.dev

  1. Avoid manual release and save upload time
  2. Github can also publish code submitted by others immediately after merging it

How do the following instructions proceed

Add the process

Start by creating a publish.yml profile in the.github/workflows directory of the plug-in.

The following

name: Publish to Pub.dev

# process trigger time, triggered when a tag is created, such as v1.0.0. Of course, other trigger timing can also be selected, such as push, release, etc
on: create

jobs:
  publishing:
    runs-on: ubuntu-latest
    steps:
      # pull repository code
      - name: "Checkout"
        uses: actions/checkout@v2
      # Release plugin
      - name: Dart and Flutter Package Publisher
        uses: K - paxian/[email protected]
        with:
          # set the Token needed to publish the plugin
          accessToken: The ${{ secrets.OAUTH_ACCESS_TOKEN }}
          refreshToken: The ${{ secrets.OAUTH_REFRESH_TOKEN }}
Copy the code

The OAUTH_ACCESS_TOKEN and OAUTH_REFRESH_TOKEN need to be set in the.pub-cache/credentials.json file, which is automatically generated after the first manual publication of the plug-in. In the user’s home directory or directory where the Flutter SDK is installed.

After getting the Token, go to the plug-in warehouse to add the above two Secret, so far the configuration has been completed 🎉

Release the plugin

Now every time you update the plugin, you just need to add a new tag and push it to the repository.

Git tag v1.0.1 git pushCopy the code

reference

Dart and Flutter Package Publisher

See Publishing Your Package here for the first time