git-for-windows / git-for-windows-automation

A few GitHub workflows and support code to help with Git for Windows' day-to-day tasks
10 stars 11 forks source link

build-and-deploy: use `update-via-pacman.ps1`, if available #29

Closed dscho closed 9 months ago

dscho commented 1 year ago

Currently the build-and-deploy workflow fails when one of the "system packages" (like bash, msys2-runtime, pacman or filesystem) need to be updated: pacman -Syyu --noconfirm "helpfully" terminates every Bash instance, including the current process, after the system packages have been updated.

To help with this issue in their sync workflows, the git-sdk-* repositories are now equipped with a PowerShell script that runs pacman and fixes things up as necessary.

Let's use the same script in build-and-deploy.

The only complication would be if we used any Git for Windows SDK flavor other than full because that script would not be there in that case.

But: currently we use this full flavor in all instances except when building mingw-w64-git (which is however not the plan to do anyway, we're developing the git-artifacts workflow for that purpose).

Besides, we could easily teach please.sh create-sdk-artifact build-installers to include that script. Or extend the makepkg-git sparse-checkout definitions in all three git-sdk-* repositories to include that script. It's not like it's large 😁

dscho commented 10 months ago

This is actually quite important to have, as I found out today. The reason is that we currently run pacman -Syyu in a Bash step. And as I found out the hard way (but not immediately, it took a failed re-run for me to realize what was going on, which was particularly annoying because the aarch64 builds have a 7-minute time tax to spin up a self-hosted runner):

[...]
:: Processing package changes...
upgrading msys2-runtime...
upgrading msys2-runtime-devel...
:: To complete this update all MSYS2 processes including this terminal will be closed. Confirm to proceed [Y/n] SUCCESS: The process with PID 7016 has been terminated.
Error: Process completed with exit code 1.

The reason is that pacman -Syyu, when it upgrades the msys2-runtime package, is designed to stop any processes using the MSYS2 runtime. And that includes... drum roll... Bash! Including the Bash step running pacman -Syyu!

The same would happen, of course, if bash had been upgraded since the last sync run that would synchronize the git-sdk-* repositories.

So yeah, we need this.

This should work:

- name: pacman -Syyu
  shell: powershell
  run: |
    # figure out where the Git for Windows SDK is installed; It adds /usr/bin to the PATH
    $git_sdk = ($env:PATH.split(';') | where { $_.EndsWith('\usr\bin') } | select-object -first 1).TrimEnd('\usr\bin')
    & ($git_sdk + "\update-via-pacman.ps1")