From 4db8fa8bc1855cf74da709ddfa9e160d69d70e42 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Fri, 24 Jan 2025 09:04:44 +0200 Subject: [PATCH 1/3] add github-actions --- .github/dependabot.yml | 7 ++ .github/workflows/make.pas | 220 +++++++++++++++++++++++++++++++++++++ .github/workflows/make.yml | 39 +++++++ .gitmodules | 3 + use/fpGUI | 1 + 5 files changed, 270 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/make.pas create mode 100644 .github/workflows/make.yml create mode 100644 .gitmodules create mode 160000 use/fpGUI diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..64284b9 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +--- +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas new file mode 100644 index 0000000..a54d022 --- /dev/null +++ b/.github/workflows/make.pas @@ -0,0 +1,220 @@ +//https://castle-engine.io/modern_pascal + +program Make; +{$mode objfpc}{$H+} + +uses + Classes, + SysUtils, + StrUtils, + FileUtil, + LazFileUtils, + Zipper, + fphttpclient, + RegExpr, + openssl, + LazUTF8, + opensslsockets, + eventlog, + Process; + + function OutLog(const Knd: TEventType; const Msg: string): string; + begin + case Knd of + etError: Result := #27'[31m%s'#27'[0m'; + etInfo: Result := #27'[32m%s'#27'[0m'; + etDebug: Result := #27'[33m%s'#27'[0m'; + end; + Writeln(stderr, UTF8ToConsole(Result.Format([Msg]))); + end; + + function AddPackage(const Path: string): string; + begin + with TRegExpr.Create do + begin + Expression := + {$IFDEF MSWINDOWS} + '(cocoa|x11|_template)' + {$ELSE} + '(cocoa|gdi|_template)' + {$ENDIF} + ; + if not Exec(Path) then + if RunCommand('lazbuild', ['--add-package-link', Path], Result, [poStderrToOutPut]) then + OutLog(etDebug, 'Add package:'#9 + Path) + else + begin + ExitCode += 1; + OutLog(etError, Result); + end; + Free; + end; + end; + + function SelectString(const Input, Reg: string): string; + var + Line: string; + begin + Result := EmptyStr; + with TRegExpr.Create do + begin + Expression := Reg; + for Line in Input.Split(LineEnding) do + if Exec(Line) then + Result += Line + LineEnding; + Free; + end; + end; + + function RunTest(const Path: String): string; + begin + OutLog(etDebug, #9'run:'#9 + Path); + if RunCommand(Path, ['--all', '--format=plain'], Result, [poStderrToOutPut]) then + OutLog(etInfo, #9'success!') + else + begin + ExitCode += 1; + OutLog(etError, Result); + end; + end; + + function AddDDL(const Path: String): string; + const + LibPath: string = '/usr/lib/'; + begin + OutLog(etDebug, #9'add:'#9 + Path); + if not FileExists(LibPath + ExtractFileNameWithoutExt(Path)) then + if RunCommand('sudo', ['bash', '-c', 'cp %s %s; ldconfig --verbose'.Format([Path, LibPath])], Result, [poStderrToOutPut]) then + OutLog(etInfo, #9'success!') + else + begin + ExitCode += 1; + OutLog(etError, Result); + end; + end; + + function BuildProject(const Path: string): string; + var + Text: string; + begin + OutLog(etDebug, 'Build from:'#9 + Path); + if RunCommand('lazbuild', + ['--build-all', '--recursive', '--no-write-project', Path], Result, [poStderrToOutPut]) then + begin + Result := SelectString(Result, 'Linking').Split(' ')[2].Replace(LineEnding, EmptyStr); + OutLog(etInfo, #9'to:'#9 + Result); + Text := ReadFileToString(Path.Replace('.lpi', '.lpr')); + if Text.Contains('program') and Text.Contains('consoletestrunner') then + RunTest(Result) + else if Text.Contains('library') and Text.Contains('exports') then + AddDDL(Result) + end + else + begin + ExitCode += 1; + OutLog(etError, SelectString(Result, '(Fatal|Error):')); + end; + end; + + function DownloadFile(const Uri: string): string; + var + OutFile: TStream; + begin + InitSSLInterface; + Result := GetTempFileName; + OutFile := TFileStream.Create(Result, fmCreate or fmOpenWrite); + with TFPHttpClient.Create(nil) do + begin + try + AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)'); + AllowRedirect := True; + Get(Uri, OutFile); + OutLog(etDebug, 'Download from %s to %s'.Format([Uri, Result])); + finally + Free; + OutFile.Free; + end; + end; + end; + + procedure UnZip(const ZipFile, ZipPath: string); + begin + with TUnZipper.Create do + begin + try + FileName := ZipFile; + OutputPath := ZipPath; + Examine; + UnZipAllFiles; + OutLog(etDebug, 'Unzip from'#9 + ZipFile + #9'to'#9 + ZipPath); + DeleteFile(ZipFile); + finally + Free; + end; + end; + end; + + function InstallOPM(const Path: string): string; + begin + Result := + {$IFDEF MSWINDOWS} + GetEnvironmentVariable('APPDATA') + {$ELSE} + GetEnvironmentVariable('HOME') + {$ENDIF} + + CleanAndExpandDirectory('/.lazarus/onlinepackagemanager/packages/') + + Path; + if not DirectoryExists(Result) then + begin + if ForceDirectories(Result) then + UnZip(DownloadFile('https://packages.lazarus-ide.org/%s.zip'.Format([Path])), Result); + end; + end; + + function BuildAll(const Dependencies: array of string): string; + var + List: TStringList; + DT: TDateTime; + begin + DT := Time; + if FileExists('.gitmodules') then + if RunCommand('git', ['submodule', 'update', '--init', '--recursive', + '--force', '--remote'], Result, [poStderrToOutPut]) then + OutLog(etInfo, Result) + else + begin + ExitCode += 1; + OutLog(etError, Result); + end; + List := FindAllFiles(GetCurrentDir, '*.lpk'); + try + for Result in Dependencies do + List.AddStrings(FindAllFiles(InstallOPM(Result), '*.lpk')); + for Result in List do + AddPackage(Result); + List := FindAllFiles(GetCurrentDir, '*.lpi'); + List.Sort; + for Result in List do + if not Result.Contains('use' + DirectorySeparator) then + BuildProject(Result); + finally + List.Free; + end; + if not RunCommand('delp', ['-r', GetCurrentDir], Result, [poStderrToOutPut]) then + OutLog(etError, Result); + OutLog(etDebug, 'Duration:'#9 + FormatDateTime('hh:nn:ss', Time - DT)); + end; + +begin + try + BuildAll([]); + case ExitCode of + 0: OutLog(etInfo, 'Errors:'#9 + ExitCode.ToString); + else + OutLog(etError, 'Errors:'#9 + ExitCode.ToString); + end; + except + on E: Exception do + Writeln(E.ClassName, #9, E.Message); + end; +end. diff --git a/.github/workflows/make.yml b/.github/workflows/make.yml new file mode 100644 index 0000000..c933967 --- /dev/null +++ b/.github/workflows/make.yml @@ -0,0 +1,39 @@ +--- +name: Make + +on: + schedule: + - cron: '0 0 1 * *' + push: + branches: + - "**" + pull_request: + branches: + - master + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ${{ matrix.os }} + timeout-minutes: 120 + strategy: + matrix: + os: + - ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: true + + - name: Build + shell: bash + run: | + set -xeuo pipefail + sudo bash -c 'apt-get update; apt-get install -y lazarus' >/dev/null + instantfpc -Fu/usr/lib/lazarus/*/components/lazutils \ + .github/workflows/make.pas build diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..93f1675 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "use/fpGUI"] + path = use/fpGUI + url = git@github.com:graemeg/fpGUI.git diff --git a/use/fpGUI b/use/fpGUI new file mode 160000 index 0000000..a2b7f8e --- /dev/null +++ b/use/fpGUI @@ -0,0 +1 @@ +Subproject commit a2b7f8e55ee9150e23315f8bf4364f20c8be3e4b From e600a9081c049c796d0341af5e7551e8fb9dc20e Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Fri, 24 Jan 2025 20:39:29 +0200 Subject: [PATCH 2/3] add mseide-msegui --- .gitmodules | 3 +++ use/mseide-msegui | 1 + 2 files changed, 4 insertions(+) create mode 160000 use/mseide-msegui diff --git a/.gitmodules b/.gitmodules index 93f1675..519425e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "use/fpGUI"] path = use/fpGUI url = git@github.com:graemeg/fpGUI.git +[submodule "use/mseide-msegui"] + path = use/mseide-msegui + url = git@github.com:mse-org/mseide-msegui.git diff --git a/use/mseide-msegui b/use/mseide-msegui new file mode 160000 index 0000000..6c8bc5e --- /dev/null +++ b/use/mseide-msegui @@ -0,0 +1 @@ +Subproject commit 6c8bc5e8107eaba2c445d34c971a05150e32d547 From 16ea4e741b1a3766fc82e93a4217fe92ab6b183d Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Fri, 24 Jan 2025 22:15:46 +0200 Subject: [PATCH 3/3] fix ExtractFileName --- .github/workflows/make.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas index a54d022..670180a 100644 --- a/.github/workflows/make.pas +++ b/.github/workflows/make.pas @@ -83,7 +83,7 @@ LibPath: string = '/usr/lib/'; begin OutLog(etDebug, #9'add:'#9 + Path); - if not FileExists(LibPath + ExtractFileNameWithoutExt(Path)) then + if not FileExists(LibPath + ExtractFileName(Path)) then if RunCommand('sudo', ['bash', '-c', 'cp %s %s; ldconfig --verbose'.Format([Path, LibPath])], Result, [poStderrToOutPut]) then OutLog(etInfo, #9'success!') else