fix(ci): add Gitea release asset uploader and switch release workflow to use it; bump package and daemon versions to 0.3.4
This commit is contained in:
90
.gitea/release-upload.ts
Normal file
90
.gitea/release-upload.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Release asset uploader for Gitea
|
||||
* Streams large files without loading them into memory (bypasses curl's 2GB multipart limit)
|
||||
*
|
||||
* Usage: GITEA_TOKEN=xxx RELEASE_ID=123 GITEA_REPO=owner/repo tsx release-upload.ts
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as https from 'https';
|
||||
|
||||
const token = process.env.GITEA_TOKEN;
|
||||
const releaseId = process.env.RELEASE_ID;
|
||||
const repo = process.env.GITEA_REPO;
|
||||
|
||||
if (!token || !releaseId || !repo) {
|
||||
console.error('Missing required env vars: GITEA_TOKEN, RELEASE_ID, GITEA_REPO');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const boundary = '----FormBoundary' + Date.now().toString(16);
|
||||
|
||||
async function uploadFile(filepath: string): Promise<void> {
|
||||
const filename = path.basename(filepath);
|
||||
const stats = fs.statSync(filepath);
|
||||
console.log(`Uploading ${filename} (${stats.size} bytes)...`);
|
||||
|
||||
const header = Buffer.from(
|
||||
`--${boundary}\r\n` +
|
||||
`Content-Disposition: form-data; name="attachment"; filename="${filename}"\r\n` +
|
||||
`Content-Type: application/octet-stream\r\n\r\n`
|
||||
);
|
||||
const footer = Buffer.from(`\r\n--${boundary}--\r\n`);
|
||||
const contentLength = header.length + stats.size + footer.length;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = https.request({
|
||||
hostname: 'code.foss.global',
|
||||
path: `/api/v1/repos/${repo}/releases/${releaseId}/assets?name=${encodeURIComponent(filename)}`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `token ${token}`,
|
||||
'Content-Type': `multipart/form-data; boundary=${boundary}`,
|
||||
'Content-Length': contentLength
|
||||
}
|
||||
}, (res) => {
|
||||
let data = '';
|
||||
res.on('data', chunk => data += chunk);
|
||||
res.on('end', () => {
|
||||
console.log(data);
|
||||
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
||||
console.log(`✓ ${filename} uploaded successfully`);
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error(`Upload failed: ${res.statusCode} ${data}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', reject);
|
||||
|
||||
// Stream: write header, pipe file, write footer
|
||||
req.write(header);
|
||||
const stream = fs.createReadStream(filepath);
|
||||
stream.on('error', reject);
|
||||
stream.on('end', () => {
|
||||
req.write(footer);
|
||||
req.end();
|
||||
});
|
||||
stream.pipe(req, { end: false });
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const distDir = 'dist';
|
||||
const files = fs.readdirSync(distDir)
|
||||
.map(f => path.join(distDir, f))
|
||||
.filter(f => fs.statSync(f).isFile());
|
||||
|
||||
for (const file of files) {
|
||||
await uploadFile(file);
|
||||
}
|
||||
|
||||
console.log('All assets uploaded successfully');
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -75,16 +75,13 @@ jobs:
|
||||
|
||||
echo "Created release with ID: $RELEASE_ID"
|
||||
|
||||
# Upload assets
|
||||
for asset in dist/*; do
|
||||
filename=$(basename "$asset")
|
||||
echo "Uploading $filename..."
|
||||
curl -X POST -s \
|
||||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
-T "$asset" \
|
||||
"https://code.foss.global/api/v1/repos/${{ gitea.repository }}/releases/$RELEASE_ID/assets?name=$filename"
|
||||
done
|
||||
# Upload assets using TypeScript (curl has 2GB multipart limit)
|
||||
pnpm install -g tsx
|
||||
|
||||
GITEA_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
|
||||
GITEA_REPO="${{ gitea.repository }}" \
|
||||
RELEASE_ID="$RELEASE_ID" \
|
||||
tsx .gitea/release-upload.ts
|
||||
|
||||
- name: Cleanup old releases (keep 3 latest)
|
||||
run: |
|
||||
|
||||
Reference in New Issue
Block a user