mirror of
https://gitlab.com/vyla-entertainment/home.git
synced 2026-11-21 09:35:39 -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) {
|
function createGitLabRelease(tag, releaseLinks) {
|
||||||
return new Promise((resolve, reject) => {
|
const sendRequest = (method, path) => {
|
||||||
let currentRef = 'main';
|
return new Promise((resolve, reject) => {
|
||||||
try {
|
let currentRef = 'main';
|
||||||
currentRef = execSync('git rev-parse HEAD').toString().trim();
|
try {
|
||||||
} catch (e) { }
|
currentRef = execSync('git rev-parse HEAD').toString().trim();
|
||||||
|
} catch (e) { }
|
||||||
|
|
||||||
const postData = JSON.stringify({
|
const postData = JSON.stringify({
|
||||||
name: `Vyla Home Release ${tag}`,
|
name: `Vyla Home Release ${tag}`,
|
||||||
tag_name: tag,
|
tag_name: tag,
|
||||||
ref: currentRef,
|
ref: currentRef,
|
||||||
description: `Automated local release ${tag}`,
|
description: `Automated local release ${tag}`,
|
||||||
assets: {
|
assets: {
|
||||||
links: releaseLinks
|
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}`));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
req.on('error', reject);
|
const req = https.request({
|
||||||
req.write(postData);
|
hostname: 'gitlab.com',
|
||||||
req.end();
|
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() {
|
async function main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user