mirror of
https://gitlab.com/vyla-entertainment/TV.git
synced 2026-11-13 11:37:21 -05:00
fixed for gitlab
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const root = process.cwd();
|
||||
const win = process.platform === 'win32';
|
||||
@@ -11,6 +14,15 @@ const run = (cmd, args, cwd = root) => {
|
||||
if (r.status !== 0) process.exit(r.status || 1);
|
||||
};
|
||||
|
||||
const token = process.env.GITLAB_TOKEN;
|
||||
if (!token) {
|
||||
console.error('GITLAB_TOKEN not found in environment or .env file.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const projectPath = encodeURIComponent('vyla-entertainment/TV');
|
||||
const gitlabApi = 'https://gitlab.com/api/v4';
|
||||
|
||||
const sdk = process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT;
|
||||
const lp = path.join(androidDir, 'local.properties');
|
||||
if (!fs.existsSync(lp)) {
|
||||
@@ -21,12 +33,6 @@ if (!fs.existsSync(lp)) {
|
||||
fs.writeFileSync(lp, 'sdk.dir=' + sdk.replace(/\\/g, '\\\\') + '\n');
|
||||
}
|
||||
|
||||
const ghCheck = spawnSync('gh', ['--version'], { shell: win, stdio: 'ignore' });
|
||||
if (ghCheck.status !== 0) {
|
||||
console.error('GitHub CLI (gh) is not installed or not in PATH.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
||||
const version = pkg.version || '1.0.0';
|
||||
const tag = `v${version}`;
|
||||
@@ -68,14 +74,61 @@ fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
||||
spawnSync('git', ['tag', '-a', tag, '-m', `Release ${tag}`], { shell: win, stdio: 'inherit' });
|
||||
spawnSync('git', ['push', 'origin', tag], { shell: win, stdio: 'inherit' });
|
||||
|
||||
run('gh', [
|
||||
'release',
|
||||
'create',
|
||||
tag,
|
||||
targetApk,
|
||||
manifestPath,
|
||||
'--title',
|
||||
`Vyla TV Release ${tag}`,
|
||||
'--notes',
|
||||
`Automated Release ${tag}`
|
||||
]);
|
||||
const uploadGenericPackage = async (filePath, fileName) => {
|
||||
const fileBytes = fs.readFileSync(filePath);
|
||||
const uploadUrl = `${gitlabApi}/projects/${projectPath}/packages/generic/vyla-tv/${version}/${fileName}`;
|
||||
const res = await fetch(uploadUrl, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'PRIVATE-TOKEN': token,
|
||||
'Content-Type': 'application/octet-stream'
|
||||
},
|
||||
body: fileBytes
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
console.error(`Failed uploading ${fileName} to GitLab Package Registry:`, await res.text());
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Uploaded ${fileName} to GitLab Packages.`);
|
||||
return uploadUrl;
|
||||
};
|
||||
|
||||
const apkUrl = await uploadGenericPackage(targetApk, targetApkName);
|
||||
const manifestUrl = await uploadGenericPackage(manifestPath, 'manifest.json');
|
||||
|
||||
const releaseRes = await fetch(`${gitlabApi}/projects/${projectPath}/releases`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'PRIVATE-TOKEN': token,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: `Vyla TV Release ${tag}`,
|
||||
tag_name: tag,
|
||||
description: `Automated Release ${tag}`,
|
||||
assets: {
|
||||
links: [
|
||||
{
|
||||
name: targetApkName,
|
||||
url: apkUrl,
|
||||
link_type: 'package'
|
||||
},
|
||||
{
|
||||
name: 'manifest.json',
|
||||
url: manifestUrl,
|
||||
link_type: 'other'
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
if (!releaseRes.ok) {
|
||||
console.error('Failed to create GitLab Release:', await releaseRes.text());
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const releaseData = await releaseRes.json();
|
||||
console.log(`\nSuccessfully released ${tag}: https://gitlab.com/vyla-entertainment/TV/-/releases/${tag}`);
|
||||
Reference in New Issue
Block a user