mirror of
https://gitlab.com/vyla-entertainment/home.git
synced 2026-11-14 06:07:23 -05:00
if release exists add a version to it
This commit is contained in:
85
release.js
85
release.js
@@ -55,48 +55,57 @@ function uploadFileToGitLabPackage(filePath, packageName, version, fileName) {
|
||||
}
|
||||
|
||||
function createGitLabRelease(tag, releaseLinks) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let currentRef = 'main';
|
||||
try {
|
||||
currentRef = execSync('git rev-parse HEAD').toString().trim();
|
||||
} catch (e) { }
|
||||
const sendRequest = (method, path) => {
|
||||
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({
|
||||
hostname: 'gitlab.com',
|
||||
port: 443,
|
||||
path: `/api/v4/projects/${PROJECT_ID}/releases`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'PRIVATE-TOKEN': TOKEN,
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(postData)
|
||||
}
|
||||
}, (res) => {
|
||||
let body = '';
|
||||
res.on('data', chunk => body += chunk);
|
||||
res.on('end', () => {
|
||||
if (res.statusCode === 201 || res.statusCode === 200) {
|
||||
resolve(JSON.parse(body));
|
||||
} else {
|
||||
reject(new Error(`Failed to create release (HTTP ${res.statusCode}): ${body}`));
|
||||
const postData = JSON.stringify({
|
||||
name: `Vyla Home Release ${tag}`,
|
||||
tag_name: tag,
|
||||
ref: currentRef,
|
||||
description: `Automated local release ${tag}`,
|
||||
assets: {
|
||||
links: releaseLinks
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', reject);
|
||||
req.write(postData);
|
||||
req.end();
|
||||
});
|
||||
const req = https.request({
|
||||
hostname: 'gitlab.com',
|
||||
port: 443,
|
||||
path: path,
|
||||
method: method,
|
||||
headers: {
|
||||
'PRIVATE-TOKEN': TOKEN,
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(postData)
|
||||
}
|
||||
}, (res) => {
|
||||
let body = '';
|
||||
res.on('data', chunk => body += chunk);
|
||||
res.on('end', () => {
|
||||
if (res.statusCode === 200 || res.statusCode === 201) {
|
||||
resolve(JSON.parse(body));
|
||||
} 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)}`)
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
} else {
|
||||
reject(new Error(`Failed to publish release (HTTP ${res.statusCode}): ${body}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', reject);
|
||||
req.write(postData);
|
||||
req.end();
|
||||
});
|
||||
};
|
||||
|
||||
return sendRequest('POST', `/api/v4/projects/${PROJECT_ID}/releases`);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
|
||||
Reference in New Issue
Block a user