Based on work by @innerout, but finished and merged by me, because the GitHub action refused to run for him. Closes #2075 Closes #2091