From 12a40462654c39361f71ba370651417c3cd09e1a Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Mon, 13 Jan 2025 20:57:31 +0200 Subject: [PATCH 1/3] Rewrote CI to Pascal --- .github/workflows/make.pas | 149 ++++++++++++++++++++++++++++++++++ .github/workflows/make.ps1 | 159 ------------------------------------- .github/workflows/make.sh | 93 ---------------------- .github/workflows/make.yml | 20 +---- 4 files changed, 153 insertions(+), 268 deletions(-) create mode 100644 .github/workflows/make.pas delete mode 100644 .github/workflows/make.ps1 delete mode 100644 .github/workflows/make.sh diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas new file mode 100644 index 0000000..82ae320 --- /dev/null +++ b/.github/workflows/make.pas @@ -0,0 +1,149 @@ +program Make; +{$mode objfpc}{$H+} + +uses + Classes, + SysUtils, + StrUtils, + FileUtil, + Zipper, + fphttpclient, + openssl, + opensslsockets, + Process; + +const + Src: string = 'src'; + Use: string = 'use'; + Tst: string = 'testconsole.lpi'; + Pkg: array of string = ('PlaysoundPackage', 'Rx', 'FPSpreadsheet', 'ZeosDBO'); + +var + Output, Line: ansistring; + List: TStringList; + Each, Item, PackagePath, TempFile, Url: string; + Zip: TStream; + +begin + InitSSLInterface; + if FileExists('.gitmodules') then + if RunCommand('git', ['submodule', 'update', '--init', '--recursive', + '--force', '--remote'], Output) then + Writeln(#27'[33m', Output, #27'[0m') + else + begin + ExitCode += 1; + Writeln(#27'[31m', Output, #27'[0m'); + end; + List := FindAllFiles(Use, '*.lpk', True); + try + for Each in List do + if RunCommand('lazbuild', ['--add-package-link', Each], Output) then + Writeln(#27'[33m', 'added ', Each, #27'[0m') + else + begin + ExitCode += 1; + Writeln(#27'[31m', 'added ', Each, #27'[0m'); + end; + finally + List.Free; + end; + for Each in Pkg do + begin + PackagePath := GetEnvironmentVariable('HOME') + + '/.lazarus/onlinepackagemanager/packages/' + Each; + TempFile := GetTempFileName; + Url := 'https://packages.lazarus-ide.org/' + Each + '.zip'; + if not DirectoryExists(PackagePath) 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('Download from ', Url, ' to ', TempFile); + finally + Free; + end; + end; + Zip.Free; + CreateDir(PackagePath); + with TUnZipper.Create do + begin + try + FileName := TempFile; + OutputPath := PackagePath; + Examine; + UnZipAllFiles; + WriteLn('Unzip from ', TempFile, ' to ', PackagePath); + finally + Free; + end; + end; + DeleteFile(TempFile); + List := FindAllFiles(PackagePath, '*.lpk', True); + try + for Item in List do + if RunCommand('lazbuild', ['--add-package-link', Item], Output) then + Writeln(#27'[33m', 'added ', Item, #27'[0m') + else + begin + ExitCode += 1; + Writeln(#27'[31m', 'added ', Item, #27'[0m'); + end; + finally + List.Free; + end; + end; + end; + List := FindAllFiles('.', Tst, True); + try + for Each in List do + begin + Writeln(#27'[33m', 'build ', Each, #27'[0m'); + if RunCommand('lazbuild', ['--build-all', '--recursive', + '--no-write-project', Each], Output) then + for Line in SplitString(Output, LineEnding) do + begin + if Pos('Linking', Line) <> 0 then + begin + if not RunCommand('command', [SplitString(Line, ' ')[2], + '--all', '--format=plain', '--progress'], Output) then + ExitCode += 1; + WriteLn(Output); + end; + end + else + for Line in SplitString(Output, LineEnding) do + if Pos('Fatal', Line) <> 0 and Pos('Error', Line) then + Writeln(#27'[31m', Line, #27'[0m'); + end; + finally + List.Free; + end; + List := FindAllFiles(Src, '*.lpi', True); + try + for Each in List do + begin + Write(#27'[33m', 'build from ', Each, #27'[0m'); + if RunCommand('lazbuild', ['--build-all', '--recursive', + '--no-write-project', Each], Output) then + for Line in SplitString(Output, LineEnding) do + begin + if Pos('Linking', Line) <> 0 then + Writeln(#27'[32m', ' to ', SplitString(Line, ' ')[2], #27'[0m'); + end + else + begin + ExitCode += 1; + for Line in SplitString(Output, LineEnding) do + if Pos('Fatal', Line) <> 0 or Pos('Error', Line) then + Writeln(#27'[31m', Line, #27'[0m'); + end; + end; + finally + List.Free; + end; +end. diff --git a/.github/workflows/make.ps1 b/.github/workflows/make.ps1 deleted file mode 100644 index f89185d..0000000 --- a/.github/workflows/make.ps1 +++ /dev/null @@ -1,159 +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 @{ - Src = 'src' - Use = 'use' - Pkg = 'use\components.txt' - } - If (! (Test-Path -Path $Var.Src)) { - 'Source do not find!' | Out-Host - Exit 1 - } - If (Test-Path -Path '.gitmodules') { - & git submodule update --init --recursive --force --remote | Out-Host - ".... [[$($LastExitCode)]] git submodule update" | 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)" - (Get-Command $_.Cmd).Source | Out-Host - } - If (Test-Path -Path $VAR.Use) { - If (Test-Path -Path $VAR.Pkg) { - Get-Content -Path $VAR.Pkg | - Where-Object { - ! (Test-Path -Path "$($VAR.Use)\$($_)") && - ! (& lazbuild --verbose-pkgsearch $_ ) && - ! (& lazbuild --add-package $_) - } | ForEach-Object { - Return @{ - Uri = "https://packages.lazarus-ide.org/$($_).zip" - Path = "$($VAR.Use)\$($_)" - OutFile = (New-TemporaryFile).FullName - } - } | ForEach-Object -Parallel { - Invoke-WebRequest -OutFile $_.OutFile -Uri $_.Uri - Expand-Archive -Path $_.OutFile -DestinationPath $_.Path - Remove-Item $_.OutFile - Return ".... download $($_.Uri)" - } | Out-Host - } - (Get-ChildItem -Filter '*.lpk' -Recurse -File –Path $VAR.Use).FullName | - ForEach-Object { - & lazbuild --add-package-link $_ | Out-Null - Return ".... [$($LastExitCode)] add package link $($_)" - } | Out-Host - } - Exit ( - (Get-ChildItem -Filter '*.lpi' -Recurse -File –Path $Var.Src).FullName | - Sort-Object | - ForEach-Object { - $Output = (& lazbuild --build-all --recursive --no-write-project --build-mode='release' $_) - $Result = @(".... [$($LastExitCode)] build project $($_)") - $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 -Name VAR -Option Constant -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 { - Return @{ - Method = 'POST' - Headers = @{ - ContentType = 'application/json' - } - Uri = 'https://postman-echo.com/post' - Body = @{ - One = '1' - } | ConvertTo-Json - } - } - Falce { - Return @{ - 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]) { - '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 15c8b18..0000000 --- a/.github/workflows/make.sh +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env bash -############################################################################################################## - -function priv_clippit -( - cat <&2 - fi - declare -i errors=0 - while read -r; do - declare -A TMP=( - [out]=$(mktemp) - ) - if (lazbuild --build-all --recursive --no-write-project --build-mode='release' --widgetset='qt5' "${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]}" - ((errors+=1)) - fi 1>&2 - rm "${TMP[out]}" - done < <(find "${VAR[src]}" -type 'f' -name '*.lpi' | sort) - exit "${errors}" -) - -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..a90dc85 100644 --- a/.github/workflows/make.yml +++ b/.github/workflows/make.yml @@ -24,26 +24,14 @@ jobs: matrix: os: - ubuntu-latest - - windows-latest steps: - name: Checkout uses: actions/checkout@v4 with: submodules: true - - name: Build on Linux - if: runner.os == 'Linux' + - name: Build 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: | + sudo bash -c 'apt-get update; apt-get install -y lazarus' >/dev/null + instantfpc "-Fu/usr/lib/lazarus/3.0/components/lazutils" .github/workflows/make.pas From 2aca3b0eb7761a276fed4624b3a5cb1abac45df9 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Mon, 13 Jan 2025 21:00:24 +0200 Subject: [PATCH 2/3] Rewrote CI to Pascal --- .github/workflows/make.pas | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas index 82ae320..03d6daa 100644 --- a/.github/workflows/make.pas +++ b/.github/workflows/make.pas @@ -117,7 +117,7 @@ end else for Line in SplitString(Output, LineEnding) do - if Pos('Fatal', Line) <> 0 and Pos('Error', Line) then + if Pos('Fatal', Line) <> 0 or Pos('Error', Line) then Writeln(#27'[31m', Line, #27'[0m'); end; finally @@ -140,6 +140,7 @@ ExitCode += 1; for Line in SplitString(Output, LineEnding) do if Pos('Fatal', Line) <> 0 or Pos('Error', Line) then + WriteLn(); Writeln(#27'[31m', Line, #27'[0m'); end; end; From 0ac4abbce1de0bad74bd967e79ce2ed88733a1a5 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Mon, 13 Jan 2025 21:06:11 +0200 Subject: [PATCH 3/3] Rewrote CI to Pascal --- .github/workflows/make.pas | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas index 03d6daa..adaa1d0 100644 --- a/.github/workflows/make.pas +++ b/.github/workflows/make.pas @@ -140,8 +140,10 @@ ExitCode += 1; for Line in SplitString(Output, LineEnding) do if Pos('Fatal', Line) <> 0 or Pos('Error', Line) then - WriteLn(); - Writeln(#27'[31m', Line, #27'[0m'); + begin + WriteLn(); + Writeln(#27'[31m', Line, #27'[0m'); + end; end; end; finally