简体   繁体   中英

What is the easiest way to publish a pub.dev package in a CI?

I'm trying to automatically publish a package in Github Actions using dart pub publish but for it I need to login. The login workflow needs user-interation (logging in via Google) and thus can't be used on a CI.

As per https://github.com/dart-lang/pub/issues/2227 there doesn't seem to be an easy way, but someone mentionned:

Having to put the path like run: echo ${{secrets.PUB_CREDENTIALS}} > /opt/hostedtoolcache/flutter/1.9.1-hotfix.2-stable/x64/.pub-cache/credentials.json is not really great to maintain.

Is the format of this credentials.json known?

Edit : On Windows, the credentials.json file is not in C:\Users\<USER>\AppData\Roaming\Pub\Cache\credentials.json as indicated in the blog post, it is now at C:\Users\<USER>\AppData\Roaming\dart\pub-credentials.json .

This medium post has a clear guide that could help you on publishing Flutter or Dart packages to pub.dev via CI-CD servers.

Assuming you have the following requirements:

  1. A Flutter package ready to be published.
  2. An active account on pub.dev .
  3. A repository on GitHub with admin access.
  4. A working laptop, inte.net connection, and some patience!

These are the steps to follow:

  1. Retrieve Login Credentials for pub.dev
  2. Create Secrets on GitHub
  3. Write a shell script to set credentials
  4. Create a workflow for GitHub Action to publish a package.
  5. Triggering Builds.

Take note of this when running pub publish :

When we run this command in our terminal for the first time, pub would ask us to log in to our pub.dev account by opening the URL printed on the command line. Once we log in using that URL, pub store some login credentials (which happens to be some tokens) into a file called credentials.json .

Next time when you run pub publish command, it checks for this file and proceeds further without asking for login again. This gave me a hint that to make it work on CI-CD servers , we need to create this file somehow on the build machine.

You can visit the blog " Publish Your Flutter/Dart Package using GitHub Actions " for more details on each steps mentioned above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM