Skip to content

Commit 52af45d

Browse files
committed
fix github-actions
1 parent 451963d commit 52af45d

File tree

2 files changed

+164
-101
lines changed

2 files changed

+164
-101
lines changed

.github/workflows/make.pas

+163-100
Original file line numberDiff line numberDiff line change
@@ -8,145 +8,208 @@
88
FileUtil,
99
Zipper,
1010
fphttpclient,
11+
RegExpr,
1112
openssl,
1213
opensslsockets,
1314
Process;
1415

1516
const
16-
Src: string = 'demos';
17+
Src: string = 'Examples';
1718
Use: string = 'Package';
1819
Tst: string = 'testconsole.lpi';
1920
Pkg: array of string = ();
2021

22+
type
23+
Output = record
24+
Code: integer;
25+
Output: ansistring;
26+
end;
27+
2128
var
22-
Output, Line: ansistring;
23-
List: TStringList;
2429
Each, Item, PackagePath, TempFile, Url: string;
30+
Line: ansistring;
31+
Answer: Output;
32+
List: TStringList;
2533
Zip: TStream;
2634

27-
begin
28-
InitSSLInterface;
29-
if FileExists('.gitmodules') then
30-
if RunCommand('git', ['submodule', 'update', '--init', '--recursive',
31-
'--force', '--remote'], Output) then
32-
Writeln(#27'[33m', Output, #27'[0m')
33-
else
34-
begin
35-
ExitCode += 1;
36-
Writeln(#27'[31m', Output, #27'[0m');
37-
end;
38-
List := FindAllFiles(Use, '*.lpk', True);
39-
try
40-
for Each in List do
41-
if RunCommand('lazbuild', ['--add-package-link', Each], Output) then
42-
Writeln(#27'[33m', 'added ', Each, #27'[0m')
35+
procedure CheckModules;
36+
begin
37+
if FileExists('.gitmodules') then
38+
if RunCommand('git', ['submodule', 'update', '--init', '--recursive',
39+
'--force', '--remote'], Answer.Output) then
40+
Writeln(stderr, #27'[33m', Answer.Output, #27'[0m')
4341
else
4442
begin
4543
ExitCode += 1;
46-
Writeln(#27'[31m', 'added ', Each, #27'[0m');
44+
Writeln(stderr, #27'[31m', Answer.Output, #27'[0m');
4745
end;
48-
finally
49-
List.Free;
5046
end;
51-
for Each in Pkg do
47+
48+
procedure AddPackage(Path: string);
5249
begin
53-
PackagePath := GetEnvironmentVariable('HOME') +
54-
'/.lazarus/onlinepackagemanager/packages/' + Each;
55-
TempFile := GetTempFileName;
56-
Url := 'https://packages.lazarus-ide.org/' + Each + '.zip';
57-
if not DirectoryExists(PackagePath) then
58-
begin
59-
Zip := TFileStream.Create(TempFile, fmCreate or fmOpenWrite);
60-
with TFPHttpClient.Create(nil) do
61-
begin
62-
try
63-
AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)');
64-
AllowRedirect := True;
65-
Get(Url, Zip);
66-
WriteLn('Download from ', Url, ' to ', TempFile);
67-
finally
68-
Free;
50+
List := FindAllFiles(Use, '*.lpk', True);
51+
try
52+
for Each in List do
53+
if RunCommand('lazbuild', ['--add-package-link', Each], Answer.Output) then
54+
Writeln(stderr, #27'[33m', 'added ', Each, #27'[0m')
55+
else
56+
begin
57+
ExitCode += 1;
58+
Writeln(stderr, #27'[31m', 'added ', Each, #27'[0m');
6959
end;
70-
end;
71-
Zip.Free;
72-
CreateDir(PackagePath);
73-
with TUnZipper.Create do
60+
finally
61+
List.Free;
62+
end;
63+
end;
64+
65+
procedure AddOPM;
66+
begin
67+
InitSSLInterface;
68+
for Each in Pkg do
69+
begin
70+
PackagePath :=
71+
{$IFDEF MSWINDOWS}
72+
GetEnvironmentVariable('APPDATA') + '\.lazarus\onlinepackagemanager\packages\'
73+
{$ELSE}
74+
GetEnvironmentVariable('HOME') + '/.lazarus/onlinepackagemanager/packages/'
75+
{$ENDIF}
76+
+ Each;
77+
TempFile := GetTempFileName;
78+
Url := 'https://packages.lazarus-ide.org/' + Each + '.zip';
79+
if not DirectoryExists(PackagePath) then
7480
begin
75-
try
76-
FileName := TempFile;
77-
OutputPath := PackagePath;
78-
Examine;
79-
UnZipAllFiles;
80-
WriteLn('Unzip from ', TempFile, ' to ', PackagePath);
81-
finally
82-
Free;
81+
Zip := TFileStream.Create(TempFile, fmCreate or fmOpenWrite);
82+
with TFPHttpClient.Create(nil) do
83+
begin
84+
try
85+
AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)');
86+
AllowRedirect := True;
87+
Get(Url, Zip);
88+
WriteLn(stderr, 'Download from ', Url, ' to ', TempFile);
89+
finally
90+
Free;
91+
end;
8392
end;
84-
end;
85-
DeleteFile(TempFile);
86-
List := FindAllFiles(PackagePath, '*.lpk', True);
87-
try
88-
for Item in List do
89-
if RunCommand('lazbuild', ['--add-package-link', Item], Output) then
90-
Writeln(#27'[33m', 'added ', Item, #27'[0m')
91-
else
92-
begin
93-
ExitCode += 1;
94-
Writeln(#27'[31m', 'added ', Item, #27'[0m');
93+
Zip.Free;
94+
CreateDir(PackagePath);
95+
with TUnZipper.Create do
96+
begin
97+
try
98+
FileName := TempFile;
99+
OutputPath := PackagePath;
100+
Examine;
101+
UnZipAllFiles;
102+
WriteLn(stderr, 'Unzip from ', TempFile, ' to ', PackagePath);
103+
finally
104+
Free;
95105
end;
96-
finally
97-
List.Free;
106+
end;
107+
DeleteFile(TempFile);
108+
AddPackage(PackagePath);
98109
end;
99110
end;
100111
end;
101-
List := FindAllFiles('.', Tst, True);
102-
try
103-
for Each in List do
104-
begin
105-
Writeln(#27'[33m', 'build ', Each, #27'[0m');
112+
113+
procedure BuildProject(Path: string);
114+
begin
115+
Write(stderr, #27'[33m', 'build from ', Each, #27'[0m');
116+
try
106117
if RunCommand('lazbuild', ['--build-all', '--recursive',
107-
'--no-write-project', Each], Output) then
108-
for Line in SplitString(Output, LineEnding) do
118+
'--no-write-project', Each], Answer.Output) then
119+
Answer.Code := 0
120+
else
121+
begin
122+
Answer.Code := 1;
123+
ExitCode += Answer.Code;
124+
end;
125+
except
126+
on E: Exception do
127+
WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message);
128+
end;
129+
end;
130+
131+
procedure RunTest;
132+
begin
133+
List := FindAllFiles('.', Tst, True);
134+
try
135+
for Each in List do
136+
begin
137+
BuildProject(Each);
138+
if Answer.Code <> 0 then
109139
begin
110-
if Pos('Linking', Line) <> 0 then
111-
begin
112-
if not RunCommand('command', [SplitString(Line, ' ')[2],
113-
'--all', '--format=plain', '--progress'], Output) then
114-
ExitCode += 1;
115-
WriteLn(Output);
116-
end;
140+
for Line in SplitString(Answer.Output, LineEnding) do
141+
with TRegExpr.Create do
142+
begin
143+
Expression := '(Fatal|Error):';
144+
if Exec(Line) then
145+
begin
146+
WriteLn(stderr);
147+
Writeln(stderr, #27'[31m', Line, #27'[0m');
148+
end;
149+
Free;
150+
end;
117151
end
118-
else
119-
for Line in SplitString(Output, LineEnding) do
120-
if Pos('Fatal', Line) <> 0 or Pos('Error', Line) then
121-
Writeln(#27'[31m', Line, #27'[0m');
152+
else
153+
for Line in SplitString(Answer.Output, LineEnding) do
154+
if Pos('Linking', Line) <> 0 then
155+
try
156+
begin
157+
Writeln(stderr, #27'[32m', ' to ', SplitString(Line, ' ')[2], #27'[0m');
158+
if not RunCommand(ReplaceStr(SplitString(Line, ' ')[2],
159+
SplitString(Tst, '.')[0], './' + SplitString(Tst, '.')[0]),
160+
['--all', '--format=plain', '--progress'], Answer.Output) then
161+
ExitCode += 1;
162+
WriteLn(stderr, Answer.Output);
163+
break;
164+
end;
165+
except
166+
on E: Exception do
167+
WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message);
168+
end;
169+
end;
170+
finally
171+
List.Free;
122172
end;
123-
finally
124-
List.Free;
125173
end;
174+
175+
begin
176+
CheckModules;
177+
AddPackage(Use);
178+
AddOPM;
179+
{$IFDEF LINUX}
180+
RunTest;
181+
{$ENDIF}
126182
List := FindAllFiles(Src, '*.lpi', True);
127183
try
128184
for Each in List do
129-
begin
130-
Write(#27'[33m', 'build from ', Each, #27'[0m');
131-
if RunCommand('lazbuild', ['--build-all', '--recursive',
132-
'--no-write-project', Each], Output) then
133-
for Line in SplitString(Output, LineEnding) do
134-
begin
135-
if Pos('Linking', Line) <> 0 then
136-
Writeln(#27'[32m', ' to ', SplitString(Line, ' ')[2], #27'[0m');
137-
end
138-
else
185+
if Pos(Tst, Each) = 0 then
139186
begin
140-
ExitCode += 1;
141-
for Line in SplitString(Output, LineEnding) do
142-
if Pos('Fatal:', Line) <> 0 or Pos('Error:', Line) then
187+
BuildProject(Each);
188+
if Answer.Code <> 0 then
189+
begin
190+
for Line in SplitString(Answer.Output, LineEnding) do
191+
with TRegExpr.Create do
143192
begin
144-
WriteLn();
145-
Writeln(#27'[31m', Line, #27'[0m');
193+
Expression := '(Fatal|Error):';
194+
if Exec(Line) then
195+
begin
196+
WriteLn(stderr);
197+
Writeln(stderr, #27'[31m', Line, #27'[0m');
198+
end;
199+
Free;
146200
end;
201+
end
202+
else
203+
for Line in SplitString(Answer.Output, LineEnding) do
204+
if Pos('Linking', Line) <> 0 then
205+
Writeln(stderr, #27'[32m', ' to ', SplitString(Line, ' ')[2], #27'[0m');
147206
end;
148-
end;
149207
finally
150208
List.Free;
151209
end;
210+
WriteLn(stderr);
211+
if ExitCode <> 0 then
212+
WriteLn(stderr, #27'[31m', 'Errors: ', ExitCode, #27'[0m')
213+
else
214+
WriteLn(stderr, #27'[32m', 'Errors: ', ExitCode, #27'[0m');
152215
end.

.github/workflows/make.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ jobs:
3434
shell: bash
3535
run: |
3636
sudo bash -c 'apt-get update; apt-get install -y lazarus' >/dev/null
37-
instantfpc "-Fu/usr/lib/lazarus/3.0/components/lazutils" .github/workflows/make.pas
37+
instantfpc -Fu/usr/lib/lazarus/*/components/lazutils .github/workflows/make.pas

0 commit comments

Comments
 (0)