Skip to content

Commit f6b9ac0

Browse files
committed
check
1 parent 17eda51 commit f6b9ac0

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

.github/workflows/update-cli.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,52 @@
1-
name: Update checkmarx ast cli
1+
name: Update Checkmarx AST CLI
2+
23
on:
34
workflow_dispatch:
5+
inputs:
6+
new_cli_version:
7+
description: 'New CLI version'
8+
required: false
49
schedule:
510
- cron: '0 0 * * *'
611

712
jobs:
813
update-checkmarx-cli:
914
runs-on: ubuntu-latest
15+
1016
steps:
1117
- uses: actions/checkout@v4
1218

19+
# Fetch the latest Checkmarx AST CLI version
1320
- name: Get Latest Checkmarx API version
1421
id: checkmarx-ast-cli
1522
run: |
16-
echo ::set-output name=release_tag::$(curl -sL https://api.github.com/repos/Checkmarx/ast-cli/releases/latest | jq -r ".tag_name")
17-
echo ::set-output name=current_tag::$(<checkmarx-ast-cli.version)
23+
LATEST_VERSION=$(curl -sL https://api.github.com/repos/Checkmarx/ast-cli/releases/latest | jq -r ".tag_name")
24+
CURRENT_VERSION=$(<checkmarx-ast-cli.version)
25+
echo ::set-output name=release_tag::$LATEST_VERSION
26+
echo ::set-output name=current_tag::$CURRENT_VERSION
1827
19-
- name: Update Checkmarx cli version
28+
# Update the version file if the latest version differs
29+
- name: Update Checkmarx CLI version in version file
2030
if: steps.checkmarx-ast-cli.outputs.current_tag != steps.checkmarx-ast-cli.outputs.release_tag
2131
env:
2232
RELEASE_TAG: ${{ steps.checkmarx-ast-cli.outputs.release_tag }}
2333
run: |
24-
# Update current release
2534
echo ${{ steps.checkmarx-ast-cli.outputs.release_tag }} > checkmarx-ast-cli.version
2635
36+
# Update the TypeScript file's cliVersion field
37+
- name: Update cliVersion in CxInstaller.ts
38+
if: steps.checkmarx-ast-cli.outputs.current_tag != steps.checkmarx-ast-cli.outputs.release_tag
39+
env:
40+
NEW_CLI_VERSION: ${{ steps.checkmarx-ast-cli.outputs.release_tag }}
41+
run: |
42+
FILE_PATH="src/your-file-containing-CxInstaller.ts"
43+
# Update the cliVersion field in the TypeScript file
44+
sed -i "s/\(private cliVersion = '\)[^']*\(';\)/\1${NEW_CLI_VERSION}\2/" $FILE_PATH
45+
46+
# Create a Pull Request with the version changes
2747
- name: Create Pull Request
2848
if: steps.checkmarx-ast-cli.outputs.current_tag != steps.checkmarx-ast-cli.outputs.release_tag
29-
uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c #v6
49+
uses: peter-evans/create-pull-request@v6
3050
with:
3151
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
3252
commit-message: Update checkmarx-ast-cli to ${{ steps.checkmarx-ast-cli.outputs.release_tag }}

src/main/osinstaller/CxInstaller.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@ type SupportedPlatforms = 'win32' | 'darwin' | 'linux';
1212

1313
export class CxInstaller {
1414
private readonly platform: string;
15-
private cliVersion: string;
15+
private cliVersion = '2.2.6';
1616
private readonly resourceDirPath: string;
17-
private readonly cliDefaultVersion = '2.2.6'; // This will be used if the version file is not found. Should be updated with the latest version.
1817
private static installSemaphore = new Semaphore(1); // Semaphore with 1 slot
1918

2019
constructor(platform: string) {
2120
this.platform = platform;
2221
this.resourceDirPath = path.join(__dirname, `../wrapper/resources`);
2322
}
2423

25-
async getDownloadURL(): Promise<string> {
26-
const cliVersion = await this.readASTCLIVersion();
27-
24+
getDownloadURL(): string {
2825
const platforms: Record<SupportedPlatforms, { platform: string; extension: string }> = {
2926
win32: {platform: 'windows', extension: 'zip'},
3027
darwin: {platform: 'darwin', extension: 'tar.gz'},
@@ -38,7 +35,7 @@ export class CxInstaller {
3835
throw new Error('Unsupported platform or architecture');
3936
}
4037

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

4441
getExecutablePath(): string {
@@ -56,7 +53,7 @@ export class CxInstaller {
5653
logger.info('Executable already installed.');
5754
return;
5855
}
59-
const url = await this.getDownloadURL();
56+
const url = this.getDownloadURL();
6057
const zipPath = path.join(this.resourceDirPath, this.getCompressFolderName());
6158

6259
await this.downloadFile(url, zipPath);
@@ -105,20 +102,6 @@ export class CxInstaller {
105102
checkExecutableExists(): boolean {
106103
return fs.existsSync(this.getExecutablePath());
107104
}
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-
}
122105

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

0 commit comments

Comments
 (0)