Skip to content

Commit 9cfd284

Browse files
authored
Add/GitHub actions (#56)
* add github-actions * fix github-actions * fix github-actions * fix github-actions
1 parent 9d7b784 commit 9cfd284

File tree

4 files changed

+321
-0
lines changed

4 files changed

+321
-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.ps1

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#!/usr/bin/env pwsh
2+
##############################################################################################################
3+
4+
Function Show-Usage {
5+
"
6+
vagrant = 'it-gro/win10-ltsc-eval'
7+
download = 'https://microsoft.com/en-us/evalcenter'
8+
package = 'https://learn.microsoft.com/en-us/mem/configmgr/develop/apps/how-to-create-the-windows-installer-file-msi'
9+
shell = 'https://learn.microsoft.com/en-us/powershell'
10+
11+
Usage: pwsh -File $($PSCommandPath) [OPTIONS]
12+
Options:
13+
build
14+
lint
15+
" | Out-Host
16+
}
17+
18+
Function Build-Project {
19+
New-Variable -Option Constant -Name VAR -Value @{
20+
Src = 'Examples'
21+
Use = 'Package'
22+
Pkg = 'Package\components.txt'
23+
}
24+
If (! (Test-Path -Path $Var.Src)) {
25+
"$([char]27)[31m.... Source do not find!$([char]27)[0m" | Out-Host
26+
Exit 1
27+
}
28+
If (Test-Path -Path '.gitmodules') {
29+
& git submodule update --init --recursive --force --remote | Out-Host
30+
"$([char]27)[32m.... [[$($LastExitCode)]] git submodule update$([char]27)[0m" | Out-Host
31+
}
32+
@(
33+
@{
34+
Cmd = 'lazbuild'
35+
Url = 'https://fossies.org/windows/misc/lazarus-3.6-fpc-3.2.2-win64.exe'
36+
Path = "C:\Lazarus"
37+
}
38+
) | Where-Object { ! (Test-Path -Path $_.Path) } |
39+
ForEach-Object {
40+
$_.Url | Request-File | Install-Program
41+
$Env:PATH+=";$($_.Path)"
42+
(Get-Command $_.Cmd).Source | Out-Host
43+
}
44+
If (Test-Path -Path $VAR.Use) {
45+
If (Test-Path -Path $VAR.Pkg) {
46+
Get-Content -Path $VAR.Pkg |
47+
Where-Object {
48+
! (Test-Path -Path "$($VAR.Use)\$($_)") &&
49+
! (& lazbuild --verbose-pkgsearch $_ ) &&
50+
! (& lazbuild --add-package $_)
51+
} | ForEach-Object {
52+
Return @{
53+
Uri = "https://packages.lazarus-ide.org/$($_).zip"
54+
Path = "$($VAR.Use)\$($_)"
55+
OutFile = (New-TemporaryFile).FullName
56+
}
57+
} | ForEach-Object -Parallel {
58+
Invoke-WebRequest -OutFile $_.OutFile -Uri $_.Uri
59+
Expand-Archive -Path $_.OutFile -DestinationPath $_.Path
60+
Remove-Item $_.OutFile
61+
Return "$([char]27)[32m.... download $($_.Uri)$([char]27)[0m"
62+
} | Out-Host
63+
}
64+
(Get-ChildItem -Filter '*.lpk' -Recurse -File –Path $VAR.Use).FullName |
65+
ForEach-Object {
66+
& lazbuild --add-package-link $_ | Out-Null
67+
Return "$([char]27)[32m.... [$($LastExitCode)] add package link $($_)$([char]27)[0m"
68+
} | Out-Host
69+
}
70+
Exit (
71+
(Get-ChildItem -Filter '*.lpi' -Recurse -File –Path $Var.Src).FullName |
72+
Sort-Object |
73+
ForEach-Object {
74+
$Output = (& lazbuild --build-all --recursive --no-write-project $_)
75+
$Result = @("$([char]27)[32m.... [$($LastExitCode)] build project $($_)$([char]27)[0m")
76+
$exitCode = Switch ($LastExitCode) {
77+
0 {
78+
$Result += $Output | Select-String -Pattern 'Linking'
79+
0
80+
}
81+
Default {
82+
$Result += $Output | Select-String -Pattern 'Error:', 'Fatal:'
83+
1
84+
}
85+
}
86+
$Result | Out-Host
87+
Return $exitCode
88+
} | Measure-Object -Sum
89+
).Sum
90+
}
91+
92+
Function Request-File {
93+
While ($Input.MoveNext()) {
94+
New-Variable -Option Constant -Name VAR -Value @{
95+
Uri = $Input.Current
96+
OutFile = (Split-Path -Path $Input.Current -Leaf).Split('?')[0]
97+
}
98+
Invoke-WebRequest @VAR
99+
Return $VAR.OutFile
100+
}
101+
}
102+
103+
Function Install-Program {
104+
While ($Input.MoveNext()) {
105+
Switch ((Split-Path -Path $Input.Current -Leaf).Split('.')[-1]) {
106+
'msi' {
107+
& msiexec /passive /package $Input.Current | Out-Null
108+
}
109+
Default {
110+
& ".\$($Input.Current)" /SP- /VERYSILENT /SUPPRESSMSGBOXES /NORESTART | Out-Null
111+
}
112+
}
113+
Remove-Item $Input.Current
114+
}
115+
}
116+
117+
Function Request-URL([Switch] $Post) {
118+
$VAR = Switch ($Post) {
119+
True {
120+
Return @{
121+
Method = 'POST'
122+
Headers = @{
123+
ContentType = 'application/json'
124+
}
125+
Uri = 'https://postman-echo.com/post'
126+
Body = @{
127+
One = '1'
128+
} | ConvertTo-Json
129+
}
130+
}
131+
False {
132+
Return @{
133+
Uri = 'https://postman-echo.com/get'
134+
}
135+
}
136+
}
137+
Return (Invoke-WebRequest @VAR | ConvertFrom-Json).Headers
138+
}
139+
140+
Function Switch-Action {
141+
$ErrorActionPreference = 'stop'
142+
Set-PSDebug -Strict #-Trace 1
143+
Invoke-ScriptAnalyzer -EnableExit -Path $PSCommandPath
144+
If ($args.count -gt 0) {
145+
Switch ($args[0]) {
146+
'lint' {
147+
Invoke-ScriptAnalyzer -EnableExit -Recurse -Path '.'
148+
(Get-ChildItem -Filter '*.ps1' -Recurse -Path '.').FullName |
149+
ForEach-Object {
150+
Invoke-Formatter -ScriptDefinition $(Get-Content -Path $_ | Out-String) |
151+
Set-Content -Path $_
152+
}
153+
}
154+
'build' {
155+
Build-Project
156+
}
157+
Default {
158+
Show-Usage
159+
}
160+
}
161+
} Else {
162+
Show-Usage
163+
}
164+
}
165+
166+
##############################################################################################################
167+
Switch-Action @args

.github/workflows/make.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env bash
2+
##############################################################################################################
3+
4+
function priv_clippit
5+
(
6+
cat <<EOF
7+
https://google.github.io/styleguide/shellguide.html
8+
https://guide.bash.academy
9+
https://devhints.io/bash
10+
https://tldr.sh
11+
12+
Usage: bash ${0} [OPTIONS]
13+
Options:
14+
build Build program
15+
EOF
16+
)
17+
18+
function priv_lazbuild
19+
(
20+
declare -rA VAR=(
21+
[src]='Examples'
22+
[use]='Package'
23+
[pkg]='Package/components.txt'
24+
)
25+
if ! [[ -d "${VAR[src]}" ]]; then
26+
printf '\x1b[31m\tSource do not find!\x1b[0m\n'
27+
exit 1
28+
fi
29+
if [[ -f '.gitmodules' ]]; then
30+
git submodule update --init --recursive --force --remote &
31+
fi
32+
if ! (command -v lazbuild); then
33+
source '/etc/os-release'
34+
case ${ID:?} in
35+
debian | ubuntu)
36+
sudo apt-get update
37+
sudo apt-get install -y lazarus{-ide-qt5,} &
38+
;;
39+
esac
40+
fi
41+
wait
42+
if [[ -d "${VAR[use]}" ]]; then
43+
if [[ -f "${VAR[pkg]}" ]]; then
44+
while read -r; do
45+
if [[ -n "${REPLY}" ]] &&
46+
! [[ -d "${VAR[use]}/${REPLY}" ]] &&
47+
! (lazbuild --verbose-pkgsearch "${REPLY}") &&
48+
! (lazbuild --add-package "${REPLY}"); then
49+
(
50+
declare -A TMP=(
51+
[url]="https://packages.lazarus-ide.org/${REPLY}.zip"
52+
[dir]="${VAR[use]}/${REPLY}"
53+
[out]=$(mktemp)
54+
)
55+
wget --quiet --output-document "${TMP[out]}" "${TMP[url]}"
56+
unzip -o "${TMP[out]}" -d "${TMP[dir]}"
57+
rm --verbose "${TMP[out]}"
58+
) &
59+
fi
60+
done < "${VAR[pkg]}"
61+
wait
62+
fi
63+
find "${VAR[use]}" -type 'f' -name '*.lpk' -printf '\033[32m\tadd package link\t%p\033[0m\n' -exec \
64+
lazbuild --add-package-link {} + 1>&2
65+
fi
66+
declare -i errors=0
67+
while read -r; do
68+
declare -A TMP=(
69+
[out]=$(mktemp)
70+
)
71+
if (lazbuild --build-all --recursive --no-write-project "${REPLY}" > "${TMP[out]}"); then
72+
printf '\x1b[32m\t[%s]\t%s\x1b[0m\n' "${?}" "${REPLY}"
73+
grep --color='always' 'Linking' "${TMP[out]}"
74+
else
75+
printf '\x1b[31m\t[%s]\t%s\x1b[0m\n' "${?}" "${REPLY}"
76+
grep --color='always' --extended-regexp '(Error|Fatal):' "${TMP[out]}"
77+
((errors+=1))
78+
fi 1>&2
79+
rm "${TMP[out]}"
80+
done < <(find "${VAR[src]}" -type 'f' -name '*.lpi' | sort)
81+
exit "${errors}"
82+
)
83+
84+
function priv_main
85+
(
86+
set -euo pipefail
87+
if ((${#})); then
88+
case ${1} in
89+
build) priv_lazbuild ;;
90+
*) priv_clippit ;;
91+
esac
92+
else
93+
priv_clippit
94+
fi
95+
)
96+
97+
##############################################################################################################
98+
priv_main "${@}" >/dev/null

.github/workflows/make.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
- windows-latest
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
submodules: true
33+
34+
- name: Build on Linux
35+
if: runner.os == 'Linux'
36+
shell: bash
37+
run: bash .github/workflows/make.sh build
38+
39+
- name: Build on Windows
40+
if: runner.os == 'Windows'
41+
shell: powershell
42+
run: pwsh -File .github/workflows/make.ps1 build
43+
44+
- name: Archive
45+
if: runner.os == 'Windows'
46+
uses: actions/upload-artifact@v4
47+
with:
48+
retention-days: 1
49+
path: src\bin\*.exe

0 commit comments

Comments
 (0)