From 844839413688a43335ce67d124114e95db04e296 Mon Sep 17 00:00:00 2001 From: Andrii Bodnar Date: Tue, 18 Jun 2024 14:14:58 +0300 Subject: [PATCH] ci: build exe package --- .github/workflows/build-test.yml | 28 +++++ packages/exe/CrowdinCLIInstaller.iss | 154 +++++++++++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100644 packages/exe/CrowdinCLIInstaller.iss diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 182fdc74..fb95f43e 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -147,3 +147,31 @@ jobs: - name: Test crowdin command run: crowdin -V + + build-exe: + needs: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + cache: 'gradle' + + - name: Prepare distribution + run: | + ./gradlew shadowJar + mkdir dist + mv build/libs/crowdin-cli-*.jar dist/crowdin-cli.jar + + - name: Build executable + run: | + iscc packages/exe/CrowdinCLIInstaller.iss + mv crowdin.exe crowdin-unsigned.exe + + - uses: actions/upload-artifact@v4 + with: + name: exe-package + path: crowdin-unsigned.exe diff --git a/packages/exe/CrowdinCLIInstaller.iss b/packages/exe/CrowdinCLIInstaller.iss new file mode 100644 index 00000000..f0b96a82 --- /dev/null +++ b/packages/exe/CrowdinCLIInstaller.iss @@ -0,0 +1,154 @@ +; Script generated by the Inno Setup Script Wizard. +; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! + +#define MyAppName "Crowdin" +#define MyAppVersion "4.0.0" +#define MyAppPublisher "OU Crowdin" +#define MyAppURL "https://crowdin.github.io/crowdin-cli" +#define MyAppExeName "crowdin-cli.jar" + +[Registry] +Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"PATH"; ValueData:"{olddata};{app}"; Flags: preservestringtype +Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"CROWDIN_HOME"; ValueData:"{app}"; Flags: preservestringtype + +[Setup] +; NOTE: The value of AppId uniquely identifies this application. +; Do not use the same AppId value in installers for other applications. +; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) +AppId={{52B80417-16B8-4EFE-B118-6FA64B25CC0F} +AppName={#MyAppName} +AppVersion={#MyAppVersion} +AppPublisher={#MyAppPublisher} +AppPublisherURL={#MyAppURL} +AppSupportURL={#MyAppURL} +AppUpdatesURL={#MyAppURL} +DefaultDirName={pf}\CrowdinCLI +DefaultGroupName={#MyAppName} +DisableProgramGroupPage=yes +OutputDir=..\..\ +OutputBaseFilename=crowdin +Compression=lzma +SolidCompression=yes +ChangesEnvironment=yes + +[Languages] +Name: "english"; MessagesFile: "compiler:Default.isl" + +[Files] +Source: "..\..\dist\crowdin-cli.jar"; DestDir: "{app}"; Flags: ignoreversion +Source: "..\zip\crowdin.bat"; DestDir: "{app}"; Flags: ignoreversion + +[Icons] +Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" + +[Code] +function CutJavaVersionPart(var V: string): Integer; +var + S: string; + P: Integer; +begin + if Length(V) = 0 then + begin + Result := 0; + end + else + begin + P := Pos('.', V); + if P = 0 then P := Pos('_', V); + + if P > 0 then + begin + S := Copy(V, 1, P - 1); + Delete(V, 1, P); + end + else + begin + S := V; + V := ''; + end; + Result := StrToIntDef(S, 0); + end; +end; + +function MaxJavaVersion(V1, V2: string): string; +var + Part1, Part2: Integer; + Buf1, Buf2: string; +begin + Buf1 := V1; + Buf2 := V2; + Result := ''; + while (Result = '') and + ((Buf1 <> '') or (Buf2 <> '')) do + begin + Part1 := CutJavaVersionPart(Buf1); + Part2 := CutJavaVersionPart(Buf2); + if Part1 > Part2 then Result := V1 + else + if Part2 > Part1 then Result := V2; + end; +end; + +function GetJavaVersion(): string; +var + TempFile: string; + ResultCode: Integer; + S: AnsiString; + P: Integer; +begin + TempFile := ExpandConstant('{tmp}\javaversion.txt'); + if (not ExecAsOriginalUser( + ExpandConstant('{cmd}'), '/c java -version 2> "' + TempFile + '"', '', + SW_HIDE, ewWaitUntilTerminated, ResultCode)) or + (ResultCode <> 0) then + begin + Log('Failed to execute java -version'); + end + else + if not LoadStringFromFile(TempFile, S) then + begin + Log(Format('Error reading file %s', [TempFile])); + end + else + if Copy(S, 1, 14) <> 'java version "' then + begin + Log('Output of the java -version not as expected'); + end + else + begin + Delete(S, 1, 14); + P := Pos('"', S); + if P = 0 then + begin + Log('Output of the java -version not as expected'); + end + else + begin + SetLength(S, P - 1); + Result := S; + end; + end; + + DeleteFile(TempFile); +end; + +function HasJava1Dot7OrNewer: Boolean; +begin + Result := (MaxJavaVersion('1.6.9', GetJavaVersion) <> '1.6.9'); +end; + +function InitializeSetup(): Boolean; +var + ErrorCode: Integer; +begin + Result := HasJava1Dot7OrNewer; + if not Result then + begin + Result := MsgBox(ExpandConstant('Your Java version needs to be updated. Download it from https://www.java.com?'), mbConfirmation, MB_YESNO) = idYes; + if Result then + begin + ShellExec( + 'open', 'https://www.java.com/getjava/', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode); + end; + end; +end;