Skip to content

Commit a6be1cc

Browse files
committed
include version file in package
1 parent 6bb1e64 commit a6be1cc

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

.github/workflows/update-cli.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
run: |
4242
FILE_PATH="src/main/osinstaller/CxInstaller.ts"
4343
# Update the cliVersion field in the TypeScript file
44-
sed -i "s/\(private cliVersion = '\)[^']*\(';\)/\1${NEW_CLI_VERSION}\2/" $FILE_PATH
44+
sed -i "s/\(private cliDefaultVersion = '\)[^']*\(';\)/\1${NEW_CLI_VERSION}\2/" $FILE_PATH
4545
4646
# Create a Pull Request with the version changes
4747
- name: Create Pull Request

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"typings": "dist/main/wrapper/CxWrapper.d.ts",
77
"files": [
88
"dist/main/**/*",
9-
"README.md"
9+
"README.md",
10+
"dist/checkmarx-ast-cli.version"
1011
],
1112
"dependencies": {
1213
"async-mutex": "^0.5.0",
@@ -18,7 +19,7 @@
1819
},
1920
"scripts": {
2021
"build": "tsc",
21-
"postbuild": "copyfiles -u 1 src/main/wrapper/resources/cx* dist/;copyfiles -u 1 src/tests/data/* dist/;",
22+
"postbuild": "copyfiles -u 1 src/main/wrapper/resources/cx* dist/;copyfiles -u 1 src/tests/data/* dist/;copyfiles -u 0 checkmarx-ast-cli.version dist/",
2223
"lint": "eslint . --ext .ts",
2324
"lint-and-fix": "eslint . --ext .ts --fix",
2425
"test": "copyfiles -u 1 src/tests/data/* dist/; tsc && jest --runInBand"

src/main/osinstaller/CxInstaller.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as fsPromises from 'fs/promises';
12
import * as fs from 'fs';
23
import * as path from 'path';
34
import * as tar from 'tar';
@@ -11,16 +12,19 @@ type SupportedPlatforms = 'win32' | 'darwin' | 'linux';
1112

1213
export class CxInstaller {
1314
private readonly platform: string;
14-
private cliVersion = '2.2.5';
15+
private cliVersion: string;
1516
private readonly resourceDirPath: string;
17+
private readonly cliDefaultVersion = '2.2.5'; // This will be used if the version file is not found. Should be updated with the latest version.
1618
private static installSemaphore = new Semaphore(1); // Semaphore with 1 slot
1719

1820
constructor(platform: string) {
1921
this.platform = platform;
2022
this.resourceDirPath = path.join(__dirname, `../wrapper/resources`);
2123
}
2224

23-
getDownloadURL(): string {
25+
async getDownloadURL(): Promise<string> {
26+
const cliVersion = await this.readASTCLIVersion();
27+
2428
const platforms: Record<SupportedPlatforms, { platform: string; extension: string }> = {
2529
win32: {platform: 'windows', extension: 'zip'},
2630
darwin: {platform: 'darwin', extension: 'tar.gz'},
@@ -34,7 +38,7 @@ export class CxInstaller {
3438
throw new Error('Unsupported platform or architecture');
3539
}
3640

37-
return `https://download.checkmarx.com/CxOne/CLI/${this.cliVersion}/ast-cli_${this.cliVersion}_${platformData.platform}_x64.${platformData.extension}`;
41+
return `https://download.checkmarx.com/CxOne/CLI/${cliVersion}/ast-cli_${cliVersion}_${platformData.platform}_x64.${platformData.extension}`;
3842
}
3943

4044
getExecutablePath(): string {
@@ -52,7 +56,7 @@ export class CxInstaller {
5256
logger.info('Executable already installed.');
5357
return;
5458
}
55-
const url = this.getDownloadURL();
59+
const url = await this.getDownloadURL();
5660
const zipPath = path.join(this.resourceDirPath, this.getCompressFolderName());
5761

5862
await this.downloadFile(url, zipPath);
@@ -101,6 +105,20 @@ export class CxInstaller {
101105
checkExecutableExists(): boolean {
102106
return fs.existsSync(this.getExecutablePath());
103107
}
108+
109+
async readASTCLIVersion(): Promise<string> {
110+
if (this.cliVersion) {
111+
return this.cliVersion;
112+
}
113+
try {
114+
const versionFilePath = path.join(process.cwd(), 'checkmarx-ast-cli.version');
115+
const versionContent = await fsPromises.readFile(versionFilePath, 'utf-8');
116+
return versionContent.trim();
117+
} catch (error) {
118+
logger.error('Error reading AST CLI version: ' + error.message);
119+
return this.cliDefaultVersion;
120+
}
121+
}
104122

105123
getCompressFolderName(): string {
106124
return `ast-cli.${this.platform === 'win32' ? 'zip' : 'tar.gz'}`;

0 commit comments

Comments
 (0)