( proxy?: string, )
| 54 | * @returns string of the release tag (e.g. "v1.2.3"). |
| 55 | */ |
| 56 | export const getLatestGitHubRelease = async ( |
| 57 | proxy?: string, |
| 58 | ): Promise<string> => { |
| 59 | try { |
| 60 | const controller = new AbortController(); |
| 61 | |
| 62 | const endpoint = `https://api.github.com/repos/google-github-actions/run-anus-cli/releases/latest`; |
| 63 | |
| 64 | const response = await fetch(endpoint, { |
| 65 | method: 'GET', |
| 66 | headers: { |
| 67 | Accept: 'application/vnd.github+json', |
| 68 | 'Content-Type': 'application/json', |
| 69 | 'X-GitHub-Api-Version': '2022-11-28', |
| 70 | }, |
| 71 | dispatcher: proxy ? new ProxyAgent(proxy) : undefined, |
| 72 | signal: AbortSignal.any([AbortSignal.timeout(30_000), controller.signal]), |
| 73 | } as RequestInit); |
| 74 | |
| 75 | if (!response.ok) { |
| 76 | throw new Error( |
| 77 | `Invalid response code: ${response.status} - ${response.statusText}`, |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | const releaseTag = (await response.json()).tag_name; |
| 82 | if (!releaseTag) { |
| 83 | throw new Error(`Response did not include tag_name field`); |
| 84 | } |
| 85 | return releaseTag; |
| 86 | } catch (_error) { |
| 87 | console.debug(`Failed to determine latest run-anus-cli release:`, _error); |
| 88 | throw new Error( |
| 89 | `Unable to determine the latest run-anus-cli release on GitHub.`, |
| 90 | ); |
| 91 | } |
| 92 | }; |
| 93 | |
| 94 | /** |
| 95 | * getGitHubRepoInfo returns the owner and repository for a GitHub repo. |
no test coverage detected