feat(release): add GitCode fallback mirror
This commit is contained in:
1 parent
391fc877a7
commit
06f024abde
6 files changed
+475
-20
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import { publishGitcodeRelease } from '../scripts/publish-gitcode-release.mjs';
|
||||
|
||||
describe('GitCode release mirror', () => {
|
||||
test('creates a release and uploads compiled artifacts', async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), 'easycli-gitcode-release-'));
|
||||
const calls: Array<{ url: string; method: string; body: unknown }> = [];
|
||||
try {
|
||||
await writeFile(join(directory, 'EasyCLIProxyAPI-v1.2.3-Windows-amd64.zip'), 'artifact');
|
||||
const fetchImpl = async (input: URL | RequestInfo, init: RequestInit = {}) => {
|
||||
const url = String(input);
|
||||
const method = init.method ?? 'GET';
|
||||
calls.push({ url, method, body: init.body });
|
||||
if (method === 'GET' && url.includes('/releases/tags/')) {
|
||||
return new Response('', { status: 404 });
|
||||
}
|
||||
if (method === 'POST' && url.includes('/releases?')) {
|
||||
return Response.json({ tag_name: 'v1.2.3', assets: [] });
|
||||
}
|
||||
if (method === 'GET' && url.includes('/upload_url?')) {
|
||||
return Response.json({
|
||||
upload_url: 'https://file-cdn.gitcode.com/presigned-upload',
|
||||
headers: { 'x-upload-token': 'signed' },
|
||||
});
|
||||
}
|
||||
if (method === 'PUT' && url === 'https://file-cdn.gitcode.com/presigned-upload') {
|
||||
return new Response('', { status: 200 });
|
||||
}
|
||||
return new Response('', { status: 500 });
|
||||
};
|
||||
|
||||
await publishGitcodeRelease({
|
||||
directory,
|
||||
repository: 'mirror-owner/EasyCLIProxyAPI',
|
||||
token: 'secret-token',
|
||||
tag: 'v1.2.3',
|
||||
fetchImpl,
|
||||
});
|
||||
|
||||
expect(calls.map(({ method }) => method)).toEqual(['GET', 'POST', 'GET', 'PUT']);
|
||||
expect(calls[0].url).toContain('/repos/mirror-owner/EasyCLIProxyAPI/releases/tags/v1.2.3');
|
||||
expect(calls[0].url).toContain('access_token=secret-token');
|
||||
expect(calls[2].url).toContain('file_name=EasyCLIProxyAPI-v1.2.3-Windows-amd64.zip');
|
||||
expect(calls[3].body).toBeInstanceOf(Uint8Array);
|
||||
} finally {
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user