mirror of
https://gitlab.com/vyla-entertainment/home.git
synced 2026-11-21 17:45:40 -05:00
if release exists add a version to it
This commit is contained in:
17
release.js
17
release.js
@@ -55,6 +55,7 @@ function uploadFileToGitLabPackage(filePath, packageName, version, fileName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createGitLabRelease(tag, releaseLinks) {
|
function createGitLabRelease(tag, releaseLinks) {
|
||||||
|
const sendRequest = (method, path) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let currentRef = 'main';
|
let currentRef = 'main';
|
||||||
try {
|
try {
|
||||||
@@ -74,8 +75,8 @@ function createGitLabRelease(tag, releaseLinks) {
|
|||||||
const req = https.request({
|
const req = https.request({
|
||||||
hostname: 'gitlab.com',
|
hostname: 'gitlab.com',
|
||||||
port: 443,
|
port: 443,
|
||||||
path: `/api/v4/projects/${PROJECT_ID}/releases`,
|
path: path,
|
||||||
method: 'POST',
|
method: method,
|
||||||
headers: {
|
headers: {
|
||||||
'PRIVATE-TOKEN': TOKEN,
|
'PRIVATE-TOKEN': TOKEN,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -85,10 +86,15 @@ function createGitLabRelease(tag, releaseLinks) {
|
|||||||
let body = '';
|
let body = '';
|
||||||
res.on('data', chunk => body += chunk);
|
res.on('data', chunk => body += chunk);
|
||||||
res.on('end', () => {
|
res.on('end', () => {
|
||||||
if (res.statusCode === 201 || res.statusCode === 200) {
|
if (res.statusCode === 200 || res.statusCode === 201) {
|
||||||
resolve(JSON.parse(body));
|
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 {
|
} else {
|
||||||
reject(new Error(`Failed to create release (HTTP ${res.statusCode}): ${body}`));
|
reject(new Error(`Failed to publish release (HTTP ${res.statusCode}): ${body}`));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -97,6 +103,9 @@ function createGitLabRelease(tag, releaseLinks) {
|
|||||||
req.write(postData);
|
req.write(postData);
|
||||||
req.end();
|
req.end();
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return sendRequest('POST', `/api/v4/projects/${PROJECT_ID}/releases`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user