diff --git a/src/buildx/install.ts b/src/buildx/install.ts index 1cac89e..2fc61f8 100644 --- a/src/buildx/install.ts +++ b/src/buildx/install.ts @@ -58,7 +58,7 @@ export class Install { const version: DownloadVersion = await Install.getDownloadVersion(v); core.debug(`Install.download version: ${version.version}`); - const release: GitHubRelease = await Install.getRelease(version); + const release: GitHubRelease = await Install.getRelease(version, this.githubToken); core.debug(`Install.download release tag name: ${release.tag_name}`); const vspec = await this.vspec(release.tag_name); @@ -315,8 +315,8 @@ export class Install { } } - public static async getRelease(version: DownloadVersion): Promise { - const github = new GitHub(); + public static async getRelease(version: DownloadVersion, githubToken?: string): Promise { + const github = new GitHub({token: githubToken}); const releases = await github.releases('Buildx', version.contentOpts); if (!releases[version.version]) { throw new Error(`Cannot find Buildx release ${version.version} in releases JSON`); diff --git a/src/compose/install.ts b/src/compose/install.ts index 67bd80d..1034982 100644 --- a/src/compose/install.ts +++ b/src/compose/install.ts @@ -54,7 +54,7 @@ export class Install { const version: DownloadVersion = await Install.getDownloadVersion(v); core.debug(`Install.download version: ${version.version}`); - const release: GitHubRelease = await Install.getRelease(version); + const release: GitHubRelease = await Install.getRelease(version, this.githubToken); core.debug(`Install.download release tag name: ${release.tag_name}`); const vspec = await this.vspec(release.tag_name); @@ -213,8 +213,8 @@ export class Install { } } - public static async getRelease(version: DownloadVersion): Promise { - const github = new GitHub(); + public static async getRelease(version: DownloadVersion, githubToken?: string): Promise { + const github = new GitHub({token: githubToken}); const releases = await github.releases('Compose', version.contentOpts); if (!releases[version.version]) { throw new Error(`Cannot find Compose release ${version.version} in releases JSON`); diff --git a/src/docker/install.ts b/src/docker/install.ts index 376f9a9..7984199 100644 --- a/src/docker/install.ts +++ b/src/docker/install.ts @@ -208,14 +208,14 @@ export class Install { } private async downloadSourceArchive(component: 'docker' | 'docker-rootless-extras', src: InstallSourceArchive): Promise { - const release: GitHubRelease = await Install.getRelease(src.version); + const release: GitHubRelease = await Install.getRelease(src.version, this.githubToken); this._version = release.tag_name.replace(/^(docker-)?v+/, ''); core.debug(`docker.Install.downloadSourceArchive version: ${this._version}`); const downloadURL = this.downloadURL(component, this._version, src.channel); core.info(`Downloading ${downloadURL}`); - const downloadPath = await tc.downloadTool(downloadURL, undefined, this.githubToken); + const downloadPath = await tc.downloadTool(downloadURL); core.debug(`docker.Install.downloadSourceArchive downloadPath: ${downloadPath}`); let extractFolder; @@ -698,8 +698,8 @@ EOF`, }); } - public static async getRelease(version: string): Promise { - const github = new GitHub(); + public static async getRelease(version: string, githubToken?: string): Promise { + const github = new GitHub({token: githubToken}); const releases = await github.releases('Docker', { owner: 'docker', repo: 'actions-toolkit', diff --git a/src/github.ts b/src/github.ts index c99d295..8d285c4 100644 --- a/src/github.ts +++ b/src/github.ts @@ -45,10 +45,12 @@ export interface GitHubOpts { } export class GitHub { + private readonly githubToken?: string; public readonly octokit: InstanceType; constructor(opts?: GitHubOpts) { - this.octokit = github.getOctokit(`${opts?.token}`); + this.githubToken = opts?.token || process.env.GITHUB_TOKEN; + this.octokit = github.getOctokit(`${this.githubToken}`); } public repoData(): Promise { @@ -58,7 +60,10 @@ export class GitHub { public async releases(name: string, opts: GitHubContentOpts): Promise> { const url = `https://raw.githubusercontent.com/${opts.owner}/${opts.repo}/${opts.ref}/${opts.path}`; const http: httpm.HttpClient = new httpm.HttpClient('docker-actions-toolkit'); - const httpResp: httpm.HttpClientResponse = await http.get(url); + // prettier-ignore + const httpResp: httpm.HttpClientResponse = await http.get(url, this.githubToken ? { + Authorization: `token ${this.githubToken}` + } : undefined); const dt = await httpResp.readBody(); const statusCode = httpResp.message.statusCode || 500; if (statusCode >= 400) { diff --git a/src/regclient/install.ts b/src/regclient/install.ts index c9a6231..5c14aaf 100644 --- a/src/regclient/install.ts +++ b/src/regclient/install.ts @@ -50,7 +50,7 @@ export class Install { const version: DownloadVersion = await Install.getDownloadVersion(v); core.debug(`Install.download version: ${version.version}`); - const release: GitHubRelease = await Install.getRelease(version); + const release: GitHubRelease = await Install.getRelease(version, this.githubToken); core.debug(`Install.download release tag name: ${release.tag_name}`); const vspec = await this.vspec(release.tag_name); @@ -153,8 +153,8 @@ export class Install { }; } - public static async getRelease(version: DownloadVersion): Promise { - const github = new GitHub(); + public static async getRelease(version: DownloadVersion, githubToken?: string): Promise { + const github = new GitHub({token: githubToken}); const releases = await github.releases('regclient', version.contentOpts); if (!releases[version.version]) { throw new Error(`Cannot find regclient release ${version.version} in releases JSON`); diff --git a/src/undock/install.ts b/src/undock/install.ts index 00027df..1bc766b 100644 --- a/src/undock/install.ts +++ b/src/undock/install.ts @@ -50,7 +50,7 @@ export class Install { const version: DownloadVersion = await Install.getDownloadVersion(v); core.debug(`Install.download version: ${version.version}`); - const release: GitHubRelease = await Install.getRelease(version); + const release: GitHubRelease = await Install.getRelease(version, this.githubToken); core.debug(`Install.download release tag name: ${release.tag_name}`); const vspec = await this.vspec(release.tag_name); @@ -164,8 +164,8 @@ export class Install { }; } - public static async getRelease(version: DownloadVersion): Promise { - const github = new GitHub(); + public static async getRelease(version: DownloadVersion, githubToken?: string): Promise { + const github = new GitHub({token: githubToken}); const releases = await github.releases('Undock', version.contentOpts); if (!releases[version.version]) { throw new Error(`Cannot find Undock release ${version.version} in releases JSON`);