Skip to content

Commit 3f094b3

Browse files
authored
Merge pull request #8 from theavege/add/github-actions
Add/GitHub actions
2 parents 58a7d12 + 7a4c9bb commit 3f094b3

File tree

4 files changed

+258
-2
lines changed

4 files changed

+258
-2
lines changed

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 2
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "monthly"

.github/workflows/make.pas

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
//https://castle-engine.io/modern_pascal
2+
3+
program Make;
4+
{$mode objfpc}{$H+}
5+
6+
uses
7+
Classes,
8+
SysUtils,
9+
StrUtils,
10+
FileUtil,
11+
Zipper,
12+
fphttpclient,
13+
RegExpr,
14+
openssl,
15+
LazUTF8,
16+
opensslsockets,
17+
eventlog,
18+
Process;
19+
20+
function OutLog(const Knd: TEventType; const Msg: string): string;
21+
begin
22+
case Knd of
23+
etError: Result := #27'[31m%s'#27'[0m';
24+
etInfo: Result := #27'[32m%s'#27'[0m';
25+
etDebug: Result := #27'[33m%s'#27'[0m';
26+
end;
27+
Writeln(stderr, UTF8ToConsole(Result.Format([Msg])));
28+
end;
29+
30+
function AddPackage(const Path: string): string;
31+
begin
32+
if RunCommand('lazbuild', ['--add-package-link', Path], Result, [poStderrToOutPut]) then
33+
OutLog(etDebug, 'Add package:'#9 + Path)
34+
else
35+
begin
36+
ExitCode += 1;
37+
OutLog(etError, Result);
38+
end;
39+
end;
40+
41+
function SelectString(const Input, Reg: string): string;
42+
var
43+
Line: string;
44+
begin
45+
Result := EmptyStr;
46+
with TRegExpr.Create do
47+
begin
48+
Expression := Reg;
49+
for Line in Input.Split(LineEnding) do
50+
if Exec(Line) then
51+
Result += Line + LineEnding;
52+
Free;
53+
end;
54+
end;
55+
56+
function RunTest(const Path: String): string;
57+
begin
58+
OutLog(etDebug, #9'run:'#9 + Path);
59+
if RunCommand(Path, ['--all', '--format=plain'], Result, [poStderrToOutPut]) then
60+
OutLog(etInfo, #9'success!')
61+
else
62+
begin
63+
ExitCode += 1;
64+
OutLog(etError, Result);
65+
end;
66+
end;
67+
68+
function AddDDL(const Path: String): string;
69+
begin
70+
OutLog(etDebug, #9'add:'#9 + Path);
71+
if RunCommand('sudo', ['bash', '-c', 'cp %s /usr/lib/; ldconfig --verbose'.Format([Path])], Result, [poStderrToOutPut]) then
72+
OutLog(etInfo, #9'success!')
73+
else
74+
begin
75+
ExitCode += 1;
76+
OutLog(etError, Result);
77+
end;
78+
end;
79+
80+
function BuildProject(const Path: string): string;
81+
begin
82+
OutLog(etDebug, 'Build from:'#9 + Path);
83+
if RunCommand('lazbuild',
84+
['--build-all', '--recursive', '--no-write-project', Path], Result, [poStderrToOutPut]) then
85+
begin
86+
Result := SelectString(Result, 'Linking').Split(' ')[2].Replace(LineEnding, EmptyStr);
87+
OutLog(etInfo, #9'to:'#9 + Result);
88+
if ReadFileToString(Path.Replace('.lpi', '.lpr')).Contains('consoletestrunner') then
89+
RunTest(Result)
90+
else if ReadFileToString(Path.Replace('.lpi', '.lpr')).Contains('exports') then
91+
AddDDL(Result)
92+
end
93+
else
94+
begin
95+
ExitCode += 1;
96+
OutLog(etError, SelectString(Result, '(Fatal|Error):'));
97+
end;
98+
end;
99+
100+
function DownloadFile(const Uri: string): string;
101+
var
102+
OutFile: TStream;
103+
begin
104+
InitSSLInterface;
105+
Result := GetTempFileName;
106+
OutFile := TFileStream.Create(Result, fmCreate or fmOpenWrite);
107+
with TFPHttpClient.Create(nil) do
108+
begin
109+
try
110+
AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)');
111+
AllowRedirect := True;
112+
Get(Uri, OutFile);
113+
OutLog(etDebug, 'Download from %s to %s'.Format([Uri, Result]));
114+
finally
115+
Free;
116+
OutFile.Free;
117+
end;
118+
end;
119+
end;
120+
121+
procedure UnZip(const ZipFile, ZipPath: string);
122+
begin
123+
with TUnZipper.Create do
124+
begin
125+
try
126+
FileName := ZipFile;
127+
OutputPath := ZipPath;
128+
Examine;
129+
UnZipAllFiles;
130+
OutLog(etDebug, 'Unzip from'#9 + ZipFile + #9'to'#9 + ZipPath);
131+
DeleteFile(ZipFile);
132+
finally
133+
Free;
134+
end;
135+
end;
136+
end;
137+
138+
function InstallOPM(const Path: string): string;
139+
begin
140+
Result :=
141+
{$IFDEF MSWINDOWS}
142+
GetEnvironmentVariable('APPDATA') + '\.lazarus\onlinepackagemanager\packages\'
143+
{$ELSE}
144+
GetEnvironmentVariable('HOME') + '/.lazarus/onlinepackagemanager/packages/'
145+
{$ENDIF}
146+
+ Path;
147+
if not DirectoryExists(Result) then
148+
begin
149+
if ForceDirectories(Result) then
150+
UnZip(DownloadFile('https://packages.lazarus-ide.org/%s.zip'.Format([Path])), Result);
151+
end;
152+
end;
153+
154+
function BuildAll(const Target: string; const Dependencies: array of string): string;
155+
var
156+
List: TStringList;
157+
DT: TDateTime;
158+
begin
159+
DT := Time;
160+
if FileExists('.gitmodules') then
161+
if RunCommand('git', ['submodule', 'update', '--init', '--recursive',
162+
'--force', '--remote'], Result, [poStderrToOutPut]) then
163+
OutLog(etInfo, Result)
164+
else
165+
begin
166+
ExitCode += 1;
167+
OutLog(etError, Result);
168+
end;
169+
List := FindAllFiles(GetCurrentDir, '*.lpk');
170+
try
171+
for Result in Dependencies do
172+
List.AddStrings(FindAllFiles(InstallOPM(Result), '*.lpk'));
173+
for Result in List do
174+
AddPackage(Result);
175+
List := FindAllFiles(Target, '*.lpi');
176+
List.Sort;
177+
for Result in List do
178+
if not Result.Contains('backup') then
179+
BuildProject(Result);
180+
finally
181+
List.Free;
182+
end;
183+
if not RunCommand('delp', ['-r', GetCurrentDir], Result, [poStderrToOutPut]) then
184+
OutLog(etError, Result);
185+
OutLog(etDebug, 'Duration:'#9 + FormatDateTime('hh:nn:ss', DT - Time));
186+
end;
187+
188+
begin
189+
try
190+
BuildAll('demos', []);
191+
case ExitCode of
192+
0: OutLog(etInfo, 'Errors:'#9 + ExitCode.ToString);
193+
else
194+
OutLog(etError, 'Errors:'#9 + ExitCode.ToString);
195+
end;
196+
except
197+
on E: Exception do
198+
Writeln(E.ClassName, #9, E.Message);
199+
end;
200+
end.

.github/workflows/make.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
name: Make
3+
4+
on:
5+
schedule:
6+
- cron: '0 0 1 * *'
7+
push:
8+
branches:
9+
- "**"
10+
pull_request:
11+
branches:
12+
- master
13+
- main
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
build:
21+
runs-on: ${{ matrix.os }}
22+
timeout-minutes: 120
23+
strategy:
24+
matrix:
25+
os:
26+
- ubuntu-latest
27+
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
submodules: true
33+
34+
- name: Build on Linux
35+
shell: bash
36+
run: |
37+
set -xeuo pipefail
38+
sudo bash -c '
39+
apt-get update
40+
apt-get -y install lazarus lib{sdl2,glfw3}-dev
41+
' >/dev/null
42+
instantfpc -Fu/usr/lib/lazarus/*/components/lazutils \
43+
-B '.github/workflows/make.pas'

demos/00_addons/01_Simple/Game.lps

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<Unit0>
88
<Filename Value="Game.lpr"/>
99
<IsPartOfProject Value="True"/>
10+
<EditorIndex Value="-1"/>
11+
<CursorPos Y="15"/>
1012
<UsageCount Value="20"/>
1113
</Unit0>
1214
<Unit1>
@@ -73,6 +75,7 @@
7375
</Unit8>
7476
<Unit9>
7577
<Filename Value="../../../source/phxSimpleXML.pas"/>
78+
<IsVisibleTab Value="True"/>
7679
<EditorIndex Value="5"/>
7780
<TopLine Value="556"/>
7881
<CursorPos X="41" Y="568"/>
@@ -89,15 +92,14 @@
8992
</Unit10>
9093
<Unit11>
9194
<Filename Value="../../../source/providers/graphics/phxOpenGL_SDL2.pas"/>
92-
<IsVisibleTab Value="True"/>
9395
<EditorIndex Value="4"/>
9496
<TopLine Value="8"/>
9597
<CursorPos Y="8"/>
9698
<UsageCount Value="10"/>
9799
<Loaded Value="True"/>
98100
</Unit11>
99101
</Units>
100-
<JumpHistory Count="26" HistoryIndex="25">
102+
<JumpHistory Count="27" HistoryIndex="26">
101103
<Position1>
102104
<Filename Value="../../../source/phxTypes.pas"/>
103105
<Caret Line="3094" Column="30" TopLine="3083"/>
@@ -202,6 +204,10 @@
202204
<Filename Value="../../../source/phxConfig.inc"/>
203205
<Caret Line="31" Column="3" TopLine="17"/>
204206
</Position26>
207+
<Position27>
208+
<Filename Value="../../../source/providers/graphics/phxOpenGL_SDL2.pas"/>
209+
<Caret Line="8" TopLine="8"/>
210+
</Position27>
205211
</JumpHistory>
206212
<RunParams>
207213
<FormatVersion Value="2"/>

0 commit comments

Comments
 (0)