I am trying to deploy my package in pub.dev via Github Action, while I am able to achieve all the process I am still getting
"Pub needs your authorization to upload packages on your behalf."
How can we avoid that?
Here is my config file where I store my secret key:
# This script creates/updates pub-credentials.json file which is used
# to authorize publisher when publishing packages to pub.dev
# Checking whether the secrets are available as environment
# variables or not.
if [ -z "${PUB_DEV_PUBLISH_ACCESS_TOKEN}" ]; then
echo "Missing PUB_DEV_PUBLISH_ACCESS_TOKEN environment variable"
exit 1
fi
if [ -z "${PUB_DEV_PUBLISH_REFRESH_TOKEN}" ]; then
echo "Missing PUB_DEV_PUBLISH_REFRESH_TOKEN environment variable"
exit 1
fi
if [ -z "${PUB_DEV_PUBLISH_TOKEN_ENDPOINT}" ]; then
echo "Missing PUB_DEV_PUBLISH_TOKEN_ENDPOINT environment variable"
exit 1
fi
if [ -z "${PUB_DEV_PUBLISH_EXPIRATION}" ]; then
echo "Missing PUB_DEV_PUBLISH_EXPIRATION environment variable"
exit 1
fi
# ADD THIS LINE TO CREATE THE DIRECTORY
mkdir -p ~/.pub-cache
# Create pub-credentials.json file.
cat <<EOF > ~/.pub-cache/pub-credentials.json
{
"accessToken":"${PUB_DEV_PUBLISH_ACCESS_TOKEN}",
"refreshToken":"${PUB_DEV_PUBLISH_REFRESH_TOKEN}",
"tokenEndpoint":"${PUB_DEV_PUBLISH_TOKEN_ENDPOINT}",
"scopes":["https://www.googleapis.com/auth/userinfo.email","openid"],
"expiration":${PUB_DEV_PUBLISH_EXPIRATION}
}
EOF
And here is my yaml file for github action
on:
release:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.3.3'
- name: Install dependencies
run: flutter pub get
- name: Analyze
run: flutter analyze
- name: Run tests
run: flutter test
- name: Setup Pub Credentials
shell: bash
env:
PUB_DEV_PUBLISH_ACCESS_TOKEN: ${{ secrets.PUB_DEV_PUBLISH_ACCESS_TOKEN }}
PUB_DEV_PUBLISH_REFRESH_TOKEN: ${{ secrets.PUB_DEV_PUBLISH_REFRESH_TOKEN }}
PUB_DEV_PUBLISH_TOKEN_ENDPOINT: ${{ secrets.PUB_DEV_PUBLISH_TOKEN_ENDPOINT }}
PUB_DEV_PUBLISH_EXPIRATION: ${{ secrets.PUB_DEV_PUBLISH_EXPIRATION }}
run: |
sh ./pub_login.sh
- name: Check Publish Warnings
run: dart pub publish --dry-run
- name: Publish Package
run: dart pub publish -f
2
Answers
Couldn't find the proper fix to this, so I end up using https://github.com/k-paxian/dart-package-publisher. Check this tutorial for complete example
Try this: