Skip to content

Commit 8653571

Browse files
authored
Rewrote CI to Pascal (#4)
1 parent 691e1dc commit 8653571

5 files changed

Lines changed: 231 additions & 315 deletions

File tree

.github/workflows/make.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

.github/workflows/make.pas

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
program Make;
2+
{$mode objfpc}{$H+}
3+
4+
uses
5+
Classes,
6+
SysUtils,
7+
StrUtils,
8+
FileUtil,
9+
Zipper,
10+
fphttpclient,
11+
RegExpr,
12+
openssl,
13+
opensslsockets,
14+
Process;
15+
16+
const
17+
Src: string = 'SimpleBaseLib.Benchmark/FreePascal.Benchmark';
18+
Use: string = 'SimpleBaseLib/src/Packages/FPC/';
19+
Tst: string = 'SimpleBaseLibConsole.Tests.lpi';
20+
Pkg: array of string = ();
21+
22+
type
23+
Output = record
24+
Code: integer;
25+
Output: ansistring;
26+
end;
27+
28+
var
29+
Each, Item, PackagePath, TempFile, Url: string;
30+
Line: ansistring;
31+
Answer: Output;
32+
List: TStringList;
33+
Zip: TStream;
34+
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')
41+
else
42+
begin
43+
ExitCode += 1;
44+
Writeln(stderr, #27'[31m', Answer.Output, #27'[0m');
45+
end;
46+
end;
47+
48+
procedure AddPackage(Path: string);
49+
begin
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');
59+
end;
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
80+
begin
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;
92+
end;
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;
105+
end;
106+
end;
107+
DeleteFile(TempFile);
108+
AddPackage(PackagePath);
109+
end;
110+
end;
111+
end;
112+
113+
procedure BuildProject(Path: string);
114+
begin
115+
Write(stderr, #27'[33m', 'build from ', Each, #27'[0m');
116+
try
117+
if RunCommand('lazbuild', ['--build-all', '--recursive',
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
139+
begin
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;
151+
end
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;
172+
end;
173+
end;
174+
175+
begin
176+
CheckModules;
177+
AddPackage(Use);
178+
AddOPM;
179+
{$IFDEF LINUX}
180+
RunTest;
181+
{$ENDIF}
182+
List := FindAllFiles(Src, '*.lpi', True);
183+
try
184+
for Each in List do
185+
if Pos(Tst, Each) = 0 then
186+
begin
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
192+
begin
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;
200+
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');
206+
end;
207+
finally
208+
List.Free;
209+
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');
215+
end.

0 commit comments

Comments
 (0)