Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support automated publishing from CI #5388

Closed
jonasfj opened this issue Jan 3, 2022 · 27 comments
Closed

Support automated publishing from CI #5388

jonasfj opened this issue Jan 3, 2022 · 27 comments

Comments

@jonasfj
Copy link
Member

jonasfj commented Jan 3, 2022

TODO: design out this should work, probably we can use OIDC from Github Actions, and similar features from Gitlab.

@Coronon
Copy link

Coronon commented May 8, 2022

Hi there, I would love this feature! The fact that Dart does not support easy automated deployment is surprising.

The only thing I am wondering about is why pub.dev does not support dart pub token? If that's already part of the pub command, wouldn't it make (and be easiest) sense to just use that? Or am I getting something wrong?

From a quick look into the code, I would presume one could implement that with an AuthProvider?

@danielgomezrico
Copy link

This would be nice to have, I was trying to automate the deploy on our library https://github.com/la-haus/iterable-flutter/runs/6353878819?check_suite_focus=true using my personal credential.json but it throws an error:

Pub needs your authorization to upload packages on your behalf.

Based on this it is not possible to automate the library deployment from the CI? it can only be done from the developer machine?

@Coronon
Copy link

Coronon commented May 9, 2022

You can deploy with your credentials.json, its just a little ugly - see here (a recent project of mine).

@danielgomezrico
Copy link

@Coronon I got a blocker, it says this:

Pub needs your authorization to upload packages on your behalf.
In a web browser, go to https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&response_type=code&client_id=xxxx-xxxxx.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A37523&code_challenge=xxxx-xxxxth%2Fuserinfo.email
Then click "Allow access".

But I haven't tried with dart pub publish -f

@Coronon
Copy link

Coronon commented May 10, 2022

@Coronon I got a blocker, it says this:

Pub needs your authorization to upload packages on your behalf.
In a web browser, go to https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&response_type=code&client_id=xxxx-xxxxx.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A37523&code_challenge=xxxx-xxxxth%2Fuserinfo.email
Then click "Allow access".

But I haven't tried with dart pub publish -f

I really dont want to use this thread for tech support, so this is my final reply here, see my profile for my email if you need more help.

Check if the credentials.json work on your machine. If they do, then you set up something incorrectly as that prompt to authenticate wouldn't come up. Again, I have a full example. Remove the condition (if), set up the secrets in your repo and off you go :)

PS: Most issues seem to arise because people haven't figured out that the credentials.json file has moved to $HOME/.config/dart/pub-credentials.json ^^

PPS: You will always have to use pub publish -f in a CI environment because you cant confirm "Would you really like to publish (y/N)" otherwise ;)

@danielgomezrico
Copy link

Thanks for that @Coronon I will try it

@danielgomezrico
Copy link

@Coronon I cant find the json in: $HOME/.config/dart/pub-credentials.json but I do find it in $HOME/Library/Application Support/dart

@Coronon
Copy link

Coronon commented Jun 21, 2022

It seems you are talking about macOS while I am referring to linux ;)

@danielgomezrico
Copy link

@Coronon I confirm that it works! thanks for helping me

@git-elliot
Copy link

git-elliot commented Aug 7, 2022

This is my workflow file - https://github.com/git-elliot/network_tools/blob/main/.github/workflows/publish.yml and script file to setup env vars - https://github.com/git-elliot/network_tools/blob/main/pub_login.sh.
But my workflow is now stuck at publishing step. I tried multiple ways, i'm not able to publish my dart package. What I'm doing wrong?
Edit 1 - Still asking me to authorize in browser, what is the latest path of credentials.json on ubuntu?
Edit 2 - Sakebook's Implementation is also facing this issue - actions-flutter-pub-publisher

@Coronon
Copy link

Coronon commented Aug 7, 2022

@git-elliot To reiterate again: I have a full working example.

Your path to the credentials is wrong as Dart changed them a few versions ago. The new path is $HOME/.config/dart/pub-credentials.json.

@git-elliot
Copy link

git-elliot commented Aug 7, 2022

@Coronon My bad that I've referenced files from my main branch. I'm adding my files from dev branch now. I've tried with ($HOME/.config/dart/pub-credentials.json) this path only.
Workflow file - https://github.com/git-elliot/network_tools/blob/dev/.github/workflows/publish.yml
Pub Env Vars setup file - https://github.com/git-elliot/network_tools/blob/dev/pub_login.sh

@Coronon
Copy link

Coronon commented Aug 7, 2022

@git-elliot You are missing the idToken it seems when comparing your code to my example

@git-elliot
Copy link

git-elliot commented Aug 7, 2022

Yeah @Coronon. I can also see the same. But there is no idToken in my json file as I can see clearly.
Edit: I looked again with ctrl+f, and it's there. Thanks.

@Coronon
Copy link

Coronon commented Aug 7, 2022

@git-elliot have you tried logging out and in again? Or delete your current credentials file and then log in again?

@git-elliot
Copy link

@Coronon Seems like logging out and in was the only solution to that problem. Thanks a lot. It worked.

@Coronon
Copy link

Coronon commented Aug 7, 2022

@Coronon Seems like logging out and in was the only solution to that problem. Thanks a lot. It worked.

Glad to hear that :)

@sigurdm
Copy link
Contributor

sigurdm commented Jan 23, 2023

Closing - this is done: https://dart.dev/tools/pub/automated-publishing

@sigurdm sigurdm closed this as completed Jan 23, 2023
@cedvdb
Copy link

cedvdb commented Jun 23, 2023

It's not obvious how to do it with an open source project where you'd like to enable auto publishing when a PR passes on a specific branch

@sigurdm
Copy link
Contributor

sigurdm commented Jun 26, 2023

@cedvdb perhaps you can find inspiration in the dart-teams "firehose" scripts: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose

@Tienisto
Copy link

Tienisto commented Jul 8, 2023

Closing - this is done: https://dart.dev/tools/pub/automated-publishing

Unfortunately, It doesn't seem to work with Flutter packages... I have looked into the code and the OIDC part is missing in the subosito/flutter-action action. I know this action is a third-party action but any ideas?

@Skycoder42
Copy link

@Tienisto Have a look at the following: https://github.com/Skycoder42/dart_test_tools/blob/main/.github/workflows/publish.yml#L87

There I basically copied the code from the dart action to add the token in the same way but for flutter

@iamchathu
Copy link

This doesn't work with Flutter packages. We need better support for flutter packages and needs support CI to publish them.

@fadlurahmanfdev
Copy link

You can deploy with your credentials.json, its just a little ugly - see here (a recent project of mine).

legit answer 👍 👍 👍

@sigurdm
Copy link
Contributor

sigurdm commented Sep 30, 2024

@jonasfj, @isoos we need to make automated publishing work with flutter packages!

@isoos
Copy link
Collaborator

isoos commented Sep 30, 2024

@sigurdm: I'm a bit unsure/out-of-context here: what is the part that we need to implement/provide?

@sigurdm
Copy link
Contributor

sigurdm commented Sep 30, 2024

I'm a bit unsure/out-of-context here: what is the part that we need to implement/provide?

The current github action (dart-lang/setup-dart/.github/workflows/publish.yml@v1) for automated publication does not install flutter, but only dart, making it hard to do automated publishing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests