8000 compose: cloud releases support by crazy-max · Pull Request #570 · docker/actions-toolkit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

compose: cloud releases support #570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions __tests__/buildx/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,26 @@ describe('download', () => {
['v0.9.0'],
['v0.10.5'],
])(
'acquires %p of buildx with cache', async (version) => {
const install = new Install({standalone: false});
const toolPath = await install.download(version);
expect(fs.existsSync(toolPath)).toBe(true);
});
'acquires %p of buildx with cache', async (version) => {
const install = new Install({standalone: false});
const toolPath = await install.download(version);
expect(fs.existsSync(toolPath)).toBe(true);
},
100000
);

// prettier-ignore
test.each([
['v0.11.2'],
['v0.12.0'],
])(
'acquires %p of buildx without cache', async (version) => {
const install = new Install({standalone: false});
const toolPath = await install.download(version, true);
expect(fs.existsSync(toolPath)).toBe(true);
});
'acquires %p of buildx without cache', async (version) => {
const install = new Install({standalone: false});
const toolPath = await install.download(version, true);
expect(fs.existsSync(toolPath)).toBe(true);
},
100000
);

// TODO: add tests for arm
// prettier-ignore
Expand All @@ -86,7 +90,7 @@ describe('download', () => {
['linux', 'ppc64'],
['linux', 's390x'],
])(
'acquires buildx for %s/%s', async (os, arch) => {
'acquires buildx for %s/%s', async (os, arch) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
const install = new Install();
Expand Down
63 changes: 47 additions & 16 deletions __tests__/compose/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('download', () => {
['v2.32.4', true],
['latest', true]
])(
'acquires %p of compose (standalone: %p)', async (version, standalone) => {
'acquires %p of compose (standalone: %p)', async (version, standalone) => {
const install = new Install({standalone: standalone});
const toolPath = await install.download(version);
expect(fs.existsSync(toolPath)).toBe(true);
Expand All @@ -57,22 +57,26 @@ describe('download', () => {
['v2.31.0'],
['v2.32.4'],
])(
'acquires %p of compose with cache', async (version) => {
const install = new Install({standalone: false});
const toolPath = await install.download(version);
expect(fs.existsSync(toolPath)).toBe(true);
});
'acquires %p of compose with cache', async (version) => {
const install = new Install({standalone: false});
const toolPath = await install.download(version);
expect(fs.existsSync(toolPath)).toBe(true);
},
100000
);

// prettier-ignore
test.each([
['v2.27.1'],
['v2.28.0'],
])(
'acquires %p of compose without cache', async (version) => {
const install = new Install({standalone: false});
const toolPath = await install.download(version, true);
expect(fs.existsSync(toolPath)).toBe(true);
});
'acquires %p of compose without cache', async (version) => {
const install = new Install({standalone: false});
const toolPath = await install.download(version, true);
expect(fs.existsSync(toolPath)).toBe(true);
},
100000
);

// TODO: add tests for arm
// prettier-ignore
Expand All @@ -86,7 +90,7 @@ describe('download', () => {
['linux', 'ppc64'],
['linux', 's390x'],
])(
'acquires compose for %s/%s', async (os, arch) => {
'acquires compose for %s/%s', async (os, arch) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
const install = new Install();
Expand All @@ -98,35 +102,62 @@ describe('download', () => {
});

describe('getDownloadVersion', () => {
it('returns latest download version', async () => {
it('returns official latest download version', async () => {
const version = await Install.getDownloadVersion('latest');
expect(version.key).toEqual('official');
expect(version.version).toEqual('latest');
expect(version.downloadURL).toEqual('https://github.com/docker/compose/releases/download/v%s/%s');
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/compose-releases.json');
});
it('returns v2.24.3 download version', async () => {
it('returns official v2.24.3 download version', async () => {
const version = await Install.getDownloadVersion('v2.24.3');
expect(version.key).toEqual('official');
expect(version.version).toEqual('v2.24.3');
expect(version.downloadURL).toEqual('https://github.com/docker/compose/releases/download/v%s/%s');
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/compose-releases.json');
});
it('returns cloud latest download version', async () => {
const version = await Install.getDownloadVersion('cloud:latest');
expect(version.key).toEqual('cloud');
expect(version.version).toEqual('latest');
expect(version.downloadURL).toEqual('https://github.com/docker/compose-desktop/releases/download/v%s/%s');
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/compose-lab-releases.json');
});
it('returns cloud v2.27.1-desktop.1 download version', async () => {
const version = await Install.getDownloadVersion('cloud:v2.27.1-desktop.1');
expect(version.key).toEqual('cloud');
expect(version.version).toEqual('v2.27.1-desktop.1');
expect(version.downloadURL).toEqual('https://github.com/docker/compose-desktop/releases/download/v%s/%s');
expect(version.releasesURL).toEqual('https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/compose-lab-releases.json');
});
it('unknown repo', async () => {
await expect(Install.getDownloadVersion('foo:bar')).rejects.toThrow(new Error('Cannot find compose version for foo:bar'));
});
});

describe('getRelease', () => {
it('returns latest GitHub release', async () => {
it('returns latest official GitHub release', async () => {
const version = await Install.getDownloadVersion('latest');
const release = await Install.getRelease(version);
expect(release).not.toBeNull();
expect(release?.tag_name).not.toEqual('');
});
it('returns v2.24.3 GitHub release', async () => {
it('returns v2.24.3 official GitHub release', async () => {
const version = await Install.getDownloadVersion('v2.24.3');
const release = await Install.getRelease(version);
expect(release).not.toBeNull();
expect(release?.id).toEqual(138380726);
expect(release?.tag_name).toEqual('v2.24.3');
expect(release?.html_url).toEqual('https://github.com/docker/compose/releases/tag/v2.24.3');
});
it('returns v2.27.1-desktop.1 cloud GitHub release', async () => {
const version = await Install.getDownloadVersion('cloud:v2.27.1-desktop.1');
const release = await Install.getRelease(version);
expect(release).not.toBeNull();
expect(release?.id).toEqual(157591108);
expect(release?.tag_name).toEqual('v2.27.1-desktop.1');
expect(release?.html_url).toEqual('https://github.com/docker/compose-desktop/releases/tag/v2.27.1-desktop.1');
});
it('unknown release', async () => {
const version = await Install.getDownloadVersion('foo');
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'));
Expand Down
33 changes: 27 additions & 6 deletions src/compose/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Install {
}

const installCache = new Cache({
htcName: 'compose-dl-bin',
htcName: version.key != 'official' ? `compose-dl-bin-${version.key}` : 'compose-dl-bin',
htcVersion: vspec,
baseCacheDir: path.join(os.homedir(), '.bin'),
cacheFile: os.platform() == 'win32' ? 'docker-compose.exe' : 'docker-compose',
Expand Down Expand Up @@ -172,11 +172,32 @@ export class Install {
}

public static async getDownloadVersion(v: string): Promise<DownloadVersion> {
return {
version: v,
downloadURL: 'https://github.com/docker/compose/releases/download/v%s/%s',
releasesURL: 'https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/compose-releases.json'
};
let [repoKey, version] = v.split(':');
if (!version) {
version = repoKey;
repoKey = 'official';
}
switch (repoKey) {
case 'official': {
return {
key: repoKey,
version: version,
downloadURL: 'https://github.com/docker/compose/releases/download/v%s/%s',
releasesURL: 'https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/compose-releases.json'
};
}
case 'cloud': {
return {
key: repoKey,
version: version,
downloadURL: 'https://github.com/docker/compose-desktop/releases/download/v%s/%s',
releasesURL: 'https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/compose-lab-releases.json'
};
}
default: {
throw new Error(`Cannot find compose version for ${v}`);
}
}
}

public static async getRelease(version: DownloadVersion): Promise<GitHubRelease> {
Expand Down
1 change: 1 addition & 0 deletions src/types/compose/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

export interface DownloadVersion {
key: string;
version: string;
downloadURL: string;
releasesURL: string;
Expand Down
Loading
0