Skip to content

Commit

Permalink
Re-factor the build script and add auto update vendors
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSDavidSoft authored Oct 17, 2022
2 parents 5b46f4f + 2ebf683 commit 5eacfc9
Show file tree
Hide file tree
Showing 5 changed files with 453 additions and 80 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/vendor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Update Vendor

on:
workflow_dispatch:
schedule:
# At 13:37 UTC every day.
- cron: '37 13 * * *'

defaults:
run:
shell: pwsh

permissions:
contents: read

jobs:
vendor:

runs-on: windows-latest
continue-on-error: false
timeout-minutes: 15
permissions:
contents: write
pull-requests: write

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- id: make-changes
run: |
$currentVersion = (Get-Content .\vendor\sources.json | ConvertFrom-Json)
. .\scripts\update.ps1 -verbose
Set-GHVariable -Name COUNT_UPDATED -Value $count
$newVersion = (Get-Content .\vendor\sources.json | ConvertFrom-Json)
$listUpdated = ""
$updateMessage = "| Name | Old Version | New Version |`n| :--- | ---- | ---- |`n"
foreach ($s in $newVersion) {
$oldVersion = ($currentVersion | Where-Object {$_.name -eq $s.name}).version
if ($s.version -ne $oldVersion) {
$listUpdated += "$($s.name) v$($s.version), "
$updateMessage += "| **$($s.name)** | $oldVersion | **$($s.version)** |`n"
}
}
Set-GHVariable -Name LIST_UPDATED -Value $listUpdated.Trim(', ')
echo "UPDATE_MESSAGE<<<EOF`n$updateMessage`n<EOF" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
- uses: peter-evans/create-pull-request@v4
with:
title: 'Updates to `${{ env.COUNT_UPDATED }}` vendored dependencies'
body: |
### Automatically updated `${{ env.COUNT_UPDATED }}` dependencies:
${{ env.UPDATE_MESSAGE }}
---
Please verify and then **Merge** the pull request to update.
commit-message: 'Update vendored dependencies (${{ env.LIST_UPDATED }})'
branch: update-vendor
base: master
171 changes: 97 additions & 74 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
.EXAMPLE
.\build.ps1
Executes the default build for Cmder; Conemu, clink. This is equivalent to the "minimum" style package in the releases
Executes the default build for Cmder; ConEmu, clink. This is equivalent to the "minimum" style package in the releases
.EXAMPLE
.\build.ps1 -Compile
Recompile the launcher executable if you have the requisite build tools for C++ installed.
.EXAMPLE
.\build.ps1 -Compile -NoVendor
Skip all downloads and only build launcher.
.EXAMPLE
.\build -verbose
Expand Down Expand Up @@ -49,7 +53,10 @@ Param(
# Config folder location
[string]$config = "$PSScriptRoot\..\config",

# New launcher if you have MSBuild tools installed
# Using this option will skip all downloads, if you only need to build launcher
[switch]$noVendor,

# Build launcher if you have MSBuild tools installed
[switch]$Compile
)

Expand All @@ -60,97 +67,113 @@ $cmder_root = Resolve-Path "$PSScriptRoot\.."
. "$PSScriptRoot\utils.ps1"
$ErrorActionPreference = "Stop"

Push-Location -Path $saveTo
$sources = Get-Content $sourcesPath | Out-String | Convertfrom-Json

# Get the version string
$version = Get-VersionStr

# Check for requirements
Ensure-Exists $sourcesPath
Ensure-Executable "7z"
Ensure-Executable "msbuild"
New-Item -Type Directory -Path (Join-Path $saveTo "/tmp/") -ErrorAction SilentlyContinue >$null

# Preserve modified (by user) ConEmu setting file
if ($config -ne "") {
$ConEmuXml = Join-Path $saveTo "conemu-maximus5\ConEmu.xml"
if (Test-Path $ConEmuXml -pathType leaf) {
$ConEmuXmlSave = Join-Path $config "ConEmu.xml"
Write-Verbose "Backup '$ConEmuXml' to '$ConEmuXmlSave'"
Copy-Item $ConEmuXml $ConEmuXmlSave
} else { $ConEmuXml = "" }
} else { $ConEmuXml = "" }
if ($Compile) {
# Check for requirements
Ensure-Executable "msbuild"

# Kill ssh-agent.exe if it is running from the $env:cmder_root we are building
foreach ($ssh_agent in $(get-process ssh-agent -erroraction silentlycontinue)) {
if ([string]$($ssh_agent.path) -match [string]$cmder_root.replace('\','\\')) {
Write-Verbose $("Stopping " + $ssh_agent.path + "!")
Stop-Process $ssh_agent.id
}
}
# Get the version string
$version = Get-VersionStr

$vend = $pwd
foreach ($s in $sources) {
Write-Verbose "Getting vendored $($s.name) $($s.version)..."
Push-Location -Path $launcher
Create-RC $version ($launcher + '\src\version.rc2')

# We do not care about the extensions/type of archive
$tempArchive = "tmp/$($s.name).tmp"
Delete-Existing $tempArchive
Delete-Existing $s.name
Write-Verbose "Building the launcher..."

Download-File -Url $s.url -File $vend\$tempArchive -ErrorAction Stop
Extract-Archive $tempArchive $s.name
# Referene: https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
msbuild CmderLauncher.vcxproj /t:Clean,Build /p:configuration=Release /m

if ((Get-Childitem $s.name).Count -eq 1) {
Flatten-Directory($s.name)
if ($LastExitCode -ne 0) {
throw "MSBuild failed to build the launcher executable."
}
# Write current version to .cmderver file, for later.
"$($s.version)" | Out-File "$($s.name)/.cmderver"
Pop-Location
}

# Restore user configuration
if ($ConEmuXml -ne "") {
Write-Verbose "Restore '$ConEmuXmlSave' to '$ConEmuXml'"
Copy-Item $ConEmuXmlSave $ConEmuXml
}
if (-Not $noVendor) {
# Check for requirements
Ensure-Exists $sourcesPath
Ensure-Executable "7z"

Pop-Location
# Get the vendor sources
$sources = Get-Content $sourcesPath | Out-String | ConvertFrom-Json

if($Compile) {
Push-Location -Path $launcher
Create-RC $version ($launcher + '\src\version.rc2');
# https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
msbuild CmderLauncher.vcxproj /t:Clean,Build /p:configuration=Release /m
if ($LastExitCode -ne 0) {
throw "MSBuild failed to build the executable."
}
else {
Write-Verbose "Successfully built Cmder v$version!"
if ( $Env:APPVEYOR -eq 'True' ) {
Add-AppveyorMessage -Message "Building Cmder v$version was successful." -Category Information
Push-Location -Path $saveTo
New-Item -Type Directory -Path (Join-Path $saveTo "/tmp/") -ErrorAction SilentlyContinue >$null

$vend = $pwd

# Preserve modified (by user) ConEmu setting file
if ($config -ne "") {
$ConEmuXml = Join-Path $saveTo "conemu-maximus5\ConEmu.xml"
if (Test-Path $ConEmuXml -pathType leaf) {
$ConEmuXmlSave = Join-Path $config "ConEmu.xml"
Write-Verbose "Backup '$ConEmuXml' to '$ConEmuXmlSave'"
Copy-Item $ConEmuXml $ConEmuXmlSave
} else { $ConEmuXml = "" }
} else { $ConEmuXml = "" }

# Kill ssh-agent.exe if it is running from the $env:cmder_root we are building
foreach ($ssh_agent in $(Get-Process ssh-agent -ErrorAction SilentlyContinue)) {
if ([string]$($ssh_agent.path) -Match [string]$cmder_root.replace('\','\\')) {
Write-Verbose $("Stopping " + $ssh_agent.path + "!")
Stop-Process $ssh_agent.id
}
if ( $Env:GITHUB_ACTIONS -eq 'true' ) {
Write-Output "::notice title=Build Complete::Building Cmder v$version was successful."
}

foreach ($s in $sources) {
Write-Verbose "Getting vendored $($s.name) $($s.version)..."

# We do not care about the extensions/type of archive
$tempArchive = "tmp/$($s.name).tmp"
Delete-Existing $tempArchive
Delete-Existing $s.name

Download-File -Url $s.url -File $vend\$tempArchive -ErrorAction Stop
Extract-Archive $tempArchive $s.name

if ((Get-ChildItem $s.name).Count -eq 1) {
Flatten-Directory($s.name)
}

# Write current version to .cmderver file, for later.
"$($s.version)" | Out-File "$($s.name)/.cmderver"
}

# Restore ConEmu user configuration
if ($ConEmuXml -ne "") {
Write-Verbose "Restore '$ConEmuXmlSave' to '$ConEmuXml'"
Copy-Item $ConEmuXmlSave $ConEmuXml
}

# Put vendor\cmder.sh in /etc/profile.d so it runs when we start bash or mintty
if ( (Test-Path $($saveTo + "git-for-windows/etc/profile.d") ) ) {
Write-Verbose "Adding cmder.sh /etc/profile.d"
Copy-Item $($saveTo + "cmder.sh") $($saveTo + "git-for-windows/etc/profile.d/cmder.sh")
}

# Replace /etc/profile.d/git-prompt.sh with cmder lambda prompt so it runs when we start bash or mintty
if ( !(Test-Path $($saveTo + "git-for-windows/etc/profile.d/git-prompt.sh.bak") ) ) {
Write-Verbose "Replacing /etc/profile.d/git-prompt.sh with our git-prompt.sh"
Move-Item $($saveTo + "git-for-windows/etc/profile.d/git-prompt.sh") $($saveTo + "git-for-windows/etc/profile.d/git-prompt.sh.bak")
Copy-Item $($saveTo + "git-prompt.sh") $($saveTo + "git-for-windows/etc/profile.d/git-prompt.sh")
}

Pop-Location
} else {
Write-Warning "You are not building a launcher, Use -Compile"
}

if (-Not $Compile -Or $noVendor) {
Write-Warning "You are not building the full project, Use -Compile without -noVendor"
Write-Warning "This cannot be a release. Test build only!"
return
}

# Put vendor\cmder.sh in /etc/profile.d so it runs when we start bash or mintty
if ( (Test-Path $($SaveTo + "git-for-windows/etc/profile.d") ) ) {
Write-Verbose "Adding cmder.sh /etc/profile.d"
Copy-Item $($SaveTo + "cmder.sh") $($SaveTo + "git-for-windows/etc/profile.d/cmder.sh")
Write-Verbose "Successfully built Cmder v$version!"

if ( $Env:APPVEYOR -eq 'True' ) {
Add-AppveyorMessage -Message "Building Cmder v$version was successful." -Category Information
}

# Replace /etc/profile.d/git-prompt.sh with cmder lambda prompt so it runs when we start bash or mintty
if ( !(Test-Path $($SaveTo + "git-for-windows/etc/profile.d/git-prompt.sh.bak") ) ) {
Write-Verbose "Replacing /etc/profile.d/git-prompt.sh with our git-prompt.sh"
Move-Item $($SaveTo + "git-for-windows/etc/profile.d/git-prompt.sh") $($SaveTo + "git-for-windows/etc/profile.d/git-prompt.sh.bak")
Copy-Item $($SaveTo + "git-prompt.sh") $($SaveTo + "git-for-windows/etc/profile.d/git-prompt.sh")
if ( $Env:GITHUB_ACTIONS -eq 'true' ) {
Write-Output "::notice title=Build Complete::Building Cmder v$version was successful."
}

Write-Host -ForegroundColor green "All good and done!"
4 changes: 2 additions & 2 deletions scripts/pack.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Creates default archives for cmder
.EXAMPLE
.\build -verbose
.\pack.ps1 -verbose
Creates default archives for cmder with plenty of information
.NOTES
Expand Down Expand Up @@ -52,7 +52,7 @@ Push-Location -Path $cmderRoot
Delete-Existing "$cmderRoot\Version*"
Delete-Existing "$cmderRoot\build\*"

If(-not (Test-Path -PathType container $saveTo)) {
if (-not (Test-Path -PathType container $saveTo)) {
(New-Item -ItemType Directory -Path $saveTo) | Out-Null
}

Expand Down
Loading

0 comments on commit 5eacfc9

Please sign in to comment.