empear-analytics / empear-analytics/codescene-ci-cd-orb

codescene CLI tool/Pre-commit hook

Open
#4 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
0
Forks
2
PR merge metrics
No merged PRs in 30d

Description

From [doc](https://codescene.io/docs/cli/index.html), Any plans to convert the binary or make cs cli tool as an npm package?
I think this might lead to something or point to some direction:

`import { exec } from 'child_process';
import { join } from 'path';
import { createWriteStream, renameSync, chmodSync } from 'fs';
import { get } from 'https';
import AdmZip from 'adm-zip';

const exeName = 'cs';
const destPath = join(process.env.HOME, '.local/bin');

async function downloadAndInstallBinary() {
const url = 'https://downloads.codescene.io/enterprise/cli/codescene-cli-linux-amd64-2024-02-16.zip';
const zipPath = '/tmp/codescene-cli.zip';
const unzipPath = '/tmp/codescene-cli';

// Download the zip file
const file = createWriteStream(zipPath);
await new Promise((resolve, reject) => {
get(url, (response) => {
response.pipe(file);
file.on('finish', () => {
file.close();
resolve();
});
}).on('error', (err) => {
reject(err);
});
});

// Unzip the file
const zip = new AdmZip(zipPath);
zip.extractAllTo(unzipPath, true);

// Move the binary to the destination path
renameSync(join(unzipPath, exeName), join(destPath, exeName));

// Make the binary executable
chmodSync(join(destPath, exeName), '755');

// Remove the quarantine attribute on macOS
exec(`xattr -dr com.apple.quarantine "${join(destPath, exeName)}"`, (error, stdout, stderr) => {
if (error) {
console.error(`Error removing quarantine attribute: ${error}`);
return;
}
console.log('Quarantine attribute removed successfully.');
});

console.log(`The '${exeName}' binary has been downloaded, unzipped, moved to your PATH, and made executable.`);
}

// binary-wrapper.js
async function executeBinary() {
await downloadAndInstallBinary();

const binaryPath = join(destPath, exeName);
exec(binaryPath, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing binary: ${error}`);
return;
}
console.log(`Binary output: ${stdout}`);
});
}

export default {
executeBinary,
};
`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.