From 1221d0d6b35a74185972b5b04e217f78e7e0c9af Mon Sep 17 00:00:00 2001 From: Andrii Bodnar Date: Thu, 18 Jul 2024 10:54:40 +0300 Subject: [PATCH] ci: build exe package (#817) --- .github/workflows/build-test.yml | 23 ++++ .github/workflows/publish.yml | 29 +++++ packages/exe/CrowdinCLIInstaller.iss | 154 +++++++++++++++++++++++++++ release.config.js | 16 +++ 4 files changed, 222 insertions(+) create mode 100644 packages/exe/CrowdinCLIInstaller.iss diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 182fdc74..2dbb4361 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -147,3 +147,26 @@ jobs: - name: Test crowdin command run: crowdin -V + + build-exe: + runs-on: windows-latest + needs: build + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: artifacts + + - name: Prepare distribution + run: mkdir dist && mv crowdin-cli-*.jar dist/crowdin-cli.jar + + - name: Compile .ISS to .EXE Installer + uses: Minionguyjpro/Inno-Setup-Action@v1.2.4 + with: + path: packages/exe/CrowdinCLIInstaller.iss + + - uses: actions/upload-artifact@v4 + with: + name: exe-package + path: crowdin.exe diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9c76fb9c..72ed940d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -209,3 +209,32 @@ jobs: docker build --pull -t "${{ secrets.DOCKER_HUB_REGISTRY_IMAGE }}:${{ github.ref_name }}" -t "${{ secrets.DOCKER_HUB_REGISTRY_IMAGE }}:latest" . docker push "${{ secrets.DOCKER_HUB_REGISTRY_IMAGE }}:${{ github.ref_name }}" docker push "${{ secrets.DOCKER_HUB_REGISTRY_IMAGE }}:latest" + + exe: + runs-on: windows-latest + if: github.event_name == 'release' + needs: assets + 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: Compile .ISS to .EXE Installer + uses: Minionguyjpro/Inno-Setup-Action@v1.2.2 + with: + path: packages/exe/CrowdinCLIInstaller.iss + + - name: Upload asset + uses: softprops/action-gh-release@v2 + with: + files: crowdin.exe diff --git a/packages/exe/CrowdinCLIInstaller.iss b/packages/exe/CrowdinCLIInstaller.iss new file mode 100644 index 00000000..b859aa8a --- /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={commonpf}\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; diff --git a/release.config.js b/release.config.js index 4ac4dee3..e4261e4c 100644 --- a/release.config.js +++ b/release.config.js @@ -97,6 +97,21 @@ module.exports = { } ], "countMatches": true + }, + { + "files": [ + "packages/exe/CrowdinCLIInstaller.iss" + ], + "from": "#define MyAppVersion \".*\"", + "to": "#define MyAppVersion \"${nextRelease.version}\"", + "results": [ + { + "file": "packages/exe/CrowdinCLIInstaller.iss", + "hasChanged": true, + "numMatches": 1, + "numReplacements": 1 + } + ], } ] } @@ -117,6 +132,7 @@ module.exports = { "package-lock.json", "packages/aur/pkgbuild/PKGBUILD", "packages/chocolatey/*", + "packages/exe/*", "CHANGELOG.md" ], "message": "chore(release): version ${nextRelease.version} [skip ci]"