Skip to content

Commit 7b1734b

Browse files
authored
Automatically create OIDC token for pub.dev. (#60)
1 parent 745c09d commit 7b1734b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

setup.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,17 @@ echo "${RUNNER_TOOL_CACHE}/dart-sdk/bin" >> $GITHUB_PATH
104104
# Report success, and print version.
105105
echo -e "Successfully installed Dart SDK:"
106106
${RUNNER_TOOL_CACHE}/dart-sdk/bin/dart --version
107+
108+
# When enabled through env variables, create OIDC token for publishing on pub.dev.
109+
if [[ "${ACTIONS_ID_TOKEN_REQUEST_URL}" != "" && "${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" != "" ]]
110+
then
111+
if [[ -x "$(command -v jq)" ]]
112+
then
113+
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')
114+
echo "PUB_TOKEN=${PUB_TOKEN}" >> $GITHUB_ENV
115+
export PUB_TOKEN
116+
${RUNNER_TOOL_CACHE}/dart-sdk/bin/dart pub token add https://pub.dev --env-var PUB_TOKEN
117+
else
118+
echo "Could not setup OIDC token, 'jq' is not available.";
119+
fi
120+
fi

0 commit comments

Comments
 (0)