Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-factor the build script to distinguish each step #2758

Merged
merged 28 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a49921b
add github variable helpers (credit: @microsoft)
DRSDavidSoft Oct 15, 2022
1c4a8b3
add vendor dependency check action
DRSDavidSoft Oct 15, 2022
59269aa
allow manual trigger
DRSDavidSoft Oct 15, 2022
e1caeb8
Merge branch 'master' of https://github.com/DRSDavidSoft/cmder
DRSDavidSoft Oct 16, 2022
f58652f
check requirements only for specified switches
DRSDavidSoft Oct 16, 2022
d94fe86
add -noVendor flag
DRSDavidSoft Oct 16, 2022
87f7ddf
formatting and case conventions
DRSDavidSoft Oct 16, 2022
7995f34
adjust comments
DRSDavidSoft Oct 16, 2022
71536dd
stop ssh agent only if building vendors
DRSDavidSoft Oct 17, 2022
3901fef
minor letter casing edit
DRSDavidSoft Oct 17, 2022
6b72e84
minor letter casing update
DRSDavidSoft Oct 17, 2022
e7139bd
initial update vendors script
DRSDavidSoft Oct 17, 2022
f468ddf
fix typo
DRSDavidSoft Oct 17, 2022
1d330e7
remove incompatible version string matching
DRSDavidSoft Oct 17, 2022
1e34c88
fix typos
DRSDavidSoft Oct 17, 2022
e1a0d38
improve formatting of text
DRSDavidSoft Oct 17, 2022
3fe76de
fix github variable
DRSDavidSoft Oct 17, 2022
3f88112
edit notice title
DRSDavidSoft Oct 17, 2022
129c297
use a table for message description
DRSDavidSoft Oct 17, 2022
ae391eb
use paranthesis to fix bug
DRSDavidSoft Oct 17, 2022
0559060
use correct escaping for new line
DRSDavidSoft Oct 17, 2022
4264158
attempt to fix new lines for PR message
DRSDavidSoft Oct 17, 2022
cc9699c
resolve issues with variable name
DRSDavidSoft Oct 17, 2022
3943ba6
fix small bug
DRSDavidSoft Oct 17, 2022
d767c9b
use alternative method to escape newlines
DRSDavidSoft Oct 17, 2022
9151fb3
new line GitHub env improvements
DRSDavidSoft Oct 17, 2022
856d22e
write raw github env var with newlines
DRSDavidSoft Oct 17, 2022
2ebf683
fix small ending delimiter
DRSDavidSoft Oct 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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