()
| 517 | * In that case increments the count to get unique parallel id. |
| 518 | */ |
| 519 | const getCiBuildId = async () => { |
| 520 | const { |
| 521 | GITHUB_WORKFLOW, |
| 522 | GITHUB_SHA, |
| 523 | GITHUB_TOKEN, |
| 524 | GITHUB_RUN_ID, |
| 525 | GITHUB_REPOSITORY, |
| 526 | GITHUB_API_URL |
| 527 | } = process.env |
| 528 | |
| 529 | const [owner, repo] = GITHUB_REPOSITORY.split('/') |
| 530 | let branch |
| 531 | let buildId = `${GITHUB_WORKFLOW} - ${GITHUB_SHA}` |
| 532 | |
| 533 | if (GITHUB_TOKEN) { |
| 534 | debug( |
| 535 | `Determining build id by asking GitHub about run ${GITHUB_RUN_ID}` |
| 536 | ) |
| 537 | |
| 538 | const client = new Octokit({ |
| 539 | auth: GITHUB_TOKEN, |
| 540 | baseUrl: GITHUB_API_URL |
| 541 | }) |
| 542 | |
| 543 | const resp = await client.request( |
| 544 | 'GET /repos/:owner/:repo/actions/runs/:run_id', |
| 545 | { |
| 546 | owner, |
| 547 | repo, |
| 548 | run_id: parseInt(GITHUB_RUN_ID) |
| 549 | } |
| 550 | ) |
| 551 | |
| 552 | if (resp && resp.data && resp.data.head_branch) { |
| 553 | branch = resp.data.head_branch |
| 554 | debug(`found the branch name ${branch}`) |
| 555 | } |
| 556 | |
| 557 | // This will return the complete list of jobs for a run with their steps, |
| 558 | // this should always return data when there are jobs on the workflow. |
| 559 | // Every time the workflow is re-run the jobs length should stay the same |
| 560 | // (because the same amount of jobs were ran) but the id of them should change |
| 561 | // letting us, select the first id as unique id |
| 562 | // https://docs.github.com/en/rest/reference/actions#list-jobs-for-a-workflow-run |
| 563 | const runsList = await client.request( |
| 564 | 'GET /repos/:owner/:repo/actions/runs/:run_id/jobs', |
| 565 | { |
| 566 | owner, |
| 567 | repo, |
| 568 | run_id: parseInt(GITHUB_RUN_ID) |
| 569 | } |
| 570 | ) |
| 571 | |
| 572 | if ( |
| 573 | runsList && |
| 574 | runsList.data && |
| 575 | runsList.data.jobs && |
| 576 | runsList.data.jobs.length |
no outgoing calls
no test coverage detected