d3ro-voice/scripts/ci/upload-asset-to-forgejo-release.mjs
2026-08-29 18:33:45 +09:00

44 lines
1.6 KiB
JavaScript

// scripts/ci/upload-asset-to-forgejo-release.mjs
// Uploads D3RO-Voice-Setup-1.0.0-x64.exe directly to Forgejo Release v1.0.0
import { readFileSync, existsSync } from 'node:fs';
import path from 'node:path';
import credentialHelpers from '../lib/credentials.cjs';
const { forgejoAuthorization } = credentialHelpers;
const authorization = forgejoAuthorization();
const EXE_PATH = 'apps/desktop/release/1.0.0/D3RO-Voice-Setup-1.0.0-x64.exe';
async function uploadAsset() {
console.log('--- Fetching release ID for v1.0.0 ---');
const relRes = await fetch('https://git.chanpaca.net/api/v1/repos/yunchan/d3ro-voice/releases/tags/v1.0.0', {
headers: { 'Authorization': authorization }
});
const relData = await relRes.json();
console.log('Release ID:', relData.id, relData.name);
if (!relData.id) {
console.error('Release not found');
return;
}
const fileBuffer = readFileSync(EXE_PATH);
console.log(`Uploading ${EXE_PATH} (${(fileBuffer.length / (1024*1024)).toFixed(1)} MB)...`);
const formData = new FormData();
formData.append('attachment', new Blob([fileBuffer]), 'D3RO-Voice-Setup-1.0.0-x64.exe');
const uploadRes = await fetch(`https://git.chanpaca.net/api/v1/repos/yunchan/d3ro-voice/releases/${relData.id}/assets?name=D3RO-Voice-Setup-1.0.0-x64.exe`, {
method: 'POST',
headers: {
'Authorization': authorization,
},
body: formData
});
console.log('Upload HTTP Status:', uploadRes.status);
const uploadData = await uploadRes.json();
console.log('Upload Result:', uploadData);
}
uploadAsset().catch(console.error);