diff --git a/shared-internal/src/main/kotlin/io/github/typesafegithub/workflows/shared/internal/GithubUtils.kt b/shared-internal/src/main/kotlin/io/github/typesafegithub/workflows/shared/internal/GithubUtils.kt index fbfb146ce5..122e59d38c 100644 --- a/shared-internal/src/main/kotlin/io/github/typesafegithub/workflows/shared/internal/GithubUtils.kt +++ b/shared-internal/src/main/kotlin/io/github/typesafegithub/workflows/shared/internal/GithubUtils.kt @@ -1,7 +1,10 @@ package io.github.typesafegithub.workflows.shared.internal +import io.github.oshai.kotlinlogging.KotlinLogging.logger import kotlinx.coroutines.runBlocking +private val logger = logger { } + /** * Returns a token that should be used to make authorized calls to GitHub, * or null if no token was configured. @@ -10,13 +13,10 @@ import kotlinx.coroutines.runBlocking */ fun getGithubAuthTokenOrNull(): String? = runBlocking { - (System.getenv("GITHUB_TOKEN") ?: getInstallationAccessToken()) - .also { - if (it == null) { - println(ERROR_NO_CONFIGURATION) - } - } - } + runCatching { getInstallationAccessToken() } + .onFailure { logger.warn(it) { "Failed to get GitHub App Installation token, falling back to GITHUB_TOKEN." } } + .getOrNull() ?: System.getenv("GITHUB_TOKEN") + }.also { if (it == null) logger.warn { ERROR_NO_CONFIGURATION } } /** * Returns a token that should be used to make authorized calls to GitHub,