Reputation: 588
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
.
Upvotes: 1
Views: 1414
Reputation: 17357
This is now supported
https://dart.dev/tools/pub/automated-publishing
I cannot post an explanation here as stackoverflow rules would require because this is too long and might change in the future.
Upvotes: 1
Reputation: 6729
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:
These are the steps to follow:
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 calledcredentials.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.
Upvotes: 6