This is just a basic idea, I am not sure how useful it is or how easy it is to implement.
I just updated Nextcloud and took a look at the upgrade screen (which nicely ticks one step after another after it is done)
(The procedure is also described at https://docs.nextcloud.com/server/13/admin_manual/maintenance/update.html)
I noticed that Nextcloud seems to backup it's files before the update. Maybe doing that would help get back to a working state in case Matomo is completly broken after an update (e.g. because of missing Classes or corrupted files which seems to be reported quite often)
Of course we would need to find a way to do the rollback (as the web ui is probably already broken at this point) and it wouldn't help if the database migration have already happened (but that would only happen in the next step).