From 365254d334f681a3820006dde0282062aa359e69 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Wed, 15 Jan 2025 16:32:52 +0200 Subject: [PATCH 1/6] Rewrote CI to Pascal --- .github/workflows/make.json | 7 - .github/workflows/make.pas | 198 ++++++++++++++++++ .github/workflows/make.ps1 | 187 ----------------- .github/workflows/make.sh | 112 ---------- .github/workflows/make.yml | 20 +- ...ibConsole.Tests.lpi => IntXLibConsole.lpi} | 0 6 files changed, 203 insertions(+), 321 deletions(-) delete mode 100644 .github/workflows/make.json create mode 100644 .github/workflows/make.pas delete mode 100644 .github/workflows/make.ps1 delete mode 100644 .github/workflows/make.sh rename IntXLib.Tests/FreePascal.Tests/{IntXLibConsole.Tests.lpi => IntXLibConsole.lpi} (100%) diff --git a/.github/workflows/make.json b/.github/workflows/make.json deleted file mode 100644 index af2cb3e..0000000 --- a/.github/workflows/make.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "app" : "IntXLib", - "lib" : "IntXLib", - "tst" : "IntXLib.Tests/FreePascal.Tests/IntXLibConsole.Tests.lpi", - "pkg" : [ - ] -} diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas new file mode 100644 index 0000000..f6612af --- /dev/null +++ b/.github/workflows/make.pas @@ -0,0 +1,198 @@ +program Make; +{$mode objfpc}{$H+} + +uses + Classes, + SysUtils, + StrUtils, + FileUtil, + Zipper, + fphttpclient, + RegExpr, + openssl, + opensslsockets, + Process; + +const + Target: string = '.'; + Dependencies: array of string = (); + +type + Output = record + Code: boolean; + Output: ansistring; + end; + + function CheckModules: Output; + begin + if FileExists('.gitmodules') then + if RunCommand('git', ['submodule', 'update', '--init', '--recursive', + '--force', '--remote'], Result.Output) then + Writeln(stderr, #27'[33m', Result.Output, #27'[0m'); + end; + + function AddPackage(Path: string): Output; + begin + with TRegExpr.Create do + begin + Expression := + {$IFDEF MSWINDOWS} + '(cocoa|x11|_template)' + {$ELSE} + '(cocoa|gdi|_template)' + {$ENDIF} + ; + if not Exec(Path) and RunCommand('lazbuild', ['--add-package-link', Path], + Result.Output) then + Writeln(stderr, #27'[33m', 'added ', Path, #27'[0m'); + Free; + end; + end; + + function BuildProject(Path: string): Output; + var + Line: string; + begin + Write(stderr, #27'[33m', 'build from ', Path, #27'[0m'); + try + Result.Code := RunCommand('lazbuild', ['--build-all', '--recursive', + '--no-write-project', Path], Result.Output); + if Result.Code then + for Line in SplitString(Result.Output, LineEnding) do + begin + if ContainsStr(Line, 'Linking') then + begin + Result.Output := SplitString(Line, ' ')[2]; + Writeln(stderr, #27'[32m', ' to ', Result.Output, #27'[0m'); + break; + end; + end + else + begin + ExitCode += 1; + for Line in SplitString(Result.Output, LineEnding) do + with TRegExpr.Create do + begin + Expression := '(Fatal|Error):'; + if Exec(Line) then + begin + WriteLn(stderr); + Writeln(stderr, #27'[31m', Line, #27'[0m'); + end; + Free; + end; + end; + except + on E: Exception do + WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message); + end; + end; + + function RunTest(Path: string): Output; + var + Temp: string; + begin + Result := BuildProject(Path); + Temp:= Result.Output; + if Result.Code then + try + if not RunCommand(Temp, ['--all', '--format=plain', '--progress'], Result.Output) then + ExitCode += 1; + WriteLn(stderr, Result.Output); + except + on E: Exception do + WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message); + end; + end; + + function AddOPM(Each: string): string; + var + TempFile, Url: string; + Zip: TStream; + begin + Result := + {$IFDEF MSWINDOWS} + GetEnvironmentVariable('APPDATA') + '\.lazarus\onlinepackagemanager\packages\' + {$ELSE} + GetEnvironmentVariable('HOME') + '/.lazarus/onlinepackagemanager/packages/' + {$ENDIF} + + Each; + TempFile := GetTempFileName; + Url := 'https://packages.lazarus-ide.org/' + Each + '.zip'; + if not DirectoryExists(Result) then + begin + Zip := TFileStream.Create(TempFile, fmCreate or fmOpenWrite); + with TFPHttpClient.Create(nil) do + begin + try + AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)'); + AllowRedirect := True; + Get(Url, Zip); + WriteLn(stderr, 'Download from ', Url, ' to ', TempFile); + finally + Free; + end; + end; + Zip.Free; + CreateDir(Result); + with TUnZipper.Create do + begin + try + FileName := TempFile; + OutputPath := Result; + Examine; + UnZipAllFiles; + WriteLn(stderr, 'Unzip from ', TempFile, ' to ', Result); + finally + Free; + end; + end; + DeleteFile(TempFile); + end; + end; + + function Main: Output; + var + Each, Item: string; + List: TStringList; + begin + CheckModules; + InitSSLInterface; + for Each in Dependencies do + begin + List := FindAllFiles(AddOPM(Each), '*.lpk', True); + try + for Item in List do + AddPackage(Item); + finally + List.Free; + end; + end; + List := FindAllFiles(GetCurrentDir, '*.lpk', True); + try + for Each in List do + AddPackage(Each); + finally + List.Free; + end; + List := FindAllFiles(Target, '*.lpi', True); + try + for Each in List do + if ContainsStr(ReadFileToString(ReplaceStr(Each, '.lpi', '.lpr')), + 'consoletestrunner') then + RunTest(Each) + else + BuildProject(Each); + finally + List.Free; + end; + WriteLn(stderr); + if ExitCode <> 0 then + WriteLn(stderr, #27'[31m', 'Errors: ', ExitCode, #27'[0m') + else + WriteLn(stderr, #27'[32m', 'Errors: ', ExitCode, #27'[0m'); + end; + +begin + Main; +end. diff --git a/.github/workflows/make.ps1 b/.github/workflows/make.ps1 deleted file mode 100644 index 5458c87..0000000 --- a/.github/workflows/make.ps1 +++ /dev/null @@ -1,187 +0,0 @@ -#!/usr/bin/env pwsh -############################################################################################################## - -Function Show-Usage { - " -vagrant = 'it-gro/win10-ltsc-eval' -download = 'https://microsoft.com/en-us/evalcenter' -package = 'https://learn.microsoft.com/en-us/mem/configmgr/develop/apps/how-to-create-the-windows-installer-file-msi' -shell = 'https://learn.microsoft.com/en-us/powershell' - -Usage: pwsh -File $($PSCommandPath) [OPTIONS] -Options: - build - lint -" | Out-Host -} - -Function Build-Project { - New-Variable -Option Constant -Name VAR -Value (Get-Content -Path $PSCommandPath.Replace('ps1', 'json') | ConvertFrom-Json) - If (! (Test-Path -Path $Var.app)) { - "$([char]27)[31m.... $($Var.app) did not find!$([char]27)[0m" | Out-Host - Exit 1 - } - If (Test-Path -Path '.gitmodules') { - & git submodule update --init --recursive --force --remote | Out-Host - "$([char]27)[33m.... [[$($LastExitCode)]] git submodule update$([char]27)[0m" | Out-Host - } - @( - @{ - Cmd = 'lazbuild' - Url = 'https://fossies.org/windows/misc/lazarus-3.6-fpc-3.2.2-win64.exe' - Path = "C:\Lazarus" - } - ) | Where-Object { - ! (Test-Path -Path $_.Path) - } | ForEach-Object { - $_.Url | Request-File | Install-Program - $Env:PATH+=";$($_.Path)" - Return (Get-Command $_.Cmd).Source - } | Out-Host - $VAR.Pkg | ForEach-Object { - @{ - Name = $_ - Uri = "https://packages.lazarus-ide.org/$($_).zip" - Path = "$($Env:HOME)\.lazarus\onlinepackagemanager\packages\$($_)" - OutFile = (New-TemporaryFile).FullName - } - } | Where-Object { - ! (Test-Path -Path $_.Path) && - ! (& lazbuild --verbose-pkgsearch $_.Name ) && - ! (& lazbuild --add-package $_.Name) - } | ForEach-Object -Parallel { - Invoke-WebRequest -OutFile $_.OutFile -Uri $_.Uri - New-Item -Type Directory -Path $_.Path | Out-Null - Expand-Archive -Path $_.OutFile -DestinationPath $_.Path - Remove-Item $_.OutFile - (Get-ChildItem -Filter '*.lpk' -Recurse -File –Path $_.Path).FullName | - ForEach-Object { - & lazbuild --add-package-link $_ | Out-Null - Return "$([char]27)[33m.... [$($LastExitCode)] add package link $($_)$([char]27)[0m" - } - } | Out-Host - If (Test-Path -Path $VAR.lib) { - (Get-ChildItem -Filter '*.lpk' -Recurse -File –Path $VAR.lib).FullName | - ForEach-Object { - & lazbuild --add-package-link $_ | Out-Null - Return "$([char]27)[33m.... [$($LastExitCode)] add package link $($_)$([char]27)[0m" - } | Out-Host - } - Exit $(Switch (Test-Path -Path $Var.tst) { - true { - $Output = ( - & lazbuild --build-all --recursive --no-write-project $VAR.tst | - Where-Object { - $_.Contains('Linking') - } | ForEach-Object { - $_.Split(' ')[2].Replace('bin', 'bin\.') - } - ) - $Output = (& $Output --all --format=plain --progress) - $exitCode = Switch ($LastExitCode) { - 0 {0} - Default { - 1 - } - } - $Output | Out-Host - Return $exitCode -K } - Default {0} - }) + ( - (Get-ChildItem -Filter '*.lpi' -Recurse -File –Path $Var.app).FullName | - ForEach-Object { - $Output = (& lazbuild --build-all --recursive --no-write-project $_) - $Result = @("$([char]27)[32m.... [$($LastExitCode)] build project $($_)$([char]27)[0m") - $exitCode = $(Switch ($LastExitCode) { - 0 { - $Result += $Output | Select-String -Pattern 'Linking' - 0 - } - Default { - $Result += $Output | Select-String -Pattern 'Error:', 'Fatal:' - 1 - } - }) - $Result | Out-Host - Return $exitCode - } | Measure-Object -Sum - ).Sum -} - -Function Request-File { - While ($Input.MoveNext()) { - New-Variable -Option Constant -Name VAR -Value @{ - Uri = $Input.Current - OutFile = (Split-Path -Path $Input.Current -Leaf).Split('?')[0] - } - Invoke-WebRequest @VAR - Return $VAR.OutFile - } -} - -Function Install-Program { - While ($Input.MoveNext()) { - Switch ((Split-Path -Path $Input.Current -Leaf).Split('.')[-1]) { - 'msi' { - & msiexec /passive /package $Input.Current | Out-Null - } - Default { - & ".\$($Input.Current)" /SP- /VERYSILENT /SUPPRESSMSGBOXES /NORESTART | Out-Null - } - } - Remove-Item $Input.Current - } -} - -Function Request-URL([Switch] $Post) { - $VAR = Switch ($Post) { - true { - @{ - Method = 'POST' - Headers = @{ - ContentType = 'application/json' - } - Uri = 'https://postman-echo.com/post' - Body = @{ - One = '1' - } | ConvertTo-Json - } - } - false { - @{ - Uri = 'https://postman-echo.com/get' - } - } - } - Return (Invoke-WebRequest @VAR | ConvertFrom-Json).Headers -} - -Function Switch-Action { - $ErrorActionPreference = 'stop' - Set-PSDebug -Strict #-Trace 1 - Invoke-ScriptAnalyzer -EnableExit -Path $PSCommandPath - If ($args.count -gt 0) { - Switch ($args[0]) { - 'lint' { - Invoke-ScriptAnalyzer -EnableExit -Recurse -Path '.' - (Get-ChildItem -Filter '*.ps1' -Recurse -Path '.').FullName | - ForEach-Object { - Invoke-Formatter -ScriptDefinition $(Get-Content -Path $_ | Out-String) | - Set-Content -Path $_ - } - } - 'build' { - Build-Project - } - Default { - Show-Usage - } - } - } Else { - Show-Usage - } -} - -############################################################################################################## -Switch-Action @args diff --git a/.github/workflows/make.sh b/.github/workflows/make.sh deleted file mode 100644 index 04643b4..0000000 --- a/.github/workflows/make.sh +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env bash -############################################################################################################## - -function priv_clippit -( - cat <&2 - if [[ -f '.gitmodules' ]]; then - git submodule update --init --recursive --force --remote & - fi - if ! (command -v lazbuild); then - # shellcheck source=/dev/null - source '/etc/os-release' - case ${ID:?} in - debian | ubuntu) - sudo apt-get update - sudo apt-get install -y lazarus{-ide-qt5,} & - ;; - esac - fi &>/dev/null - wait - while read -r; do - ( - declare -rA TMP=( - [url]="https://packages.lazarus-ide.org/${REPLY}.zip" - [dir]="${HOME}/.lazarus/onlinepackagemanager/packages/${REPLY}" - [out]=$(mktemp) - ) - if ! [[ -d "${TMP[dir]}" ]] && - ! (lazbuild --verbose-pkgsearch "${REPLY}") && - ! (lazbuild --add-package "${REPLY}"); then - wget --quiet --output-document "${TMP[out]}" "${TMP[url]}" - mkdir --parents "${TMP[dir]}" - unzip -o "${TMP[out]}" -d "${TMP[dir]}" - rm --verbose "${TMP[out]}" - find "${TMP[dir]}" -type 'f' -name '*.lpk' -printf '\033[33m\tadd package link\t%p\033[0m\n' -exec \ - lazbuild --add-package-link {} + >&2 - fi - ) & - done < <(jq --raw-output --exit-status '.pkg[]' <<< "${MAPFILE[@]}") - wait - if [[ -d "${VAR[lib]}" ]]; then - find "${VAR[lib]}" -type 'f' -name '*.lpk' -printf '\033[33m\tadd package link\t%p\033[0m\n' -exec \ - lazbuild --add-package-link {} + >&2 - fi - declare -i exitCode=0 - if [[ -f "${VAR[tst]}" ]]; then - declare -A TMP=( - [tst]=$( - lazbuild --build-all --recursive --no-write-project "${VAR[tst]}" | - awk '/Linking/{print $3}' - ) - ) - if ! ("${TMP[tst]}" --all --format=plain --progress >&2); then - ((exitCode+=1)) - fi - fi - while read -r; do - declare -A TMP=( - [out]=$(mktemp) - ) - if (lazbuild --build-all --recursive --no-write-project "${REPLY}" > "${TMP[out]}"); then - printf '\x1b[32m\t[%s]\t%s\x1b[0m\n' "${?}" "${REPLY}" - grep --color='always' 'Linking' "${TMP[out]}" - else - printf '\x1b[31m\t[%s]\t%s\x1b[0m\n' "${?}" "${REPLY}" - grep --color='always' --extended-regexp '(Error|Fatal):' "${TMP[out]}" - ((exitCode+=1)) - fi >&2 - rm "${TMP[out]}" - done < <(find "${VAR[app]}" -type 'f' -name '*.lpi') - exit "${exitCode}" -) - -function priv_main -( - set -euo pipefail - if ((${#})); then - case ${1} in - build) priv_lazbuild ;; - *) priv_clippit ;; - esac - else - priv_clippit - fi -) - -############################################################################################################## -priv_main "${@}" >/dev/null diff --git a/.github/workflows/make.yml b/.github/workflows/make.yml index 006d55c..9b1f91e 100644 --- a/.github/workflows/make.yml +++ b/.github/workflows/make.yml @@ -24,7 +24,7 @@ jobs: matrix: os: - ubuntu-latest - - windows-latest + steps: - name: Checkout uses: actions/checkout@v4 @@ -32,18 +32,8 @@ jobs: submodules: true - name: Build on Linux - if: runner.os == 'Linux' shell: bash - run: bash .github/workflows/make.sh build - - - name: Build on Windows - if: runner.os == 'Windows' - shell: powershell - run: pwsh -File .github/workflows/make.ps1 build - - - name: Archive - if: runner.os == 'Windows' - uses: actions/upload-artifact@v4 - with: - retention-days: 1 - path: src\bin\*.exe + run: | + set -xeuo pipefail + sudo bash -c 'apt-get update; apt-get install -y lazarus yt-dlp' >/dev/null + instantfpc -Fu/usr/lib/lazarus/*/components/lazutils .github/workflows/make.pas diff --git a/IntXLib.Tests/FreePascal.Tests/IntXLibConsole.Tests.lpi b/IntXLib.Tests/FreePascal.Tests/IntXLibConsole.lpi similarity index 100% rename from IntXLib.Tests/FreePascal.Tests/IntXLibConsole.Tests.lpi rename to IntXLib.Tests/FreePascal.Tests/IntXLibConsole.lpi From 01bdd3dc018b91c865089f13867c67e17aaa3324 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Sat, 18 Jan 2025 12:20:15 +0200 Subject: [PATCH 2/6] add Windows Build --- .github/workflows/make.pas | 231 +++++++++++++++++++------------------ .github/workflows/make.yml | 25 +++- 2 files changed, 142 insertions(+), 114 deletions(-) diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas index f6612af..32ccc8e 100644 --- a/.github/workflows/make.pas +++ b/.github/workflows/make.pas @@ -18,20 +18,31 @@ Dependencies: array of string = (); type + TLog = (audit, info, error); + Output = record - Code: boolean; - Output: ansistring; + Success: boolean; + Output: string; end; - function CheckModules: Output; + procedure OutLog(const Knd: TLog; const Msg: string); + begin + case Knd of + error: Writeln(stderr, #27'[31m', Msg, #27'[0m'); + info: Writeln(stderr, #27'[32m', Msg, #27'[0m'); + audit: Writeln(stderr, #27'[33m', Msg, #27'[0m'); + end; + end; + + function CheckModules: string; begin if FileExists('.gitmodules') then if RunCommand('git', ['submodule', 'update', '--init', '--recursive', - '--force', '--remote'], Result.Output) then - Writeln(stderr, #27'[33m', Result.Output, #27'[0m'); + '--force', '--remote'], Result) then + OutLog(info, Result); end; - function AddPackage(Path: string): Output; + function AddPackage(const Path: string): string; begin with TRegExpr.Create do begin @@ -43,72 +54,100 @@ Output = record {$ENDIF} ; if not Exec(Path) and RunCommand('lazbuild', ['--add-package-link', Path], - Result.Output) then - Writeln(stderr, #27'[33m', 'added ', Path, #27'[0m'); + Result) then + OutLog(audit, ' ' + Path); Free; end; end; - function BuildProject(Path: string): Output; + function SelectString(const Input, Reg: string): string; var Line: string; begin - Write(stderr, #27'[33m', 'build from ', Path, #27'[0m'); - try - Result.Code := RunCommand('lazbuild', ['--build-all', '--recursive', - '--no-write-project', Path], Result.Output); - if Result.Code then - for Line in SplitString(Result.Output, LineEnding) do - begin - if ContainsStr(Line, 'Linking') then - begin - Result.Output := SplitString(Line, ' ')[2]; - Writeln(stderr, #27'[32m', ' to ', Result.Output, #27'[0m'); - break; - end; - end - else + for Line in SplitString(Input, LineEnding) do + with TRegExpr.Create do begin - ExitCode += 1; - for Line in SplitString(Result.Output, LineEnding) do - with TRegExpr.Create do - begin - Expression := '(Fatal|Error):'; - if Exec(Line) then - begin - WriteLn(stderr); - Writeln(stderr, #27'[31m', Line, #27'[0m'); - end; - Free; - end; + Expression := Reg; + if Exec(Line) then + Result += Line + LineEnding; + Free; end; - except - on E: Exception do - WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message); + end; + + function BuildProject(const Path: string): Output; + begin + OutLog(audit, 'Build from ' + Path); + Result.Success := RunCommand('lazbuild', + ['--build-all', '--recursive', '--no-write-project', Path], Result.Output); + Result.Output := SelectString(Result.Output, '(Fatal:|Error:|Linking)'); + if Result.Success then + begin + Result.Output := SplitString(Result.Output, ' ')[2]; + OutLog(info, ' to ' + Result.Output); + end + else + begin + ExitCode += 1; + OutLog(error, Result.Output); end; end; function RunTest(Path: string): Output; - var - Temp: string; begin Result := BuildProject(Path); - Temp:= Result.Output; - if Result.Code then - try - if not RunCommand(Temp, ['--all', '--format=plain', '--progress'], Result.Output) then - ExitCode += 1; - WriteLn(stderr, Result.Output); - except - on E: Exception do - WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message); - end; + if Result.Success then + begin + Path := Result.Output; + OutLog(audit, 'run ' + Path); + if not RunCommand(Path, ['--all', '--format=plain'], Result.Output) then + begin + ExitCode += 1; + OutLog(error, Result.Output); + end + else + OutLog(info, ' success!'); + end; end; - function AddOPM(Each: string): string; + function DownloadFile(const Uri: string): string; var - TempFile, Url: string; - Zip: TStream; + 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(audit, 'Download from ' + Uri + ' to ' + 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(audit, 'Unzip from ' + ZipFile + ' to ' + ZipPath); + DeleteFile(ZipFile); + finally + Free; + end; + end; + end; + + function InstallOPM(const Path: string): string; begin Result := {$IFDEF MSWINDOWS} @@ -116,83 +155,51 @@ Output = record {$ELSE} GetEnvironmentVariable('HOME') + '/.lazarus/onlinepackagemanager/packages/' {$ENDIF} - + Each; - TempFile := GetTempFileName; - Url := 'https://packages.lazarus-ide.org/' + Each + '.zip'; + + Path; if not DirectoryExists(Result) then begin - Zip := TFileStream.Create(TempFile, fmCreate or fmOpenWrite); - with TFPHttpClient.Create(nil) do - begin - try - AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)'); - AllowRedirect := True; - Get(Url, Zip); - WriteLn(stderr, 'Download from ', Url, ' to ', TempFile); - finally - Free; - end; - end; - Zip.Free; CreateDir(Result); - with TUnZipper.Create do - begin - try - FileName := TempFile; - OutputPath := Result; - Examine; - UnZipAllFiles; - WriteLn(stderr, 'Unzip from ', TempFile, ' to ', Result); - finally - Free; - end; - end; - DeleteFile(TempFile); + UnZip(DownloadFile('https://packages.lazarus-ide.org/' + Path + '.zip'), Result); end; end; - function Main: Output; + procedure BuildAll; var - Each, Item: string; + Each: string; List: TStringList; begin CheckModules; - InitSSLInterface; - for Each in Dependencies do - begin - List := FindAllFiles(AddOPM(Each), '*.lpk', True); - try - for Item in List do - AddPackage(Item); - finally - List.Free; - end; - end; List := FindAllFiles(GetCurrentDir, '*.lpk', True); try + for Each in Dependencies do + List.AddStrings(FindAllFiles(InstallOPM(Each), '*.lpk', True)); + if List.Count <> 0 then + OutLog(audit, 'Add packages: ' + IntToStr(List.Count)); for Each in List do AddPackage(Each); - finally - List.Free; - end; - List := FindAllFiles(Target, '*.lpi', True); - try + List := FindAllFiles(Target, '*.lpi', True); for Each in List do - if ContainsStr(ReadFileToString(ReplaceStr(Each, '.lpi', '.lpr')), - 'consoletestrunner') then - RunTest(Each) - else - BuildProject(Each); + if not ContainsStr(Each, 'zengl') then + if ContainsStr(ReadFileToString(ReplaceStr(Each, '.lpi', '.lpr')), + 'consoletestrunner') then + RunTest(Each) + else + BuildProject(Each); finally List.Free; end; - WriteLn(stderr); - if ExitCode <> 0 then - WriteLn(stderr, #27'[31m', 'Errors: ', ExitCode, #27'[0m') - else - WriteLn(stderr, #27'[32m', 'Errors: ', ExitCode, #27'[0m'); + case ExitCode of + 0: OutLog(info, 'Errors: ' + IntToStr(ExitCode)); + else + OutLog(error, 'Errors: ' + IntToStr(ExitCode)); + end; end; begin - Main; + if ParamCount <> 0 then + case ParamStr(1) of + 'build': BuildAll; + else + OutLog(audit, 'Nothing!'); + end; end. diff --git a/.github/workflows/make.yml b/.github/workflows/make.yml index 9b1f91e..32f0c55 100644 --- a/.github/workflows/make.yml +++ b/.github/workflows/make.yml @@ -24,6 +24,7 @@ jobs: matrix: os: - ubuntu-latest + - windows-latest steps: - name: Checkout @@ -32,8 +33,28 @@ jobs: submodules: true - name: Build on Linux + if: runner.os == 'Linux' shell: bash run: | set -xeuo pipefail - sudo bash -c 'apt-get update; apt-get install -y lazarus yt-dlp' >/dev/null - instantfpc -Fu/usr/lib/lazarus/*/components/lazutils .github/workflows/make.pas + 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 + delp -r "${PWD}" + + - name: Build on Windows + if: runner.os == 'Windows' + shell: powershell + run: | + New-Variable -Option Constant -Name VAR -Value @{ + Uri = 'https://fossies.org/windows/misc/lazarus-3.6-fpc-3.2.2-win64.exe' + OutFile = (New-TemporaryFile).FullName + '.exe' + } + Invoke-WebRequest @VAR + & $VAR.OutFile.Replace('Temp', 'Temp\.') /SP- /VERYSILENT /SUPPRESSMSGBOXES /NORESTART | Out-Null + $Env:PATH+=';C:\Lazarus' + (Get-Command 'lazbuild').Source | Out-Host + $Env:PATH+=';C:\Lazarus\fpc\3.2.2\bin\x86_64-win64' + (Get-Command 'instantfpc').Source | Out-Host + instantfpc '-FuC:\Lazarus\components\lazutils' .github/workflows/make.pas + (Get-Command 'delp').Source | Out-Host + delp -r $Pwd.Path From fe74849c489dc6f3fb23ef38afefbb80f4a40b61 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Sat, 18 Jan 2025 14:32:13 +0200 Subject: [PATCH 3/6] fix github-actions --- .github/workflows/make.pas | 92 +++++++++++++++----------------------- .github/workflows/make.yml | 3 +- 2 files changed, 39 insertions(+), 56 deletions(-) diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas index 32ccc8e..564f9cd 100644 --- a/.github/workflows/make.pas +++ b/.github/workflows/make.pas @@ -1,6 +1,6 @@ program Make; {$mode objfpc}{$H+} - +{$unitpath /usr/lib64/lazarus/components/lazutils} uses Classes, SysUtils, @@ -14,7 +14,7 @@ Process; const - Target: string = '.'; + Target: string = 'IntXLib.Tests'; Dependencies: array of string = (); type @@ -39,32 +39,23 @@ Output = record if FileExists('.gitmodules') then if RunCommand('git', ['submodule', 'update', '--init', '--recursive', '--force', '--remote'], Result) then - OutLog(info, Result); + OutLog(info, Result) + else + OutLog(error, Result); 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) and RunCommand('lazbuild', ['--add-package-link', Path], - Result) then - OutLog(audit, ' ' + Path); - Free; - end; + if RunCommand('lazbuild', ['--add-package-link', Path], Result) then + OutLog(audit, #9 + Path); end; function SelectString(const Input, Reg: string): string; var Line: string; begin - for Line in SplitString(Input, LineEnding) do + Result := ' '; + for Line in Input.Split(LineEnding) do with TRegExpr.Create do begin Expression := Reg; @@ -74,16 +65,30 @@ Output = record end; end; + function RunTest(const Path: String): string; + begin + OutLog(audit, #9'run:'#9 + Path); + if RunCommand(Path, ['--all', '--format=plain'], Result) then + OutLog(info, #9'success!') + else + begin + ExitCode += 1; + OutLog(error, Result); + end; + end; + function BuildProject(const Path: string): Output; begin - OutLog(audit, 'Build from ' + Path); + OutLog(audit, 'Build from:'#9 + Path); Result.Success := RunCommand('lazbuild', ['--build-all', '--recursive', '--no-write-project', Path], Result.Output); Result.Output := SelectString(Result.Output, '(Fatal:|Error:|Linking)'); if Result.Success then begin - Result.Output := SplitString(Result.Output, ' ')[2]; - OutLog(info, ' to ' + Result.Output); + Result.Output := Result.Output.Split(' ')[3].Replace(LineEnding, ''); + OutLog(info, #9'to:'#9 + Result.Output); + if ContainsStr(ReadFileToString(Path.Replace('.lpi', '.lpr')), 'consoletestrunner') then + RunTest(Result.Output.Replace(#10, '')); end else begin @@ -92,23 +97,6 @@ Output = record end; end; - function RunTest(Path: string): Output; - begin - Result := BuildProject(Path); - if Result.Success then - begin - Path := Result.Output; - OutLog(audit, 'run ' + Path); - if not RunCommand(Path, ['--all', '--format=plain'], Result.Output) then - begin - ExitCode += 1; - OutLog(error, Result.Output); - end - else - OutLog(info, ' success!'); - end; - end; - function DownloadFile(const Uri: string): string; var OutFile: TStream; @@ -139,7 +127,7 @@ Output = record OutputPath := ZipPath; Examine; UnZipAllFiles; - OutLog(audit, 'Unzip from ' + ZipFile + ' to ' + ZipPath); + OutLog(audit, 'Unzip from'#9 + ZipFile + #9'to'#9 + ZipPath); DeleteFile(ZipFile); finally Free; @@ -163,35 +151,29 @@ Output = record end; end; - procedure BuildAll; + function BuildAll: string; var - Each: string; List: TStringList; begin CheckModules; List := FindAllFiles(GetCurrentDir, '*.lpk', True); try - for Each in Dependencies do - List.AddStrings(FindAllFiles(InstallOPM(Each), '*.lpk', True)); + for Result in Dependencies do + List.AddStrings(FindAllFiles(InstallOPM(Result), '*.lpk', True)); if List.Count <> 0 then - OutLog(audit, 'Add packages: ' + IntToStr(List.Count)); - for Each in List do - AddPackage(Each); + OutLog(audit, 'Add packages:'#9 + IntToStr(List.Count)); + for Result in List do + AddPackage(Result); List := FindAllFiles(Target, '*.lpi', True); - for Each in List do - if not ContainsStr(Each, 'zengl') then - if ContainsStr(ReadFileToString(ReplaceStr(Each, '.lpi', '.lpr')), - 'consoletestrunner') then - RunTest(Each) - else - BuildProject(Each); + for Result in List do + BuildProject(Result); finally List.Free; end; case ExitCode of - 0: OutLog(info, 'Errors: ' + IntToStr(ExitCode)); + 0: OutLog(info, 'Errors:'#9 + IntToStr(ExitCode)); else - OutLog(error, 'Errors: ' + IntToStr(ExitCode)); + OutLog(error, 'Errors:'#9 + IntToStr(ExitCode)); end; end; diff --git a/.github/workflows/make.yml b/.github/workflows/make.yml index 32f0c55..4187dc2 100644 --- a/.github/workflows/make.yml +++ b/.github/workflows/make.yml @@ -38,7 +38,8 @@ jobs: 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 + instantfpc -Fu/usr/lib/lazarus/*/components/lazutils \ + -B .github/workflows/make.pas build delp -r "${PWD}" - name: Build on Windows From e0c8c90d417af57dcddbdb2b2082d07bde108be4 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Sat, 18 Jan 2025 14:46:28 +0200 Subject: [PATCH 4/6] fix github-actions --- .github/workflows/make.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/make.yml b/.github/workflows/make.yml index 4187dc2..7d95662 100644 --- a/.github/workflows/make.yml +++ b/.github/workflows/make.yml @@ -56,6 +56,6 @@ jobs: (Get-Command 'lazbuild').Source | Out-Host $Env:PATH+=';C:\Lazarus\fpc\3.2.2\bin\x86_64-win64' (Get-Command 'instantfpc').Source | Out-Host - instantfpc '-FuC:\Lazarus\components\lazutils' .github/workflows/make.pas + instantfpc '-FuC:\Lazarus\components\lazutils' -B .github/workflows/make.pas build (Get-Command 'delp').Source | Out-Host delp -r $Pwd.Path From eec98a3c1c18bc6c6e77309e3b567ecfbfd53144 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Sat, 18 Jan 2025 17:21:32 +0200 Subject: [PATCH 5/6] fix github-actions --- .github/workflows/make.pas | 12 ++++++------ .github/workflows/make.yml | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas index 564f9cd..b5006b9 100644 --- a/.github/workflows/make.pas +++ b/.github/workflows/make.pas @@ -178,10 +178,10 @@ Output = record end; begin - if ParamCount <> 0 then - case ParamStr(1) of - 'build': BuildAll; - else - OutLog(audit, 'Nothing!'); - end; + try + BuildAll + 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 index 7d95662..b6b57e2 100644 --- a/.github/workflows/make.yml +++ b/.github/workflows/make.yml @@ -39,23 +39,25 @@ jobs: set -xeuo pipefail sudo bash -c 'apt-get update; apt-get install -y lazarus' >/dev/null instantfpc -Fu/usr/lib/lazarus/*/components/lazutils \ - -B .github/workflows/make.pas build - delp -r "${PWD}" + -B '.github/workflows/make.pas' - name: Build on Windows if: runner.os == 'Windows' shell: powershell run: | + $ErrorActionPreference = 'stop' + Set-PSDebug -Strict New-Variable -Option Constant -Name VAR -Value @{ - Uri = 'https://fossies.org/windows/misc/lazarus-3.6-fpc-3.2.2-win64.exe' - OutFile = (New-TemporaryFile).FullName + '.exe' + Uri = + 'https://fossies.org/windows/misc/lazarus-3.6-fpc-3.2.2-win64.exe' + OutFile = (New-TemporaryFile).FullName + '.exe' } Invoke-WebRequest @VAR - & $VAR.OutFile.Replace('Temp', 'Temp\.') /SP- /VERYSILENT /SUPPRESSMSGBOXES /NORESTART | Out-Null + & $VAR.OutFile.Replace('Temp', 'Temp\.') /SP- /VERYSILENT /NORESTART ` + /SUPPRESSMSGBOXES | Out-Null $Env:PATH+=';C:\Lazarus' (Get-Command 'lazbuild').Source | Out-Host $Env:PATH+=';C:\Lazarus\fpc\3.2.2\bin\x86_64-win64' (Get-Command 'instantfpc').Source | Out-Host - instantfpc '-FuC:\Lazarus\components\lazutils' -B .github/workflows/make.pas build - (Get-Command 'delp').Source | Out-Host - delp -r $Pwd.Path + instantfpc -FuC:\Lazarus\components\lazutils ` + -B '.github/workflows/make.pas' From a96f9879a45daafa9e6184444118ee3faf4f9f8b Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Sun, 19 Jan 2025 19:47:05 +0200 Subject: [PATCH 6/6] Update make.pas --- .github/workflows/make.pas | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas index b5006b9..1d92a99 100644 --- a/.github/workflows/make.pas +++ b/.github/workflows/make.pas @@ -71,10 +71,8 @@ Output = record if RunCommand(Path, ['--all', '--format=plain'], Result) then OutLog(info, #9'success!') else - begin ExitCode += 1; - OutLog(error, Result); - end; + OutLog(audit, Result); end; function BuildProject(const Path: string): Output;