Skip to content

Commit 675e32f

Browse files
authored
Merge pull request #2 from theavege/upd/ci
Rewrote CI to Pascal
2 parents de1e462 + 63196bc commit 675e32f

4 files changed

Lines changed: 202 additions & 281 deletions

File tree

.github/workflows/make.pas

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
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+
Target: string = 'demos';
18+
Dependencies: array of string = ('Rhl');
19+
20+
type
21+
Output = record
22+
Code: boolean;
23+
Output: ansistring;
24+
end;
25+
26+
function CheckModules: Output;
27+
begin
28+
if FileExists('.gitmodules') then
29+
if RunCommand('git', ['submodule', 'update', '--init', '--recursive',
30+
'--force', '--remote'], Result.Output) then
31+
Writeln(stderr, #27'[33m', Result.Output, #27'[0m');
32+
end;
33+
34+
function AddPackage(Path: string): Output;
35+
begin
36+
with TRegExpr.Create do
37+
begin
38+
Expression :=
39+
{$IFDEF MSWINDOWS}
40+
'(cocoa|x11|_template)'
41+
{$ELSE}
42+
'(cocoa|gdi|_template)'
43+
{$ENDIF}
44+
;
45+
if not Exec(Path) and RunCommand('lazbuild', ['--add-package-link', Path],
46+
Result.Output) then
47+
Writeln(stderr, #27'[33m', 'added ', Path, #27'[0m');
48+
Free;
49+
end;
50+
end;
51+
52+
function BuildProject(Path: string): Output;
53+
var
54+
Line: string;
55+
begin
56+
Write(stderr, #27'[33m', 'build from ', Path, #27'[0m');
57+
try
58+
Result.Code := RunCommand('lazbuild', ['--build-all', '--recursive',
59+
'--no-write-project', Path], Result.Output);
60+
if Result.Code then
61+
for Line in SplitString(Result.Output, LineEnding) do
62+
begin
63+
if ContainsStr(Line, 'Linking') then
64+
begin
65+
Result.Output := SplitString(Line, ' ')[2];
66+
Writeln(stderr, #27'[32m', ' to ', Result.Output, #27'[0m');
67+
break;
68+
end;
69+
end
70+
else
71+
begin
72+
ExitCode += 1;
73+
for Line in SplitString(Result.Output, LineEnding) do
74+
with TRegExpr.Create do
75+
begin
76+
Expression := '(Fatal|Error):';
77+
if Exec(Line) then
78+
begin
79+
WriteLn(stderr);
80+
Writeln(stderr, #27'[31m', Line, #27'[0m');
81+
end;
82+
Free;
83+
end;
84+
end;
85+
except
86+
on E: Exception do
87+
WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message);
88+
end;
89+
end;
90+
91+
function RunTest(Path: string): Output;
92+
var
93+
Temp: string;
94+
begin
95+
Result := BuildProject(Path);
96+
Temp:= Result.Output;
97+
if Result.Code then
98+
try
99+
if not RunCommand(Temp, ['--all', '--format=plain', '--progress'], Result.Output) then
100+
ExitCode += 1;
101+
WriteLn(stderr, Result.Output);
102+
except
103+
on E: Exception do
104+
WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message);
105+
end;
106+
end;
107+
108+
function AddOPM(Each: string): string;
109+
var
110+
TempFile, Url: string;
111+
Zip: TStream;
112+
begin
113+
Result :=
114+
{$IFDEF MSWINDOWS}
115+
GetEnvironmentVariable('APPDATA') + '\.lazarus\onlinepackagemanager\packages\'
116+
{$ELSE}
117+
GetEnvironmentVariable('HOME') + '/.lazarus/onlinepackagemanager/packages/'
118+
{$ENDIF}
119+
+ Each;
120+
TempFile := GetTempFileName;
121+
Url := 'https://packages.lazarus-ide.org/' + Each + '.zip';
122+
if not DirectoryExists(Result) then
123+
begin
124+
Zip := TFileStream.Create(TempFile, fmCreate or fmOpenWrite);
125+
with TFPHttpClient.Create(nil) do
126+
begin
127+
try
128+
AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)');
129+
AllowRedirect := True;
130+
Get(Url, Zip);
131+
WriteLn(stderr, 'Download from ', Url, ' to ', TempFile);
132+
finally
133+
Free;
134+
end;
135+
end;
136+
Zip.Free;
137+
CreateDir(Result);
138+
with TUnZipper.Create do
139+
begin
140+
try
141+
FileName := TempFile;
142+
OutputPath := Result;
143+
Examine;
144+
UnZipAllFiles;
145+
WriteLn(stderr, 'Unzip from ', TempFile, ' to ', Result);
146+
finally
147+
Free;
148+
end;
149+
end;
150+
DeleteFile(TempFile);
151+
end;
152+
end;
153+
154+
procedure Main;
155+
var
156+
Each, Item: string;
157+
List: TStringList;
158+
begin
159+
CheckModules;
160+
InitSSLInterface;
161+
for Each in Dependencies do
162+
begin
163+
List := FindAllFiles(AddOPM(Each), '*.lpk', True);
164+
try
165+
for Item in List do
166+
AddPackage(Item);
167+
finally
168+
List.Free;
169+
end;
170+
end;
171+
List := FindAllFiles(GetCurrentDir, '*.lpk', True);
172+
try
173+
for Each in List do
174+
AddPackage(Each);
175+
finally
176+
List.Free;
177+
end;
178+
List := FindAllFiles(Target, '*.lpi', True);
179+
try
180+
for Each in List do
181+
if ContainsStr(ReadFileToString(ReplaceStr(Each, '.lpi', '.lpr')),
182+
'consoletestrunner') then
183+
RunTest(Each)
184+
else
185+
BuildProject(Each);
186+
finally
187+
List.Free;
188+
end;
189+
WriteLn(stderr);
190+
if ExitCode <> 0 then
191+
WriteLn(stderr, #27'[31m', 'Errors: ', ExitCode, #27'[0m')
192+
else
193+
WriteLn(stderr, #27'[32m', 'Errors: ', ExitCode, #27'[0m');
194+
end;
195+
196+
begin
197+
Main;
198+
end.

.github/workflows/make.ps1

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

0 commit comments

Comments
 (0)