mirror of
https://gitlab.com/vyla-entertainment/home.git
synced 2026-11-16 23:27:23 -05:00
automate fresh repo cloning, resolve asset caching, and auto-update Vyla SDK at startup
This commit is contained in:
72
release.js
72
release.js
@@ -78,42 +78,38 @@ function uploadFileToGitLabPackage(filePath, packageName, version, fileName) {
|
||||
}
|
||||
|
||||
function createGitLabRelease(tag, releaseLinks) {
|
||||
const sendRequest = (method, path) => {
|
||||
const sendRequest = (method, path, data = null) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let currentRef = 'main';
|
||||
try {
|
||||
currentRef = execSync('git rev-parse HEAD').toString().trim();
|
||||
} catch (e) { }
|
||||
|
||||
const postData = JSON.stringify({
|
||||
name: `Vyla Home Release ${tag}`,
|
||||
tag_name: tag,
|
||||
ref: currentRef,
|
||||
description: `Automated local release ${tag}`,
|
||||
assets: {
|
||||
links: releaseLinks
|
||||
}
|
||||
});
|
||||
|
||||
const req = https.request({
|
||||
const options = {
|
||||
hostname: 'gitlab.com',
|
||||
port: 443,
|
||||
path: path,
|
||||
method: method,
|
||||
headers: {
|
||||
'PRIVATE-TOKEN': TOKEN,
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(postData)
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}, (res) => {
|
||||
};
|
||||
let postData = '';
|
||||
if (data) {
|
||||
postData = JSON.stringify(data);
|
||||
options.headers['Content-Length'] = Buffer.byteLength(postData);
|
||||
}
|
||||
|
||||
const req = https.request(options, (res) => {
|
||||
let body = '';
|
||||
res.on('data', chunk => body += chunk);
|
||||
res.on('end', () => {
|
||||
if (res.statusCode === 200 || res.statusCode === 201) {
|
||||
resolve(JSON.parse(body));
|
||||
if (res.statusCode >= 200 && res.statusCode < 300) {
|
||||
try {
|
||||
resolve(body ? JSON.parse(body) : {});
|
||||
} catch (e) {
|
||||
resolve({});
|
||||
}
|
||||
} else if (res.statusCode === 409 && method === 'POST') {
|
||||
console.log(`Release ${tag} already exists, updating assets...`);
|
||||
sendRequest('PUT', `/api/v4/projects/${PROJECT_ID}/releases/${encodeURIComponent(tag)}`)
|
||||
console.log(`Release ${tag} already exists, deleting and recreating...`);
|
||||
sendRequest('DELETE', `/api/v4/projects/${PROJECT_ID}/releases/${encodeURIComponent(tag)}`)
|
||||
.then(() => sendRequest('POST', `/api/v4/projects/${PROJECT_ID}/releases`, data))
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
} else {
|
||||
@@ -123,12 +119,27 @@ function createGitLabRelease(tag, releaseLinks) {
|
||||
});
|
||||
|
||||
req.on('error', reject);
|
||||
req.write(postData);
|
||||
if (data) req.write(postData);
|
||||
req.end();
|
||||
});
|
||||
};
|
||||
|
||||
return sendRequest('POST', `/api/v4/projects/${PROJECT_ID}/releases`);
|
||||
let currentRef = 'main';
|
||||
try {
|
||||
currentRef = execSync('git rev-parse HEAD').toString().trim();
|
||||
} catch (e) { }
|
||||
|
||||
const releaseData = {
|
||||
name: `Vyla Home Release ${tag}`,
|
||||
tag_name: tag,
|
||||
ref: currentRef,
|
||||
description: `Automated local release ${tag}`,
|
||||
assets: {
|
||||
links: releaseLinks
|
||||
}
|
||||
};
|
||||
|
||||
return sendRequest('POST', `/api/v4/projects/${PROJECT_ID}/releases`, releaseData);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
@@ -182,11 +193,13 @@ async function main() {
|
||||
}
|
||||
|
||||
console.log('[2/4] Uploading artifacts to GitLab Package Registry...');
|
||||
const timestamp = Date.now();
|
||||
|
||||
console.log('Uploading update-payload.zip...');
|
||||
const payloadUrl = await uploadFileToGitLabPackage(payloadPath, 'vyla-home', version, 'update-payload.zip');
|
||||
const payloadUrl = await uploadFileToGitLabPackage(payloadPath, 'vyla-home', version, `update-payload-${timestamp}.zip`);
|
||||
|
||||
console.log('Uploading manifest.json...');
|
||||
const manifestUrl = await uploadFileToGitLabPackage(manifestPath, 'vyla-home', version, 'manifest.json');
|
||||
const manifestUrl = await uploadFileToGitLabPackage(manifestPath, 'vyla-home', version, `manifest-${timestamp}.json`);
|
||||
|
||||
const releaseLinks = [
|
||||
{ name: 'update-payload.zip', url: payloadUrl, link_type: 'other' },
|
||||
@@ -195,7 +208,8 @@ async function main() {
|
||||
|
||||
if (installerPath && installerUploadName) {
|
||||
console.log(`Uploading installer ${installerUploadName}...`);
|
||||
const installerUrl = await uploadFileToGitLabPackage(installerPath, 'vyla-home', version, installerUploadName);
|
||||
const installerUnique = installerUploadName.replace('.exe', `-${timestamp}.exe`);
|
||||
const installerUrl = await uploadFileToGitLabPackage(installerPath, 'vyla-home', version, installerUnique);
|
||||
releaseLinks.push({ name: installerUploadName, url: installerUrl, link_type: 'package' });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user