Skip to content

Commit

Permalink
Add/GitHub actions (#56)
Browse files Browse the repository at this point in the history
* add github-actions

* fix github-actions

* fix github-actions

* fix github-actions
  • Loading branch information
theavege authored Jan 12, 2025
1 parent 9d7b784 commit 9cfd284
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
167 changes: 167 additions & 0 deletions .github/workflows/make.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#!/usr/bin/env pwsh
##############################################################################################################

Function Show-Usage {
"
vagrant = 'it-gro/win10-ltsc-eval'
download = 'https://microsoft.com/en-us/evalcenter'
package = 'https://learn.microsoft.com/en-us/mem/configmgr/develop/apps/how-to-create-the-windows-installer-file-msi'
shell = 'https://learn.microsoft.com/en-us/powershell'
Usage: pwsh -File $($PSCommandPath) [OPTIONS]
Options:
build
lint
" | Out-Host
}

Function Build-Project {
New-Variable -Option Constant -Name VAR -Value @{
Src = 'Examples'
Use = 'Package'
Pkg = 'Package\components.txt'
}
If (! (Test-Path -Path $Var.Src)) {
"$([char]27)[31m.... Source do not find!$([char]27)[0m" | Out-Host
Exit 1
}
If (Test-Path -Path '.gitmodules') {
& git submodule update --init --recursive --force --remote | Out-Host
"$([char]27)[32m.... [[$($LastExitCode)]] git submodule update$([char]27)[0m" | Out-Host
}
@(
@{
Cmd = 'lazbuild'
Url = 'https://fossies.org/windows/misc/lazarus-3.6-fpc-3.2.2-win64.exe'
Path = "C:\Lazarus"
}
) | Where-Object { ! (Test-Path -Path $_.Path) } |
ForEach-Object {
$_.Url | Request-File | Install-Program
$Env:PATH+=";$($_.Path)"
(Get-Command $_.Cmd).Source | Out-Host
}
If (Test-Path -Path $VAR.Use) {
If (Test-Path -Path $VAR.Pkg) {
Get-Content -Path $VAR.Pkg |
Where-Object {
! (Test-Path -Path "$($VAR.Use)\$($_)") &&
! (& lazbuild --verbose-pkgsearch $_ ) &&
! (& lazbuild --add-package $_)
} | ForEach-Object {
Return @{
Uri = "https://packages.lazarus-ide.org/$($_).zip"
Path = "$($VAR.Use)\$($_)"
OutFile = (New-TemporaryFile).FullName
}
} | ForEach-Object -Parallel {
Invoke-WebRequest -OutFile $_.OutFile -Uri $_.Uri
Expand-Archive -Path $_.OutFile -DestinationPath $_.Path
Remove-Item $_.OutFile
Return "$([char]27)[32m.... download $($_.Uri)$([char]27)[0m"
} | Out-Host
}
(Get-ChildItem -Filter '*.lpk' -Recurse -File –Path $VAR.Use).FullName |
ForEach-Object {
& lazbuild --add-package-link $_ | Out-Null
Return "$([char]27)[32m.... [$($LastExitCode)] add package link $($_)$([char]27)[0m"
} | Out-Host
}
Exit (
(Get-ChildItem -Filter '*.lpi' -Recurse -File –Path $Var.Src).FullName |
Sort-Object |
ForEach-Object {
$Output = (& lazbuild --build-all --recursive --no-write-project $_)
$Result = @("$([char]27)[32m.... [$($LastExitCode)] build project $($_)$([char]27)[0m")
$exitCode = Switch ($LastExitCode) {
0 {
$Result += $Output | Select-String -Pattern 'Linking'
0
}
Default {
$Result += $Output | Select-String -Pattern 'Error:', 'Fatal:'
1
}
}
$Result | Out-Host
Return $exitCode
} | Measure-Object -Sum
).Sum
}

Function Request-File {
While ($Input.MoveNext()) {
New-Variable -Option Constant -Name VAR -Value @{
Uri = $Input.Current
OutFile = (Split-Path -Path $Input.Current -Leaf).Split('?')[0]
}
Invoke-WebRequest @VAR
Return $VAR.OutFile
}
}

Function Install-Program {
While ($Input.MoveNext()) {
Switch ((Split-Path -Path $Input.Current -Leaf).Split('.')[-1]) {
'msi' {
& msiexec /passive /package $Input.Current | Out-Null
}
Default {
& ".\$($Input.Current)" /SP- /VERYSILENT /SUPPRESSMSGBOXES /NORESTART | Out-Null
}
}
Remove-Item $Input.Current
}
}

Function Request-URL([Switch] $Post) {
$VAR = Switch ($Post) {
True {
Return @{
Method = 'POST'
Headers = @{
ContentType = 'application/json'
}
Uri = 'https://postman-echo.com/post'
Body = @{
One = '1'
} | ConvertTo-Json
}
}
False {
Return @{
Uri = 'https://postman-echo.com/get'
}
}
}
Return (Invoke-WebRequest @VAR | ConvertFrom-Json).Headers
}

Function Switch-Action {
$ErrorActionPreference = 'stop'
Set-PSDebug -Strict #-Trace 1
Invoke-ScriptAnalyzer -EnableExit -Path $PSCommandPath
If ($args.count -gt 0) {
Switch ($args[0]) {
'lint' {
Invoke-ScriptAnalyzer -EnableExit -Recurse -Path '.'
(Get-ChildItem -Filter '*.ps1' -Recurse -Path '.').FullName |
ForEach-Object {
Invoke-Formatter -ScriptDefinition $(Get-Content -Path $_ | Out-String) |
Set-Content -Path $_
}
}
'build' {
Build-Project
}
Default {
Show-Usage
}
}
} Else {
Show-Usage
}
}

##############################################################################################################
Switch-Action @args
98 changes: 98 additions & 0 deletions .github/workflows/make.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash
##############################################################################################################

function priv_clippit
(
cat <<EOF
https://google.github.io/styleguide/shellguide.html
https://guide.bash.academy
https://devhints.io/bash
https://tldr.sh
Usage: bash ${0} [OPTIONS]
Options:
build Build program
EOF
)

function priv_lazbuild
(
declare -rA VAR=(
[src]='Examples'
[use]='Package'
[pkg]='Package/components.txt'
)
if ! [[ -d "${VAR[src]}" ]]; then
printf '\x1b[31m\tSource do not find!\x1b[0m\n'
exit 1
fi
if [[ -f '.gitmodules' ]]; then
git submodule update --init --recursive --force --remote &
fi
if ! (command -v lazbuild); then
source '/etc/os-release'
case ${ID:?} in
debian | ubuntu)
sudo apt-get update
sudo apt-get install -y lazarus{-ide-qt5,} &
;;
esac
fi
wait
if [[ -d "${VAR[use]}" ]]; then
if [[ -f "${VAR[pkg]}" ]]; then
while read -r; do
if [[ -n "${REPLY}" ]] &&
! [[ -d "${VAR[use]}/${REPLY}" ]] &&
! (lazbuild --verbose-pkgsearch "${REPLY}") &&
! (lazbuild --add-package "${REPLY}"); then
(
declare -A TMP=(
[url]="https://packages.lazarus-ide.org/${REPLY}.zip"
[dir]="${VAR[use]}/${REPLY}"
[out]=$(mktemp)
)
wget --quiet --output-document "${TMP[out]}" "${TMP[url]}"
unzip -o "${TMP[out]}" -d "${TMP[dir]}"
rm --verbose "${TMP[out]}"
) &
fi
done < "${VAR[pkg]}"
wait
fi
find "${VAR[use]}" -type 'f' -name '*.lpk' -printf '\033[32m\tadd package link\t%p\033[0m\n' -exec \
lazbuild --add-package-link {} + 1>&2
fi
declare -i errors=0
while read -r; do
declare -A TMP=(
[out]=$(mktemp)
)
if (lazbuild --build-all --recursive --no-write-project "${REPLY}" > "${TMP[out]}"); then
printf '\x1b[32m\t[%s]\t%s\x1b[0m\n' "${?}" "${REPLY}"
grep --color='always' 'Linking' "${TMP[out]}"
else
printf '\x1b[31m\t[%s]\t%s\x1b[0m\n' "${?}" "${REPLY}"
grep --color='always' --extended-regexp '(Error|Fatal):' "${TMP[out]}"
((errors+=1))
fi 1>&2
rm "${TMP[out]}"
done < <(find "${VAR[src]}" -type 'f' -name '*.lpi' | sort)
exit "${errors}"
)

function priv_main
(
set -euo pipefail
if ((${#})); then
case ${1} in
build) priv_lazbuild ;;
*) priv_clippit ;;
esac
else
priv_clippit
fi
)

##############################################################################################################
priv_main "${@}" >/dev/null
49 changes: 49 additions & 0 deletions .github/workflows/make.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: Make

on:
schedule:
- cron: '0 0 1 * *'
push:
branches:
- "**"
pull_request:
branches:
- master
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ${{ matrix.os }}
timeout-minutes: 120
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- name: Build on Linux
if: runner.os == 'Linux'
shell: bash
run: bash .github/workflows/make.sh build

- name: Build on Windows
if: runner.os == 'Windows'
shell: powershell
run: pwsh -File .github/workflows/make.ps1 build

- name: Archive
if: runner.os == 'Windows'
uses: actions/upload-artifact@v4
with:
retention-days: 1
path: src\bin\*.exe

0 comments on commit 9cfd284

Please sign in to comment.