Skip to content

Commit 739746b

Browse files
committed
releases: fallback to github api if github cdn fails
Signed-off-by: CrazyMax <[email protected]>
1 parent b39426e commit 739746b

File tree

22 files changed

+283
-109
lines changed

22 files changed

+283
-109
lines changed

__tests__/buildx/install.test.itg.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {describe, expect, test} from '@jest/globals';
17+
import {describe, expect, jest, test} from '@jest/globals';
1818
import * as fs from 'fs';
1919

2020
import {Install} from '../../src/buildx/install';
2121

2222
const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip;
2323

24+
// needs GitHub REST API to get releases JSON
25+
jest.unmock('@actions/github');
26+
2427
maybe('download', () => {
2528
// prettier-ignore
2629
test.each(['latest'])(

__tests__/buildx/install.test.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import {Install} from '../../src/buildx/install';
2525

2626
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-install-'));
2727

28+
// needs GitHub REST API to get releases JSON
29+
jest.unmock('@actions/github');
30+
2831
afterEach(function () {
2932
rimraf.sync(tmpDir);
3033
});
@@ -119,39 +122,64 @@ describe('getDownloadVersion', () => {
119122
expect(version.key).toEqual('official');
120123
expect(version.version).toEqual('latest');
121124
expect(version.downloadURL).toEqual('https://github.com/docker/buildx/releases/download/v%s/%s');
122-
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/buildx-releases.json');
125+
expect(version.contentOpts).toEqual({
126+
owner: 'docker',
127+
repo: 'actions-toolkit',
128+
ref: 'main',
129+
path: '.github/buildx-releases.json'
130+
});
123131
});
124132

125133
it('returns official v0.10.1 download version', async () => {
126134
const version = await Install.getDownloadVersion('v0.10.1');
127135
expect(version.key).toEqual('official');
128136
expect(version.version).toEqual('v0.10.1');
129137
expect(version.downloadURL).toEqual('https://github.com/docker/buildx/releases/download/v%s/%s');
130-
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/buildx-releases.json');
138+
expect(version.contentOpts).toEqual({
139+
owner: 'docker',
140+
repo: 'actions-toolkit',
141+
ref: 'main',
142+
path: '.github/buildx-releases.json'
143+
});
131144
});
132145

133146
it('returns cloud latest download version', async () => {
134147
const version = await Install.getDownloadVersion('cloud:latest');
135148
expect(version.key).toEqual('cloud');
136149
expect(version.version).toEqual('latest');
137150
expect(version.downloadURL).toEqual('https://github.com/docker/buildx-desktop/releases/download/v%s/%s');
138-
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/buildx-lab-releases.json');
151+
expect(version.contentOpts).toEqual({
152+
owner: 'docker',
153+
repo: 'actions-toolkit',
154+
ref: 'main',
155+
path: '.github/buildx-lab-releases.json'
156+
});
139157
});
140158

141159
it('returns cloud v0.11.2-desktop.2 download version', async () => {
142160
const version = await Install.getDownloadVersion('cloud:v0.11.2-desktop.2');
143161
expect(version.key).toEqual('cloud');
144162
expect(version.version).toEqual('v0.11.2-desktop.2');
145163
expect(version.downloadURL).toEqual('https://github.com/docker/buildx-desktop/releases/download/v%s/%s');
146-
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/buildx-lab-releases.json');
164+
expect(version.contentOpts).toEqual({
165+
owner: 'docker',
166+
repo: 'actions-toolkit',
167+
ref: 'main',
168+
path: '.github/buildx-lab-releases.json'
169+
});
147170
});
148171

149172
it('returns cloud for lab version', async () => {
150173
const version = await Install.getDownloadVersion('lab:latest');
151174
expect(version.key).toEqual('cloud');
152175
expect(version.version).toEqual('latest');
153176
expect(version.downloadURL).toEqual('https://github.com/docker/buildx-desktop/releases/download/v%s/%s');
154-
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/buildx-lab-releases.json');
177+
expect(version.contentOpts).toEqual({
178+
owner: 'docker',
179+
repo: 'actions-toolkit',
180+
ref: 'main',
181+
path: '.github/buildx-lab-releases.json'
182+
});
155183
});
156184

157185
it('unknown repo', async () => {
@@ -187,6 +215,6 @@ describe('getRelease', () => {
187215

188216
it('unknown release', async () => {
189217
const version = await Install.getDownloadVersion('foo');
190-
await expect(Install.getRelease(version)).rejects.toThrow(new Error('Cannot find Buildx release foo in https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/buildx-releases.json'));
218+
await expect(Install.getRelease(version)).rejects.toThrow(new Error('Cannot find Buildx release foo in releases JSON'));
191219
});
192220
});

__tests__/compose/install.test.itg.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {describe, expect, test} from '@jest/globals';
17+
import {describe, expect, jest, test} from '@jest/globals';
1818
import * as fs from 'fs';
1919

2020
import {Install} from '../../src/compose/install';
2121

2222
const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip;
2323

24+
// needs GitHub REST API to get releases JSON
25+
jest.unmock('@actions/github');
26+
2427
maybe('download', () => {
2528
// prettier-ignore
2629
test.each(['latest'])(

__tests__/compose/install.test.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import {Install} from '../../src/compose/install';
2525

2626
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'compose-install-'));
2727

28+
// needs GitHub REST API to get releases JSON
29+
jest.unmock('@actions/github');
30+
2831
afterEach(function () {
2932
rimraf.sync(tmpDir);
3033
});
@@ -99,28 +102,48 @@ describe('getDownloadVersion', () => {
99102
expect(version.key).toEqual('official');
100103
expect(version.version).toEqual('latest');
101104
expect(version.downloadURL).toEqual('https://github.com/docker/compose/releases/download/v%s/%s');
102-
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/compose-releases.json');
105+
expect(version.contentOpts).toEqual({
106+
owner: 'docker',
107+
repo: 'actions-toolkit',
108+
ref: 'main',
109+
path: '.github/compose-releases.json'
110+
});
103111
});
104112
it('returns official v2.24.3 download version', async () => {
105113
const version = await Install.getDownloadVersion('v2.24.3');
106114
expect(version.key).toEqual('official');
107115
expect(version.version).toEqual('v2.24.3');
108116
expect(version.downloadURL).toEqual('https://github.com/docker/compose/releases/download/v%s/%s');
109-
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/compose-releases.json');
117+
expect(version.contentOpts).toEqual({
118+
owner: 'docker',
119+
repo: 'actions-toolkit',
120+
ref: 'main',
121+
path: '.github/compose-releases.json'
122+
});
110123
});
111124
it('returns cloud latest download version', async () => {
112125
const version = await Install.getDownloadVersion('cloud:latest');
113126
expect(version.key).toEqual('cloud');
114127
expect(version.version).toEqual('latest');
115128
expect(version.downloadURL).toEqual('https://github.com/docker/compose-desktop/releases/download/v%s/%s');
116-
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/compose-lab-releases.json');
129+
expect(version.contentOpts).toEqual({
130+
owner: 'docker',
131+
repo: 'actions-toolkit',
132+
ref: 'main',
133+
path: '.github/compose-lab-releases.json'
134+
});
117135
});
118136
it('returns cloud v2.27.1-desktop.1 download version', async () => {
119137
const version = await Install.getDownloadVersion('cloud:v2.27.1-desktop.1');
120138
expect(version.key).toEqual('cloud');
121139
expect(version.version).toEqual('v2.27.1-desktop.1');
122140
expect(version.downloadURL).toEqual('https://github.com/docker/compose-desktop/releases/download/v%s/%s');
123-
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/compose-lab-releases.json');
141+
expect(version.contentOpts).toEqual({
142+
owner: 'docker',
143+
repo: 'actions-toolkit',
144+
ref: 'main',
145+
path: '.github/compose-lab-releases.json'
146+
});
124147
});
125148
it('unknown repo', async () => {
126149
await expect(Install.getDownloadVersion('foo:bar')).rejects.toThrow(new Error('Cannot find compose version for foo:bar'));
@@ -152,6 +175,6 @@ describe('getRelease', () => {
152175
});
153176
it('unknown release', async () => {
154177
const version = await Install.getDownloadVersion('foo');
155-
await expect(Install.getRelease(version)).rejects.toThrow(new Error('Cannot find Compose release foo in https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/compose-releases.json'));
178+
await expect(Install.getRelease(version)).rejects.toThrow(new Error('Cannot find Compose release foo in releases JSON'));
156179
});
157180
});

__tests__/docker/install.test.itg.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {beforeAll, describe, test, expect} from '@jest/globals';
17+
import {beforeAll, describe, jest, test, expect} from '@jest/globals';
1818
import fs from 'fs';
1919
import os from 'os';
2020
import path from 'path';
@@ -29,6 +29,9 @@ import {Exec} from '../../src/exec';
2929

3030
const tmpDir = () => fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-install-itg-'));
3131

32+
// needs GitHub REST API to get releases JSON
33+
jest.unmock('@actions/github');
34+
3235
beforeAll(async () => {
3336
const undockInstall = new UndockInstall();
3437
const undockBinPath = await undockInstall.download('v0.10.0', true);

__tests__/docker/install.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import {Undock} from '../../src/undock/undock';
2727

2828
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-install-'));
2929

30+
// needs GitHub REST API to get releases JSON
31+
jest.unmock('@actions/github');
32+
3033
afterEach(function () {
3134
rimraf.sync(tmpDir);
3235
});
@@ -90,7 +93,7 @@ describe('getRelease', () => {
9093
});
9194

9295
it('unknown release', async () => {
93-
await expect(Install.getRelease('foo')).rejects.toThrow(new Error('Cannot find Docker release foo in https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/docker-releases.json'));
96+
await expect(Install.getRelease('foo')).rejects.toThrow(new Error('Cannot find Docker release foo in releases JSON'));
9497
});
9598
});
9699

__tests__/regclient/install.test.itg.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {describe, expect, test} from '@jest/globals';
17+
import {describe, expect, jest, test} from '@jest/globals';
1818
import * as fs from 'fs';
1919

2020
import {Install} from '../../src/regclient/install';
2121

22+
// needs GitHub REST API to get releases JSON
23+
jest.unmock('@actions/github');
24+
2225
describe('download', () => {
2326
// prettier-ignore
2427
test.each(['latest'])(

__tests__/regclient/install.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import {Install} from '../../src/regclient/install';
2525

2626
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'regclient-install-'));
2727

28+
// needs GitHub REST API to get releases JSON
29+
jest.unmock('@actions/github');
30+
2831
afterEach(function () {
2932
rimraf.sync(tmpDir);
3033
});
@@ -88,13 +91,23 @@ describe('getDownloadVersion', () => {
8891
const version = await Install.getDownloadVersion('latest');
8992
expect(version.version).toEqual('latest');
9093
expect(version.downloadURL).toEqual('https://github.com/regclient/regclient/releases/download/v%s/%s');
91-
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/regclient-releases.json');
94+
expect(version.contentOpts).toEqual({
95+
owner: 'docker',
96+
repo: 'actions-toolkit',
97+
ref: 'main',
98+
path: '.github/regclient-releases.json'
99+
});
92100
});
93101
it('returns v0.8.1 download version', async () => {
94102
const version = await Install.getDownloadVersion('v0.8.1');
95103
expect(version.version).toEqual('v0.8.1');
96104
expect(version.downloadURL).toEqual('https://github.com/regclient/regclient/releases/download/v%s/%s');
97-
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/regclient-releases.json');
105+
expect(version.contentOpts).toEqual({
106+
owner: 'docker',
107+
repo: 'actions-toolkit',
108+
ref: 'main',
109+
path: '.github/regclient-releases.json'
110+
});
98111
});
99112
});
100113

@@ -115,6 +128,6 @@ describe('getRelease', () => {
115128
});
116129
it('unknown release', async () => {
117130
const version = await Install.getDownloadVersion('foo');
118-
await expect(Install.getRelease(version)).rejects.toThrow(new Error('Cannot find regclient release foo in https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/regclient-releases.json'));
131+
await expect(Install.getRelease(version)).rejects.toThrow(new Error('Cannot find regclient release foo in releases JSON'));
119132
});
120133
});

__tests__/undock/install.test.itg.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {describe, expect, test} from '@jest/globals';
17+
import {describe, expect, jest, test} from '@jest/globals';
1818
import * as fs from 'fs';
1919

2020
import {Install} from '../../src/undock/install';
2121

22+
// needs GitHub REST API to get releases JSON
23+
jest.unmock('@actions/github');
24+
2225
describe('download', () => {
2326
// prettier-ignore
2427
test.each(['latest'])(

__tests__/undock/install.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import {Install} from '../../src/undock/install';
2525

2626
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'undock-install-'));
2727

28+
// needs GitHub REST API to get releases JSON
29+
jest.unmock('@actions/github');
30+
2831
afterEach(function () {
2932
rimraf.sync(tmpDir);
3033
});
@@ -93,13 +96,23 @@ describe('getDownloadVersion', () => {
9396
const version = await Install.getDownloadVersion('latest');
9497
expect(version.version).toEqual('latest');
9598
expect(version.downloadURL).toEqual('https://github.com/crazy-max/undock/releases/download/v%s/%s');
96-
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/undock-releases.json');
99+
expect(version.contentOpts).toEqual({
100+
owner: 'docker',
101+
repo: 'actions-toolkit',
102+
ref: 'main',
103+
path: '.github/undock-releases.json'
104+
});
97105
});
98106
it('returns v0.6.0 download version', async () => {
99107
const version = await Install.getDownloadVersion('v0.6.0');
100108
expect(version.version).toEqual('v0.6.0');
101109
expect(version.downloadURL).toEqual('https://github.com/crazy-max/undock/releases/download/v%s/%s');
102-
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/undock-releases.json');
110+
expect(version.contentOpts).toEqual({
111+
owner: 'docker',
112+
repo: 'actions-toolkit',
113+
ref: 'main',
114+
path: '.github/undock-releases.json'
115+
});
103116
});
104117
});
105118

@@ -120,6 +133,6 @@ describe('getRelease', () => {
120133
});
121134
it('unknown release', async () => {
122135
const version = await Install.getDownloadVersion('foo');
123-
await expect(Install.getRelease(version)).rejects.toThrow(new Error('Cannot find Undock release foo in https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/undock-releases.json'));
136+
await expect(Install.getRelease(version)).rejects.toThrow(new Error('Cannot find Undock release foo in releases JSON'));
124137
});
125138
});

0 commit comments

Comments
 (0)