Skip to content

Commit

Permalink
fix github-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
theavege committed Jan 15, 2025
1 parent 4b3d374 commit b639eac
Showing 1 changed file with 141 additions and 158 deletions.
299 changes: 141 additions & 158 deletions .github/workflows/make.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,202 +14,185 @@
Process;

const
Src: string = 'demos';
Use: string = 'packages';
Tst: string = 'testconsole.lpi';
Pkg: array of string = ();
Target: string = '.';
Dependencies: array of string = ('Rhl');

type
Output = record
Code: integer;
Code: boolean;
Output: ansistring;
end;

var
Each, Item, PackagePath, TempFile, Url: string;
Line: ansistring;
Answer: Output;
List: TStringList;
Zip: TStream;

procedure CheckModules;
function CheckModules: Output;
begin
if FileExists('.gitmodules') then
if RunCommand('git', ['submodule', 'update', '--init', '--recursive',
'--force', '--remote'], Answer.Output) then
Writeln(stderr, #27'[33m', Answer.Output, #27'[0m')
else
begin
ExitCode += 1;
Writeln(stderr, #27'[31m', Answer.Output, #27'[0m');
end;
'--force', '--remote'], Result.Output) then
Writeln(stderr, #27'[33m', Result.Output, #27'[0m');
end;

procedure AddPackage(Path: string);
function AddPackage(Path: string): Output;
begin
List := FindAllFiles(Use, '*.lpk', True);
try
for Each in List do
if RunCommand('lazbuild', ['--add-package-link', Each], Answer.Output) then
Writeln(stderr, #27'[33m', 'added ', Each, #27'[0m')
else
begin
ExitCode += 1;
Writeln(stderr, #27'[31m', 'added ', Each, #27'[0m');
end;
finally
List.Free;
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;

procedure AddOPM;
function BuildProject(Path: string): Output;
var
Line: string;
begin
InitSSLInterface;
for Each in Pkg do
begin
PackagePath :=
{$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(PackagePath) then
begin
Zip := TFileStream.Create(TempFile, fmCreate or fmOpenWrite);
with TFPHttpClient.Create(nil) do
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
try
AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)');
AllowRedirect := True;
Get(Url, Zip);
WriteLn(stderr, 'Download from ', Url, ' to ', TempFile);
finally
Free;
if ContainsStr(Line, 'Linking') then
begin
Result.Output := SplitString(Line, ' ')[2];
Writeln(stderr, #27'[32m', ' to ', Result.Output, #27'[0m');
break;
end;
end;
Zip.Free;
CreateDir(PackagePath);
with TUnZipper.Create do
begin
try
FileName := TempFile;
OutputPath := PackagePath;
Examine;
UnZipAllFiles;
WriteLn(stderr, 'Unzip from ', TempFile, ' to ', PackagePath);
finally
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;
DeleteFile(TempFile);
AddPackage(PackagePath);
end;
except
on E: Exception do
WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message);
end;
end;

procedure BuildProject(Path: string);
function RunTest(Path: string): Output;
var
Temp: string;
begin
Write(stderr, #27'[33m', 'build from ', Each, #27'[0m');
try
if RunCommand('lazbuild', ['--build-all', '--recursive',
'--no-write-project', Each], Answer.Output) then
Answer.Code := 0
else
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
Answer.Code := 1;
ExitCode += Answer.Code;
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;
except
on E: Exception do
WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message);
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;

procedure RunTest;
procedure Main;
var
Each, Item: string;
List: TStringList;
begin
List := FindAllFiles('.', Tst, True);
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
begin
BuildProject(Each);
if Answer.Code <> 0 then
begin
for Line in SplitString(Answer.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
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
for Line in SplitString(Answer.Output, LineEnding) do
if Pos('Linking', Line) <> 0 then
try
begin
Writeln(stderr, #27'[32m', ' to ', SplitString(Line, ' ')[2], #27'[0m');
if not RunCommand(ReplaceStr(SplitString(Line, ' ')[2],
SplitString(Tst, '.')[0], './' + SplitString(Tst, '.')[0]),
['--all', '--format=plain', '--progress'], Answer.Output) then
ExitCode += 1;
WriteLn(stderr, Answer.Output);
break;
end;
except
on E: Exception do
WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message);
end;
end;
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
CheckModules;
AddPackage(Use);
AddOPM;
{$IFDEF LINUX}
RunTest;
{$ENDIF}
List := FindAllFiles(Src, '*.lpi', True);
try
for Each in List do
if Pos(Tst, Each) = 0 then
begin
BuildProject(Each);
if Answer.Code <> 0 then
begin
for Line in SplitString(Answer.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
else
for Line in SplitString(Answer.Output, LineEnding) do
if Pos('Linking', Line) <> 0 then
Writeln(stderr, #27'[32m', ' to ', SplitString(Line, ' ')[2], #27'[0m');
end;
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');
Main;
end.

0 comments on commit b639eac

Please sign in to comment.