Skip to content

Commit 7b10a91

Browse files
authored
Merge pull request #1 from theavege/add/ci
Add CI
2 parents 9beb4f9 + 21d52a7 commit 7b10a91

File tree

4 files changed

+272
-0
lines changed

4 files changed

+272
-0
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: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
//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+
LazFileUtils,
12+
Zipper,
13+
fphttpclient,
14+
RegExpr,
15+
openssl,
16+
LazUTF8,
17+
opensslsockets,
18+
eventlog,
19+
Process;
20+
21+
function OutLog(const Knd: TEventType; const Msg: string): string; cdecl;
22+
begin
23+
case Knd of
24+
etError: OutLog := #27'[31m%s'#27'[0m';
25+
etInfo: OutLog := #27'[32m%s'#27'[0m';
26+
etDebug: OutLog := #27'[33m%s'#27'[0m';
27+
end;
28+
if Knd = etError then
29+
ExitCode += 1;
30+
Writeln(stderr, UTF8ToConsole(OutLog.Format([Msg])));
31+
end;
32+
33+
function SelectString(const Input, Reg: string): string; cdecl;
34+
var
35+
Line: string;
36+
begin
37+
SelectString := EmptyStr;
38+
with TRegExpr.Create do
39+
begin
40+
Expression := Reg;
41+
for Line in Input.Split(LineEnding) do
42+
if Exec(Line) then
43+
SelectString += Line + LineEnding;
44+
Free;
45+
end;
46+
end;
47+
48+
function AddPackage(const Path: string): string; cdecl;
49+
begin
50+
AddPackage :=
51+
{$IFDEF MSWINDOWS}
52+
'(cocoa|x11|_template)'
53+
{$ELSE}
54+
'(cocoa|gdi|_template)'
55+
{$ENDIF}
56+
;
57+
if SelectString(Path, AddPackage) = EmptyStr then
58+
if RunCommand('lazbuild', ['--add-package-link', Path], AddPackage, [poStderrToOutPut]) then
59+
OutLog(etDebug, 'Add package:'#9 + Path)
60+
else
61+
OutLog(etError, AddPackage);
62+
end;
63+
64+
function ConsoleTestRunner(const Path: String): string; cdecl;
65+
begin
66+
OutLog(etDebug, #9'Run test:'#9 + Path);
67+
if not RunCommand(Path, ['--all', '--format=plain'], ConsoleTestRunner, [poStderrToOutPut]) then
68+
OutLog(etError, ConsoleTestRunner);
69+
end;
70+
71+
function AddLibrary(const Path: String): string; cdecl;
72+
const
73+
LibPath: string = '/usr/lib/';
74+
begin
75+
OutLog(etDebug, #9'Add lib:'#9 + Path);
76+
if not FileExists(LibPath + ExtractFileName(Path)) and not RunCommand('sudo', ['cp', Path, LibPath, ';', 'ldconfig'], AddLibrary, [poStderrToOutPut]) then
77+
OutLog(etError, AddLibrary);
78+
end;
79+
80+
function BuildProject(const Path: string): string; cdecl;
81+
var
82+
Text: string;
83+
begin
84+
OutLog(etDebug, 'Build from:'#9 + Path);
85+
if RunCommand('lazbuild',
86+
['--build-all', '--recursive', '--no-write-project', Path], BuildProject, [poStderrToOutPut, poWaitOnExit]) then
87+
begin
88+
BuildProject := SelectString(BuildProject, 'Linking').Split(' ')[2].Replace(LineEnding, EmptyStr);
89+
OutLog(etInfo, #9'to:'#9 + BuildProject);
90+
Text := ReadFileToString(Path.Replace('.lpi', '.lpr'));
91+
if Text.Contains('program') and Text.Contains('consoletestrunner') then
92+
ConsoleTestRunner(BuildProject)
93+
else if Text.Contains('library') and Text.Contains('exports') then
94+
AddLibrary(BuildProject)
95+
end
96+
else
97+
OutLog(etError, SelectString(BuildProject, '(Fatal|Error):'));
98+
end;
99+
100+
function DownloadFile(const Uri: string): string; cdecl;
101+
var
102+
FileStream: TStream;
103+
begin
104+
InitSSLInterface;
105+
DownloadFile := GetTempFileName;
106+
FileStream := TFileStream.Create(DownloadFile, 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, FileStream);
113+
OutLog(etDebug, 'Download from'#9 + Uri + #9'to'#9 + DownloadFile);
114+
finally
115+
Free;
116+
FileStream.Free;
117+
end;
118+
end;
119+
end;
120+
121+
procedure UnZip(const ZipFile, ZipPath: string); cdecl;
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; cdecl;
139+
begin
140+
InstallOPM :=
141+
{$IFDEF MSWINDOWS}
142+
GetEnvironmentVariable('APPDATA')
143+
{$ELSE}
144+
GetEnvironmentVariable('HOME')
145+
{$ENDIF}
146+
+ '/.lazarus/onlinepackagemanager/packages/'.Replace('/', DirectorySeparator)
147+
+ Path;
148+
if not DirectoryExists(InstallOPM) and ForceDirectories(InstallOPM) then
149+
UnZip(DownloadFile('https://packages.lazarus-ide.org/' + Path + '.zip'), InstallOPM);
150+
end;
151+
152+
function BuildAll(const Dependencies: array of string): string;
153+
var
154+
List: TStringList;
155+
DT: TDateTime;
156+
begin
157+
// INSTALL-ENVIRONMENTS
158+
DT := Time;
159+
if FileExists('.gitmodules') then
160+
if not RunCommand('git', ['submodule', 'update', '--init', '--recursive',
161+
'--force', '--remote'], BuildAll, [poStderrToOutPut]) then
162+
OutLog(etError, BuildAll);
163+
// INSTALL-PACKAGES
164+
List := FindAllFiles(GetCurrentDir, '*.lpk');
165+
try
166+
for BuildAll in Dependencies do
167+
List.AddStrings(FindAllFiles(InstallOPM(BuildAll), '*.lpk'));
168+
List.Sort;
169+
for BuildAll in List do
170+
AddPackage(BuildAll);
171+
// BUILD-PROJECTS
172+
List := FindAllFiles(GetCurrentDir, '*.lpi');
173+
List.Sort;
174+
for BuildAll in List do
175+
if not BuildAll.Contains(DirectorySeparator + 'use' + DirectorySeparator) then
176+
BuildProject(BuildAll);
177+
finally
178+
List.Free;
179+
end;
180+
OutLog(etDebug, 'Duration:'#9'%s'#10'Errors:'#9'%s'.Format(
181+
[FormatDateTime('hh:nn:ss', Time - DT), ExitCode.ToString]
182+
));
183+
end;
184+
185+
//-------------------------------------------------------------------------------
186+
// MAIN ENDPOINT
187+
//-------------------------------------------------------------------------------
188+
189+
begin
190+
try
191+
if ParamCount > 0 then
192+
case ParamStr(1) of
193+
'build': BuildAll([]);
194+
else
195+
OutLog(etError, ParamStr(1));
196+
end;
197+
except
198+
on E: Exception do
199+
OutLog(etError, E.ClassName + #9 + E.Message);
200+
end;
201+
end.

.github/workflows/make.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env pwsh
2+
################################################################################
3+
4+
$ErrorActionPreference = 'stop'
5+
Set-PSDebug -Strict
6+
New-Variable -Option Constant -Name VAR -Value @{
7+
Uri = 'https://download.lazarus-ide.org/Lazarus%20Windows%2064%20bits/Lazarus%204.4/lazarus-4.4-fpc-3.2.2-win64.exe'
8+
OutFile = (New-TemporaryFile).FullName + '.exe'
9+
}
10+
Invoke-WebRequest @VAR
11+
& $VAR.OutFile.Replace('Temp', 'Temp\.') /SP- /VERYSILENT /NORESTART `
12+
/SUPPRESSMSGBOXES | Out-Null
13+
$Env:PATH+=';C:\Lazarus'
14+
(Get-Command 'lazbuild').Source | Out-Host
15+
$Env:PATH+=';C:\Lazarus\fpc\3.2.2\bin\x86_64-win64'
16+
(Get-Command 'instantfpc').Source | Out-Host
17+
$Env:INSTANTFPCOPTIONS='-FuC:\Lazarus\components\lazutils'
18+
& instantfpc '.github/workflows/make.pas' build | Out-Host
19+
Exit $LastExitCode

.github/workflows/make.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
- main
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
make:
20+
runs-on: ${{ matrix.os }}
21+
timeout-minutes: 120
22+
strategy:
23+
matrix:
24+
os:
25+
# - ubuntu-latest
26+
- windows-latest
27+
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
submodules: true
33+
34+
- name: Build
35+
if: runner.os != 'Windows'
36+
shell: bash
37+
run: |
38+
sudo bash -c 'apt-get update; apt-get install -y lazarus' >/dev/null
39+
declare -rx INSTANTFPCOPTIONS='-Fu/usr/lib/lazarus/*/components/lazutils'
40+
instantfpc '.github/workflows/make.pas' build
41+
42+
- name: Build on Windows
43+
if: runner.os == 'Windows'
44+
shell: powershell
45+
run: pwsh -File .github/workflows/make.ps1

0 commit comments

Comments
 (0)