From 14d9c28776de95fa1aca6d4fa9c2095443729e7d Mon Sep 17 00:00:00 2001 From: Binrui Dong Date: Wed, 12 Apr 2023 19:55:27 +0800 Subject: Improve checkout performance on Windows runners by upgrading @actions/github dependency (#1246) * Improve checkout performance on Windows runners by upgrading @actions/github dependency Re: https://github.com/actions/checkout/issues/1186 @dscho discovered that the checkout action could stall for a considerable amount of time on Windows runners waiting for PowerShell invocations made from 'windows-release' npm package to complete. Then I studied the dependency chain to figure out where 'windows-release' was imported: '@actions/checkout'@main <- '@actions/github'@2.2.0 <- '@octokit/endpoint'@6.0.1 <- '@octokit/graphql'@4.3.1 <- '@octokit/request'@5.4.2 <- '@octokit/rest'@16.43.1 <- 'universal-user-agent'@4.0.1 <- 'os-name'@3.1.0 <- 'windows-release'@3.1.0 'universal-user-agent' package dropped its dependency on 'os-name' in https://github.com/gr2m/universal-user-agent/releases/tag/v6.0.0 . '@actions/github' v3 removed dependency on '@octokit/rest'@16.43.1 and allows users to move away from the old 'universal-user-agent' v4. (https://github.com/actions/toolkit/pull/453) This pull request attempts to update the version of '@actions/github' used in the checkout action to avoid importing 'windows-release'. Based on testing in my own repositories, I can see an improvement in reduced wait time between entering the checkout action and git actually starts to do useful work. * Update .licenses * Rebuild index.js --- src/github-api-helper.ts | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'src/github-api-helper.ts') diff --git a/src/github-api-helper.ts b/src/github-api-helper.ts index 2124a86..86632f5 100644 --- a/src/github-api-helper.ts +++ b/src/github-api-helper.ts @@ -1,12 +1,12 @@ import * as assert from 'assert' import * as core from '@actions/core' import * as fs from 'fs' +import * as github from '@actions/github' import * as io from '@actions/io' import * as path from 'path' import * as retryHelper from './retry-helper' import * as toolCache from '@actions/tool-cache' import {default as uuid} from 'uuid/v4' -import {getOctokit, Octokit} from './octokit-provider' const IS_WINDOWS = process.platform === 'win32' @@ -84,11 +84,11 @@ export async function getDefaultBranch( ): Promise { return await retryHelper.execute(async () => { core.info('Retrieving the default branch name') - const octokit = getOctokit(authToken, {baseUrl: baseUrl}) + const octokit = github.getOctokit(authToken, {baseUrl: baseUrl}) let result: string try { // Get the default branch from the repo info - const response = await octokit.repos.get({owner, repo}) + const response = await octokit.rest.repos.get({owner, repo}) result = response.data.default_branch assert.ok(result, 'default_branch cannot be empty') } catch (err) { @@ -125,19 +125,14 @@ async function downloadArchive( commit: string, baseUrl?: string ): Promise { - const octokit = getOctokit(authToken, {baseUrl: baseUrl}) - const params: Octokit.ReposGetArchiveLinkParams = { + const octokit = github.getOctokit(authToken, {baseUrl: baseUrl}) + const download = IS_WINDOWS + ? octokit.rest.repos.downloadZipballArchive + : octokit.rest.repos.downloadTarballArchive + const response = await download({ owner: owner, repo: repo, - archive_format: IS_WINDOWS ? 'zipball' : 'tarball', ref: commit || ref - } - const response = await octokit.repos.getArchiveLink(params) - if (response.status != 200) { - throw new Error( - `Unexpected response from GitHub API. Status: ${response.status}, Data: ${response.data}` - ) - } - - return Buffer.from(response.data) // response.data is ArrayBuffer + }) + return Buffer.from(response.data as ArrayBuffer) // response.data is ArrayBuffer } -- cgit v1.2.3