Skip to content

Commit

Permalink
Allow develop/* and fix/* branches to build.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjsr committed Feb 25, 2025
1 parent 554292b commit cfcc68f
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 74 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/devbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ on:
push:
branches:
- dev
- develop/*
- fix/*
paths-ignore:
- README.md
- CHANGELOG.md
- .grenrc.yml
- .idea/*
- .vscode/*

name: DevelopmentBuild

Expand All @@ -24,8 +28,14 @@ jobs:
with:
python-version: 3.10.*
- name: Checkout code
#uses: actions/checkout@master
uses: actions/checkout@v4
- uses: actions/cache@v4
if: startsWith(runner.os, 'macOS')
with:
path: ~/Library/Caches/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Setup Environment
run: |
cd $GITHUB_WORKSPACE
Expand All @@ -35,6 +45,7 @@ jobs:
cd $GITHUB_WORKSPACE
bash compile.sh -a -A
- name: Dev Release
if: github.ref == 'refs/heads/dev'
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
Expand All @@ -54,6 +65,13 @@ jobs:
python-version: 3.10.*
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/cache@v4
if: startsWith(runner.os, 'Windows')
with:
path: ~\AppData\Local\pip\Cache
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Setup Environment
shell: powershell
run: |
Expand All @@ -65,6 +83,7 @@ jobs:
cd $env:GITHUB_WORKSPACE
.\compile.ps1 -all -everything
- name: Dev Release
if: github.ref == 'refs/heads/dev'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
33 changes: 33 additions & 0 deletions Scripts/gitutils.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
. .\Scripts\utils.ps1

function IsDevelopmentBranch() {
$githubref = $env:GITHUB_REF.Split('/')
$refs = $githubref[1].ToLower()
if ($refs -ne 'heads') {
Write-Debug "Refs is not heads", $refs
return $false
}
$branchName = $githubref[2]

if ( [string]::IsNullOrEmpty($branchName)) {
return $false
}
$allowed = @(
'dev',
'develop',
'fix'
)
if ( $allowed -contains $branchName.ToLower() ) {
return $true
}

return $false
}

function IsTag() {
$githubref = $env:GITHUB_REF.Split('/')
if ($githubref[1].ToLower() -ne 'tags') {
return $false
}
return $true
}
19 changes: 19 additions & 0 deletions Scripts/utils.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function RequireProgram($program)
{
if ( [string]::IsNullOrEmpty($program) ) {
Get-PSCallStack
Write-Host "No program specified. Aborting..."
exit 1
}
}

function GetBuildDir($program)
{
RequireProgram($program)
$builddir = '.'
if ($program -ne 'CrossMgr')
{
$builddir = $program
}
return $builddir
}
97 changes: 97 additions & 0 deletions Scripts/versions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
. .\Scripts\utils.ps1

function GetVersionFilePath($program)
{
RequireProgram($program)
$builddir = GetBuildDir($program)
$VersionFilePath = "$builddir/Version.py"
return $VersionFilePath
}

function GetVersionFileContents($program)
{
RequireProgram($program)
$VersionFile = GetVersionFilePath($program)
if (!(Test-Path -Path $VersionFile))
{
Get-PSCallStack
Write-Host "No version file at ", $VersionFile,". Aborting..."
exit 1
}

$versionItem = Get-Content $VersionFile
if ([string]::IsNullOrEmpty($versionItem))
{
Get-PSCallStack
Write-Host "Version file at", $VersionFile, "is empty. Aborting..."
exit 1
}
return $versionItem
}

function GetVersion($program)
{
RequireProgram($program)
$versionItem = GetVersionFileContents($program)
$version = $versionItem.Split(' ')[1].Replace("`"", "")
return $version
}

function WriteVersionFile($program, $appVersionString)
{
if ([string]::IsNullOrEmpty($appVersionString))
{
Write-Host "No version string for program", $program, ". Aborting..."
Get-PSCallStack
exit 1
}
$VersionFile = GetVersionFilePath($program)

$appvername = "AppVerName=`"$program $appVersionString`""
Write-Host "Writing", $appvername,"to version file", $VersionFile

Set-Content -Path $VersionFile -Value $appvername
}

function updateProgramVersion($program) {
RequireProgram($program)
$version = GetVersion($program)
if ([string]::IsNullOrEmpty($version))
{
Write-Host "Failed getting version for", $program,". Aborting..."
exit 1
}
if (IsDevelopmentBranch) {
$shortsha=$env:GITHUB_SHA.SubString(0,7)
$appVersionString="${version}-beta-${shortsha}"
Write-Host "Updating version of", $program, "from development branch to", $appVersionString
} elseif (IsTag) {
$refdate = ValidateTag
$appVersionString="${version}-${refdate}"
Write-Host "Updating version of", $program, "from tag to", $version
} else {
Write-Host "Not a development branch or tag. Using version", $version
$appVersionString = $version
}
WriteVersionFile $program $appVersionString
}

function updateVersion($programs)
{
if ($programs.Length -eq 0)
{
Write-Host "No programs selected"
exit 1
}
if ([string]::IsNullOrEmpty($env:GITHUB_REF))
{
Write-Host "No GITHUB_REF - not updating versions."
return 0
}

Write-Host "GITHUB_REF=$env:GITHUB_REF"
foreach ($program in $programs)
{
updateProgramVersion $program
}
}
80 changes: 16 additions & 64 deletions compile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ param (
$environ = "env"
$script:pythongood = $false

. .\Scripts\utils.ps1
. .\Scripts\gitutils.ps1
. .\Scripts\versions.ps1

# Check the python version. Current only 3.10.x.
function CheckPythonVersion
{
Expand All @@ -76,15 +80,6 @@ function CheckPythonVersion
}

}
function GetBuildDir($program)
{
$builddir = '.'
if ($program -ne 'CrossMgr')
{
$builddir = $program
}
return $builddir
}

function CheckEnvActive
{
Expand Down Expand Up @@ -135,20 +130,6 @@ function doPyInstaller($program)
}
}

function GetVersion($program)
{
$builddir = GetBuildDir($program)
if (!(Test-Path -Path "$builddir/Version.py"))
{
Write-Host "No version file in ", $builddir, "/Version.py. Aborting..."
exit 1
}
$versionItem = Get-Content "$builddir/Version.py"
$version = $versionItem.Split(' ')[1].Replace("`"", "")
Write-Host $program, "Version is", $version
return $version
}

function Cleanup($program)
{
Write-Host 'Cleaning up everything...'
Expand Down Expand Up @@ -430,50 +411,21 @@ function EnvSetup($program)

}

function updateVersion($programs)
{
if ($programs.Length -eq 0)
function ValidateTag() {
$githubref = $env:GITHUB_REF.Split('/')
$verno = $githubref[2].Split('-')[0]
$refdate = $githubref[2].Split('-')[1]
$major = $verno.Split('.')[0]
$minor = $verno.Split('.')[1]
$release = $verno.Split('.')[2]
if ($major -ne 'v3' -or [string]::IsNullOrEmpty($minor) -or [string]::IsNullOrEmpty($release) -or [string]::IsNullOrEmpty($refdate))
{
Write-Host "No programs selected"
Write-Host "Invalid Tag format. Must be v3.0.3-20200101010101. Refusing to build!"
exit 1
}
if (-not [string]::IsNullOrEmpty($env:GITHUB_REF))
{
Write-Host "GITHUB_REF=$env:GITHUB_REF"
foreach ($program in $programs)
{
$builddir = GetBuildDir($program)
$version = GetVersion($program)
$githubref = $env:GITHUB_REF.Split('/')
$version = $version.Split('-')[0]
$shortsha=$env:GITHUB_SHA.SubString(0,7)
if ($githubref[1] -eq 'heads' -and $githubref[2] -eq 'dev')
{
$appvername = "AppVerName=`"$program $version-beta-$shortsha`""
$version="${version}-beta-${shortsha}"
}
if ($githubref[1] -eq 'tags')
{
$verno = $githubref[2].Split('-')[0]
$refdate = $githubref[2].Split('-')[1]
$major = $verno.Split('.')[0]
$minor = $verno.Split('.')[1]
$release = $verno.Split('.')[2]
if ($major -ne 'v3' -or [string]::IsNullOrEmpty($minor) -or [string]::IsNullOrEmpty($release) -or [string]::IsNullOrEmpty($refdate))
{
Write-Host "Invalid Tag format. Must be v3.0.3-20200101010101. Refusing to build!"
exit 1
}
$appvername = "AppVerName=`"$program $version-$refdate`""
$version = $githubref[2]
}
Write-Host "$program version is now $version"
Set-Content -Path "$builddir\Version.py" -Value "$appvername"
}

}

return $refdate
}

function BuildAll($programs)
{
CheckPythonVersion
Expand Down Expand Up @@ -523,7 +475,6 @@ function Virustotal
Write-Host "Uploading $file to VirusTotal..."
Start-Process -Wait -NoNewWindow -FilePath "python.exe" -ArgumentList "VirusTotalSubmit.py -v $file"
}

}

function DoRelease
Expand Down Expand Up @@ -808,6 +759,7 @@ if ($everything -eq $false)
{
updateVersion($programs)
}
$virus = $false
}
else
{
Expand Down
Loading

0 comments on commit cfcc68f

Please sign in to comment.