github: use github token to fetch releases JSON from CDN if available
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -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<GitHubRelease> {
|
||||
const github = new GitHub();
|
||||
public static async getRelease(version: DownloadVersion, githubToken?: string): Promise<GitHubRelease> {
|
||||
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`);
|
||||
|
||||
@@ -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<GitHubRelease> {
|
||||
const github = new GitHub();
|
||||
public static async getRelease(version: DownloadVersion, githubToken?: string): Promise<GitHubRelease> {
|
||||
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`);
|
||||
|
||||
@@ -208,14 +208,14 @@ export class Install {
|
||||
}
|
||||
|
||||
private async downloadSourceArchive(component: 'docker' | 'docker-rootless-extras', src: InstallSourceArchive): Promise<string> {
|
||||
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<GitHubRelease> {
|
||||
const github = new GitHub();
|
||||
public static async getRelease(version: string, githubToken?: string): Promise<GitHubRelease> {
|
||||
const github = new GitHub({token: githubToken});
|
||||
const releases = await github.releases('Docker', {
|
||||
owner: 'docker',
|
||||
repo: 'actions-toolkit',
|
||||
|
||||
@@ -45,10 +45,12 @@ export interface GitHubOpts {
|
||||
}
|
||||
|
||||
export class GitHub {
|
||||
private readonly githubToken?: string;
|
||||
public readonly octokit: InstanceType<typeof Octokit>;
|
||||
|
||||
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<GitHubRepo> {
|
||||
@@ -58,7 +60,10 @@ export class GitHub {
|
||||
public async releases(name: string, opts: GitHubContentOpts): Promise<Record<string, GitHubRelease>> {
|
||||
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) {
|
||||
|
||||
@@ -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<GitHubRelease> {
|
||||
const github = new GitHub();
|
||||
public static async getRelease(version: DownloadVersion, githubToken?: string): Promise<GitHubRelease> {
|
||||
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`);
|
||||
|
||||
@@ -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<GitHubRelease> {
|
||||
const github = new GitHub();
|
||||
public static async getRelease(version: DownloadVersion, githubToken?: string): Promise<GitHubRelease> {
|
||||
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`);
|
||||
|
||||
Reference in New Issue
Block a user