Skip to content

Commit

Permalink
Automatically create OIDC token for pub.dev. (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Jan 5, 2023
1 parent 745c09d commit 7b1734b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,17 @@ echo "${RUNNER_TOOL_CACHE}/dart-sdk/bin" >> $GITHUB_PATH
# Report success, and print version.
echo -e "Successfully installed Dart SDK:"
${RUNNER_TOOL_CACHE}/dart-sdk/bin/dart --version

# When enabled through env variables, create OIDC token for publishing on pub.dev.
if [[ "${ACTIONS_ID_TOKEN_REQUEST_URL}" != "" && "${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" != "" ]]
then
if [[ -x "$(command -v jq)" ]]
then
PUB_TOKEN=$(curl --retry 5 --retry-connrefused -sLS "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=https://pub.dev" -H "User-Agent: actions/oidc-client" -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" | jq -r '.value')
echo "PUB_TOKEN=${PUB_TOKEN}" >> $GITHUB_ENV
export PUB_TOKEN
${RUNNER_TOOL_CACHE}/dart-sdk/bin/dart pub token add https://pub.dev --env-var PUB_TOKEN
else
echo "Could not setup OIDC token, 'jq' is not available.";
fi
fi

0 comments on commit 7b1734b

Please sign in to comment.