Skip to content

Commit 1dc9859

Browse files
authored
Merge pull request #819 from crazy-max/install-cdn-token
use github token to fetch releases JSON from CDN if available
2 parents 75cde15 + d970614 commit 1dc9859

File tree

18 files changed

+264
-120
lines changed

18 files changed

+264
-120
lines changed

__tests__/buildx/install.test.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,39 +119,64 @@ describe('getDownloadVersion', () => {
119119
expect(version.key).toEqual('official');
120120
expect(version.version).toEqual('latest');
121121
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');
122+
expect(version.contentOpts).toEqual({
123+
owner: 'docker',
124+
repo: 'actions-toolkit',
125+
ref: 'main',
126+
path: '.github/buildx-releases.json'
127+
});
123128
});
124129

125130
it('returns official v0.10.1 download version', async () => {
126131
const version = await Install.getDownloadVersion('v0.10.1');
127132
expect(version.key).toEqual('official');
128133
expect(version.version).toEqual('v0.10.1');
129134
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');
135+
expect(version.contentOpts).toEqual({
136+
owner: 'docker',
137+
repo: 'actions-toolkit',
138+
ref: 'main',
139+
path: '.github/buildx-releases.json'
140+
});
131141
});
132142

133143
it('returns cloud latest download version', async () => {
134144
const version = await Install.getDownloadVersion('cloud:latest');
135145
expect(version.key).toEqual('cloud');
136146
expect(version.version).toEqual('latest');
137147
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');
148+
expect(version.contentOpts).toEqual({
149+
owner: 'docker',
150+
repo: 'actions-toolkit',
151+
ref: 'main',
152+
path: '.github/buildx-lab-releases.json'
153+
});
139154
});
140155

141156
it('returns cloud v0.11.2-desktop.2 download version', async () => {
142157
const version = await Install.getDownloadVersion('cloud:v0.11.2-desktop.2');
143158
expect(version.key).toEqual('cloud');
144159
expect(version.version).toEqual('v0.11.2-desktop.2');
145160
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');
161+
expect(version.contentOpts).toEqual({
162+
owner: 'docker',
163+
repo: 'actions-toolkit',
164+
ref: 'main',
165+
path: '.github/buildx-lab-releases.json'
166+
});
147167
});
148168

149169
it('returns cloud for lab version', async () => {
150170
const version = await Install.getDownloadVersion('lab:latest');
151171
expect(version.key).toEqual('cloud');
152172
expect(version.version).toEqual('latest');
153173
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');
174+
expect(version.contentOpts).toEqual({
175+
owner: 'docker',
176+
repo: 'actions-toolkit',
177+
ref: 'main',
178+
path: '.github/buildx-lab-releases.json'
179+
});
155180
});
156181

157182
it('unknown repo', async () => {
@@ -187,6 +212,6 @@ describe('getRelease', () => {
187212

188213
it('unknown release', async () => {
189214
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'));
215+
await expect(Install.getRelease(version)).rejects.toThrow(new Error('Cannot find Buildx release foo in releases JSON'));
191216
});
192217
});

__tests__/compose/install.test.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,48 @@ describe('getDownloadVersion', () => {
9999
expect(version.key).toEqual('official');
100100
expect(version.version).toEqual('latest');
101101
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');
102+
expect(version.contentOpts).toEqual({
103+
owner: 'docker',
104+
repo: 'actions-toolkit',
105+
ref: 'main',
106+
path: '.github/compose-releases.json'
107+
});
103108
});
104109
it('returns official v2.24.3 download version', async () => {
105110
const version = await Install.getDownloadVersion('v2.24.3');
106111
expect(version.key).toEqual('official');
107112
expect(version.version).toEqual('v2.24.3');
108113
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');
114+
expect(version.contentOpts).toEqual({
115+
owner: 'docker',
116+
repo: 'actions-toolkit',
117+
ref: 'main',
118+
path: '.github/compose-releases.json'
119+
});
110120
});
111121
it('returns cloud latest download version', async () => {
112122
const version = await Install.getDownloadVersion('cloud:latest');
113123
expect(version.key).toEqual('cloud');
114124
expect(version.version).toEqual('latest');
115125
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');
126+
expect(version.contentOpts).toEqual({
127+
owner: 'docker',
128+
repo: 'actions-toolkit',
129+
ref: 'main',
130+
path: '.github/compose-lab-releases.json'
131+
});
117132
});
118133
it('returns cloud v2.27.1-desktop.1 download version', async () => {
119134
const version = await Install.getDownloadVersion('cloud:v2.27.1-desktop.1');
120135
expect(version.key).toEqual('cloud');
121136
expect(version.version).toEqual('v2.27.1-desktop.1');
122137
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');
138+
expect(version.contentOpts).toEqual({
139+
owner: 'docker',
140+
repo: 'actions-toolkit',
141+
ref: 'main',
142+
path: '.github/compose-lab-releases.json'
143+
});
124144
});
125145
it('unknown repo', async () => {
126146
await expect(Install.getDownloadVersion('foo:bar')).rejects.toThrow(new Error('Cannot find compose version for foo:bar'));
@@ -152,6 +172,6 @@ describe('getRelease', () => {
152172
});
153173
it('unknown release', async () => {
154174
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'));
175+
await expect(Install.getRelease(version)).rejects.toThrow(new Error('Cannot find Compose release foo in releases JSON'));
156176
});
157177
});

__tests__/docker/install.test.itg.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import path from 'path';
2121

2222
import {Install, InstallSource, InstallSourceArchive, InstallSourceImage} from '../../src/docker/install';
2323
import {Docker} from '../../src/docker/docker';
24-
import {Regctl} from '../../src/regclient/regctl';
2524
import {Install as RegclientInstall} from '../../src/regclient/install';
26-
import {Undock} from '../../src/undock/undock';
2725
import {Install as UndockInstall} from '../../src/undock/install';
2826
import {Exec} from '../../src/exec';
2927

@@ -48,9 +46,7 @@ describe('root', () => {
4846
source: source,
4947
runDir: tmpDir(),
5048
contextName: 'foo',
51-
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`,
52-
regctl: new Regctl(),
53-
undock: new Undock()
49+
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`
5450
});
5551
await expect(tryInstall(install)).resolves.not.toThrow();
5652
}, 30 * 60 * 1000);
@@ -70,9 +66,7 @@ describe('rootless', () => {
7066
runDir: tmpDir(),
7167
contextName: 'foo',
7268
daemonConfig: `{"debug":true}`,
73-
rootless: true,
74-
regctl: new Regctl(),
75-
undock: new Undock()
69+
rootless: true
7670
});
7771
await expect(
7872
tryInstall(install, async () => {
@@ -97,9 +91,7 @@ describe('tcp', () => {
9791
runDir: tmpDir(),
9892
contextName: 'foo',
9993
daemonConfig: `{"debug":true}`,
100-
localTCPPort: 2378,
101-
regctl: new Regctl(),
102-
undock: new Undock()
94+
localTCPPort: 2378
10395
});
10496
await expect(
10597
tryInstall(install, async () => {

__tests__/docker/install.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import * as rimraf from 'rimraf';
2222
import osm = require('os');
2323

2424
import {Install, InstallSourceArchive, InstallSourceImage} from '../../src/docker/install';
25-
import {Regctl} from '../../src/regclient/regctl';
26-
import {Undock} from '../../src/undock/undock';
2725

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

@@ -66,9 +64,7 @@ describe('download', () => {
6664
jest.spyOn(osm, 'arch').mockImplementation(() => 'x64');
6765
const install = new Install({
6866
source: source,
69-
runDir: tmpDir,
70-
regctl: new Regctl(),
71-
undock: new Undock()
67+
runDir: tmpDir
7268
});
7369
const toolPath = await install.download();
7470
expect(fs.existsSync(toolPath)).toBe(true);
@@ -99,7 +95,7 @@ describe('getRelease', () => {
9995
});
10096

10197
it('unknown release', async () => {
102-
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'));
98+
await expect(Install.getRelease('foo')).rejects.toThrow(new Error('Cannot find Docker release foo in releases JSON'));
10399
});
104100
});
105101

__tests__/github.test.ts

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

17-
import {describe, expect, jest, it, beforeEach, afterEach} from '@jest/globals';
17+
import {describe, expect, jest, it, beforeEach, afterEach, test} from '@jest/globals';
1818
import * as fs from 'fs';
1919
import * as path from 'path';
2020
import * as core from '@actions/core';
@@ -43,6 +43,29 @@ describe('context', () => {
4343
});
4444
});
4545

46+
describe('releases', () => {
47+
// prettier-ignore
48+
test.each([
49+
['.github/buildx-lab-releases.json'],
50+
['.github/buildx-releases.json'],
51+
['.github/compose-lab-releases.json'],
52+
['.github/compose-releases.json'],
53+
['.github/docker-releases.json'],
54+
['.github/regclient-releases.json'],
55+
['.github/undock-releases.json'],
56+
])('returns %p', async (path: string) => {
57+
const github = new GitHub();
58+
const releases = await github.releases('App', {
59+
owner: 'docker',
60+
repo: 'actions-toolkit',
61+
ref: 'main',
62+
path: path
63+
});
64+
expect(releases).toBeDefined();
65+
expect(Object.keys(releases).length).toBeGreaterThan(0);
66+
});
67+
});
68+
4669
describe('serverURL', () => {
4770
const originalEnv = process.env;
4871
beforeEach(() => {

__tests__/regclient/install.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,23 @@ describe('getDownloadVersion', () => {
8888
const version = await Install.getDownloadVersion('latest');
8989
expect(version.version).toEqual('latest');
9090
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');
91+
expect(version.contentOpts).toEqual({
92+
owner: 'docker',
93+
repo: 'actions-toolkit',
94+
ref: 'main',
95+
path: '.github/regclient-releases.json'
96+
});
9297
});
9398
it('returns v0.8.1 download version', async () => {
9499
const version = await Install.getDownloadVersion('v0.8.1');
95100
expect(version.version).toEqual('v0.8.1');
96101
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');
102+
expect(version.contentOpts).toEqual({
103+
owner: 'docker',
104+
repo: 'actions-toolkit',
105+
ref: 'main',
106+
path: '.github/regclient-releases.json'
107+
});
98108
});
99109
});
100110

@@ -115,6 +125,6 @@ describe('getRelease', () => {
115125
});
116126
it('unknown release', async () => {
117127
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'));
128+
await expect(Install.getRelease(version)).rejects.toThrow(new Error('Cannot find regclient release foo in releases JSON'));
119129
});
120130
});

__tests__/undock/install.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,23 @@ describe('getDownloadVersion', () => {
9393
const version = await Install.getDownloadVersion('latest');
9494
expect(version.version).toEqual('latest');
9595
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');
96+
expect(version.contentOpts).toEqual({
97+
owner: 'docker',
98+
repo: 'actions-toolkit',
99+
ref: 'main',
100+
path: '.github/undock-releases.json'
101+
});
97102
});
98103
it('returns v0.6.0 download version', async () => {
99104
const version = await Install.getDownloadVersion('v0.6.0');
100105
expect(version.version).toEqual('v0.6.0');
101106
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');
107+
expect(version.contentOpts).toEqual({
108+
owner: 'docker',
109+
repo: 'actions-toolkit',
110+
ref: 'main',
111+
path: '.github/undock-releases.json'
112+
});
103113
});
104114
});
105115

@@ -120,6 +130,6 @@ describe('getRelease', () => {
120130
});
121131
it('unknown release', async () => {
122132
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'));
133+
await expect(Install.getRelease(version)).rejects.toThrow(new Error('Cannot find Undock release foo in releases JSON'));
124134
});
125135
});

0 commit comments

Comments
 (0)