Flank / flank

:speedboat: Massively parallel Android and iOS test runner for Firebase Test Lab
https://firebase.community/
Apache License 2.0
677 stars 115 forks source link

flank makes unauthenticated requests to github API #2344

Closed andreschab90 closed 1 year ago

andreschab90 commented 1 year ago

Describe the bug

A clear and concise description of what the bug is.

  • it seems that flank is doing unauthenticated requests to github API in their github actions, even when GITHUB_TOKEN is present on the machine. The rate limit is therefore only 60 requests per hour.

To Reproduce

Steps to reproduce the behavior:

  • add flank step to your workflow
  • trigger workflow multiple times
  • if you hit the rate limit for unauthenticated requests, then build will fail

Expected behavior

A clear and concise description of what you expected to happen.

  • flank should use GITHUB_TOKEN to make authenticated requests
  • step should not fail when hitting unauthenticated rate limit

Details (please complete the following information):

Have you tested on the latest Flank snapshot? yes Post the output of flank --version. v23.01.0

Additional context

Add any other context about the problem here.

Run Flank/flank@master Run curl -L https://github.com/Flank/flank/releases/download/flank-scripts-1.9.1/flank-scripts.jar --output flank-scripts.jar % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0

77 15.8M 77 12.3M 0 0 16.5M 0 --:--:-- --:--:-- --:--:-- 16.5M 100 15.8M 100 15.8M 0 0 20.3M 0 --:--:-- --:--:-- --:--:-- 110M Run ./flankScripts github download_flank --version= Exception in thread "main" Error while doing GitHub request, because of API rate limit exceeded for 199.19.85.81. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.), more info at https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting at flank.scripts.utils.exceptions.FlankScriptsExceptionMappersKt.toGithubException(FlankScriptsExceptionMappers.kt:17) at flank.scripts.utils.exceptions.FlankScriptsExceptionMappersKt$mapClientErrorToGithubException$1.invoke(FlankScriptsExceptionMappers.kt:15) at flank.scripts.utils.exceptions.FlankScriptsExceptionMappersKt$mapClientErrorToGithubException$1.invoke(FlankScriptsExceptionMappers.kt) at flank.scripts.utils.exceptions.FlankScriptsExceptionMappersKt.mapClientError(FlankScriptsExceptionMappers.kt:11) at flank.scripts.utils.exceptions.FlankScriptsExceptionMappersKt.mapClientErrorToGithubException(FlankScriptsExceptionMappers.kt:15) at flank.scripts.data.github.GithubApiKt.getLatestReleaseTag(GithubApi.kt:58) at flank.scripts.data.github.GithubApiKt$getLatestReleaseTag$1.invokeSuspend(GithubApi.kt) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56) at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274) at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:84) at kotlinx.coroutines.BuildersKtBuildersKt.runBlocking(Builders.kt:59) at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source) at kotlinx.coroutines.BuildersKtBuildersKt.runBlocking$default(Builders.kt:38) at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source) at flank.scripts.cli.github.DownloadFlankCommand.run(DownloadFlankCommand.kt:19) at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:170) at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:179) at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:179) at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:16) at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:258) at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:255) at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:273) at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:298) at flank.scripts.cli.MainKt.main(Main.kt:29)

ryancfogarty commented 1 year ago

My team is also experiencing this issue. We are a fairly small team (~8 android engineers) and are being rate limited on our CI a few times a week.

This line may be the cause of the issue. When no version is specified for Flank, a network request is made to fetch the latest version. This request uses an empty string for the token instead of getting it from the env variable.

https://github.com/Flank/flank/blob/3a213579b0b8ed7ca018314f0619146408292b35/flank-scripts/src/main/kotlin/flank/scripts/ops/github/DownloadFlank.kt#L13

Unfortunately I do not have capacity to create a pull request but would greatly appreciate if someone else could.