| 1 | # ---------------------------------------------------------------------------- |
| 2 | # GitHub Action workflow to |
| 3 | # |
| 4 | # - test CGE compilation and automatic tests |
| 5 | # - pack CGE into zip |
| 6 | # |
| 7 | # on some platforms for which |
| 8 | # |
| 9 | # - we don't use Docker |
| 10 | # - we don't use cross-compilation from other platform |
| 11 | # - we just use a runner with the given platform - self-hosted or GH hosted. |
| 12 | # ---------------------------------------------------------------------------- |
| 13 | |
| 14 | name: Test and Pack (Runner Native) |
| 15 | |
| 16 | # Called by everything.yml |
| 17 | on: [workflow_call] |
| 18 | #on: [push, pull_request] |
| 19 | |
| 20 | defaults: |
| 21 | run: |
| 22 | shell: bash |
| 23 | |
| 24 | jobs: |
| 25 | test_and_pack: |
| 26 | name: Test and Pack |
| 27 | strategy: |
| 28 | matrix: |
| 29 | # TODO: |
| 30 | # Readd macos-latest: |
| 31 | # |
| 32 | # Fails teapot-to-pascal compilation with: |
| 33 | # |
| 34 | # Undefined symbols for architecture arm64: |
| 35 | # "_LSOpenCFURLRef", referenced from: |
| 36 | # _CASTLEOPENDOCUMENT_$$_OPENURL$ANSISTRING$$BOOLEAN in castleopendocument.o |
| 37 | # |
| 38 | # Using macos-12 as last Intel-based mac. |
| 39 | # |
| 40 | # TODO: Readd macos-12: |
| 41 | # For now cannot be used as |
| 42 | # https://github.com/gcarreno/setup-lazarus doesn't have Lazarus >= 3.5 |
| 43 | # and we need it to have https://gitlab.com/freepascal.org/lazarus/lazarus/-/merge_requests/291 |
| 44 | # solved. |
| 45 | |
| 46 | runner: [macos_x64, ubuntu-latest, windows-latest] |
| 47 | include: |
| 48 | # To not overload the slower RPi, use it only with master |
| 49 | - if: ${{ github.ref == 'refs/heads/master' }} |
| 50 | runner: raspberry_pi_64 |
| 51 | - if: ${{ github.ref == 'refs/heads/master' }} |
| 52 | runner: raspberry_pi_32 |
| 53 | # Add is_macos variable to later easily check. |
| 54 | # Default is false, and then we override it to true for macos runners. |
| 55 | - is_macos: false |
| 56 | - runner: macos_x64 |
| 57 | is_macos: true |
| 58 | # Uncomment this once we reeanable macos-12 |
| 59 | # - runner: macos-12 |
| 60 | # is_macos: true |
| 61 | # Uncomment this once we reeanable macos-latest |
| 62 | # - runner: macos-latest |
| 63 | # is_macos: true |
| 64 | runs-on: ${{ matrix.runner }} |
| 65 | steps: |
| 66 | - uses: actions/checkout@v4 |
| 67 | |
| 68 | - name: Install FPC+Lazarus |
| 69 | # On GH hosted runners, install FPC+Lazarus |
| 70 | if: ${{ matrix.runner == 'ubuntu-latest' || matrix.runner == 'macos-latest' || matrix.runner == 'macos-12' || matrix.runner == 'windows-latest'}} |
| 71 | uses: gcarreno/[email protected] |
| 72 | with: |
| 73 | lazarus-version: stable |
| 74 | - name: Install Linux dependencies |
| 75 | if: ${{ matrix.runner == 'ubuntu-latest' }} |
| 76 | # Run "apt-get update" before installing, following https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/customizing-github-hosted-runners |
| 77 | run: | |
| 78 | sudo apt-get update |
| 79 | sudo apt-get --no-install-recommends -y install libgl-dev |
| 80 | - name: Install macOS dependencies (on GH hosted macs) |
| 81 | # We do this only on GH hosted macs, not on our macos_x64, because on our mac: 1. this is already installed, 2. ci user doesn't have permissions to install more. |
| 82 | if: ${{ matrix.runner == 'macos-latest' || matrix.runner == 'macos-12'}} |
| 83 | run: brew install gnu-sed coreutils |
| 84 | - name: Install Windows dependencies |
| 85 | if: ${{ matrix.runner == 'windows-latest' }} |
| 86 | # We need Inno Setup for creating Windows installer. |
| 87 | # Note: Inno Setup seems already available on windows-latest. |
| 88 | # For future-proof, just keep it declared here. |
| 89 | # wget to later get pasdoc. |
| 90 | # zip is used by pack_release. |
| 91 | run: choco install innosetup wget zip |
| 92 | |
| 93 | - name: Windows force Git Bash |
| 94 | if: ${{ matrix.runner == 'windows-latest' }} |
| 95 | run: echo "WINDOWS_FORCE_GIT_BASH=true" >> $GITHUB_ENV |
| 96 | |
| 97 | # MSys2 does something quite unexpected by default: it autoconverts |
| 98 | # any parameter that looks like Unix path to Windows path. |
| 99 | # See https://www.msys2.org/docs/filesystem-paths/ . |
| 100 | # |
| 101 | # This does result in weird problems when calling iscc. |
| 102 | # It seems (reported in bash through "set -x") it's calling something |
| 103 | # sensible, like this |
| 104 | # |
| 105 | # iscc |
| 106 | # 'D:\a\castle-engine\castle-engine/tools/internal/pack_release/cge-windows-setup.iss' |
| 107 | # /OD:/a/castle-engine/castle-engine |
| 108 | # /Fcastle-engine-setup-7.0-alpha.snapshot |
| 109 | # /DMyAppSrcDir=C:/Users/RUNNER~1/AppData/Local/Temp/castle-engine-release-1378/castle_game_engine |
| 110 | # /DMyAppVersion=7.0-alpha.snapshot |
| 111 | # |
| 112 | # (see iscc command-line docs). But in reality, it is passing (detected by |
| 113 | # our https://github.com/michaliskambi/report-params/ ) these nonsense |
| 114 | # parameters: |
| 115 | # |
| 116 | # iscc |
| 117 | # D:\a\castle-engine\castle-engine/tools/internal/pack_release/cge-windows-setup.iss |
| 118 | # C:\Program Files\Git\OD;A:\castle-engine\castle-engine |
| 119 | # C:/Program Files/Git/Fcastle-engine-setup-7.0-alpha.snapshot |
| 120 | # C:\Program Files\Git\DMyAppSrcDir=C;C:\Program Files\Git\Users\RUNNER~1\AppData\Local\Temp\castle-engine-release-1378\castle_game_engine |
| 121 | # C:/Program Files/Git/DMyAppVersion=7.0-alpha.snapshot |
| 122 | # |
| 123 | # As you see, it added "C:/Program Files/Git/" or "C:\Program Files\Git\" prefix |
| 124 | # in front of every parameter that started with /. |
| 125 | # This of course breaks iscc later. |
| 126 | # We don't want this. Our scripts are prepared to call `cygpath` to deal |
| 127 | # with path conversion problems explicitly. It is much much more reliable, |
| 128 | # and it is explicit -- easy to debug. |
| 129 | - name: Disable broken MSys2 paths conversion |
| 130 | if: ${{ matrix.runner == 'windows-latest' }} |
| 131 | run: echo "MSYS2_ENV_CONV_EXCL='*'" >> $GITHUB_ENV |
| 132 | # Git For Windows has a different name for this: |
| 133 | # https://stackoverflow.com/questions/7250130/how-to-stop-mingw-and-msys-from-mangling-path-names-given-at-the-command-line |
| 134 | # https://github.com/git-for-windows/git/issues/577 |
| 135 | # https://github.com/git-for-windows/msys2-runtime/pull/11 |
| 136 | - name: Disable broken Git For Windows MSys paths conversion |
| 137 | if: ${{ matrix.runner == 'windows-latest' }} |
| 138 | run: echo "MSYS_NO_PATHCONV=1" >> $GITHUB_ENV |
| 139 | |
| 140 | - name: Set environment CASTLE_ENGINE_PATH |
| 141 | run: echo "CASTLE_ENGINE_PATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV |
| 142 | # Convert CASTLE_ENGINE_PATH to use slashes on Windows. |
| 143 | # Most of the build commands actually honor Windows backslashes as well |
| 144 | # as slashes in $CASTLE_ENGINE_PATH. Exception is the Makefile assignments |
| 145 | # done on PREFIX variable, they go badly with |
| 146 | # "make clean tools install PREFIX=${CASTLE_ENGINE_PATH}/installed/" |
| 147 | # resulting in weird installation directory (backslashes are stripped |
| 148 | # during Makefile assignments and the build tool data gets copied to weird |
| 149 | # subdirectory under build-tool/data/). |
| 150 | - name: Make CASTLE_ENGINE_PATH use / (Windows) |
| 151 | if: ${{ matrix.runner == 'windows-latest' }} |
| 152 | run: echo "CASTLE_ENGINE_PATH=`cygpath --mixed \"${CASTLE_ENGINE_PATH}\"`" >> $GITHUB_ENV |
| 153 | |
| 154 | # Even on Windows, in GH hosted runner, |
| 155 | # PATH (at least within bash -- this is MSys bash) is separated by :. |
| 156 | # So the same path separator works for all platforms. |
| 157 | # However, for Windows, we have to convert native Windows path to MSys, |
| 158 | # otherwise path like "D:\a\castle-engine\castle-engine/installed/bin/" |
| 159 | # would mean that "D" relative path is present in PATH, which would make |
| 160 | # /bin/find later fail ("""The relative path 'D' is included in the PATH environment variable, which is insecure in combination with the -execdir action of find. Please remove that entry from $PATH""") |
| 161 | # even though the path seems to work fine for other tools. |
| 162 | # It looks like MSys "bash" has code to understand drive letter : in a PATH, |
| 163 | # but "find" doesn't. |
| 164 | - name: Extend environment PATH (non-Windows) |
| 165 | if: ${{ matrix.runner != 'windows-latest' }} |
| 166 | run: echo "PATH=${PATH}:${CASTLE_ENGINE_PATH}/installed/bin/:${GITHUB_WORKSPACE}/pasdoc/bin/" >> $GITHUB_ENV |
| 167 | - name: Extend environment PATH (Windows) |
| 168 | if: ${{ matrix.runner == 'windows-latest' }} |
| 169 | run: echo "PATH=${PATH}:`cygpath --unix ${CASTLE_ENGINE_PATH}/installed/bin/`:`cygpath --unix ${GITHUB_WORKSPACE}/pasdoc/bin/`" >> $GITHUB_ENV |
| 170 | |
| 171 | - name: Set environment FPC_OS |
| 172 | run: echo "FPC_OS="`fpc -iTO` >> $GITHUB_ENV |
| 173 | - name: Set environment FPC_CPU |
| 174 | run: echo "FPC_CPU="`fpc -iTP` >> $GITHUB_ENV |
| 175 | - name: Disable FPC version check (RPi 64) |
| 176 | if: ${{ matrix.runner == 'raspberry_pi_64' }} |
| 177 | run: echo "CASTLE_PACK_DISABLE_FPC_VERSION_CHECK=true" >> $GITHUB_ENV |
| 178 | |
| 179 | # check versions (and availability) of our requirements early |
| 180 | |
| 181 | - name: (Info) FPC version |
| 182 | run: fpc -iV |
| 183 | - name: (Info) Lazarus version |
| 184 | run: lazbuild --version |
| 185 | - name: (Info) Make version |
| 186 | run: make --version |
| 187 | - name: (Info) Sed version (macOS) |
| 188 | if: ${{ matrix.is_macos }} |
| 189 | run: gsed --version |
| 190 | - name: (Info) Sed version (non-macOS) |
| 191 | if: ${{ !matrix.is_macos }} |
| 192 | run: sed --version |
| 193 | # Make sure we got GNU Make, not Embarcadero make. |
| 194 | # This is important, as Delphi installer inserts Embarcadero make into PATH, |
| 195 | # earlier than Cygwin's. It has to be corrected after installation. |
| 196 | - name: (Info) Check GNU Make |
| 197 | run: if make -version 2>&1 | grep -i "GNU Make" -; then echo "OK, make from GNU"; else echo "ERROR, make not from GNU!"; exit 1; fi |
| 198 | |
| 199 | - name: Build Tools |
| 200 | run: | |
| 201 | rm -Rf installed/ |
| 202 | mkdir -p installed/ |
| 203 | make clean tools install PREFIX=${CASTLE_ENGINE_PATH}/installed/ |
| 204 | |
| 205 | - name: Build Examples |
| 206 | # Too slow on RPi |
| 207 | if : ${{ matrix.runner != 'raspberry_pi_64' && matrix.runner != 'raspberry_pi_32' }} |
| 208 | run: make clean examples CASTLE_CONSERVE_DISK_SPACE=true |
| 209 | |
| 210 | - name: Build And Run Auto-Tests |
| 211 | run: make tests |
| 212 | |
| 213 | # Fails at least on ubuntu-latest. TODO: Unsure how to set $FPCDIR, for now skip this test. |
| 214 | # - name: Build Using FpMake |
| 215 | # # Too slow on RPi |
| 216 | # # On macOS: we don't have fpmake "opengl" package ok after installing on macOS using fpcupdeluxe? |
| 217 | # # So this never executes now... |
| 218 | # if : ${{ matrix.runner != 'raspberry_pi_64' && matrix.runner != 'raspberry_pi_32' && matrix.runner != 'macos_x64'}} |
| 219 | # run: make clean test-fpmake |
| 220 | |
| 221 | - name: Build Lazarus Packages |
| 222 | run: | |
| 223 | lazbuild packages/castle_base.lpk |
| 224 | lazbuild packages/castle_window.lpk |
| 225 | lazbuild packages/castle_components.lpk |
| 226 | lazbuild packages/castle_editor_components.lpk |
| 227 | lazbuild packages/alternative_castle_window_based_on_lcl.lpk |
| 228 | |
| 229 | # TODO: also run examples-laz here |
| 230 | |
| 231 | - name: Build and Install PasDoc |
| 232 | run: | |
| 233 | wget https://github.com/pasdoc/pasdoc/archive/refs/heads/master.zip --output-document pasdoc-master.zip |
| 234 | unzip pasdoc-master.zip |
| 235 | mv pasdoc-master pasdoc |
| 236 | cd pasdoc |
| 237 | make |
| 238 | |
| 239 | - name: Pack Release |
| 240 | run: | |
| 241 | rm -f castle-engine*.zip # remove previous artifacts |
| 242 | ./tools/internal/pack_release/pack_release.sh ${FPC_OS} ${FPC_CPU} |
| 243 | - name: Archive Artifacts (zip) |
| 244 | # We don't archive build on: |
| 245 | # |
| 246 | # - macos-12, because build on macos_x64 is already good for us. |
| 247 | # Testing, both these runners produce the functionally equivalent zip |
| 248 | # (there are small differences in binaries, though both use the same FPC version |
| 249 | # but e.g. FPC puts absolute paths in some binaries, so they differ). |
| 250 | # We choose to use macos_x64 as the primary runner for the release, |
| 251 | # since this is our own machine (self hosted), we have more control over it. |
| 252 | # |
| 253 | # - windows-latest, because the test-and-pack-docker.yml is also doing |
| 254 | # equivalent build (castle-engine-7.0-alpha.snapshot-win64-x86_64.zip). |
| 255 | # Moreover that Docker job is also doing version bundled |
| 256 | # with FPC (castle-engine-7.0-alpha.snapshot-win64-x86_64-bundle.zip) |
| 257 | # and win32 (castle-engine-7.0-alpha.snapshot-win32-i386.zip). |
| 258 | # OTOH, windows-latest is doing castle-engine-setup-7.0-alpha.snapshot.exe, |
| 259 | # as it has to be done on Windows (with InnoSetup). |
| 260 | # |
| 261 | # The differences between doing a job in Docker and windows-latest are |
| 262 | # ignorable: |
| 263 | # - From Docker, we get Unix line endings even for Windows build |
| 264 | # since its a checkout on Linux. |
| 265 | # (disadvantage but ignorable, nothing seems to complain?), |
| 266 | # - PasDoc version from Docker is slightly different (advantage, |
| 267 | # we control PasDoc version in Docker better, consistent with others). |
| 268 | # - Docker build is a bit safer, as packing is a separate job, |
| 269 | # not depending that cge_clean_all in pack_release.sh |
| 270 | # cleans everything. |
| 271 | # |
| 272 | # - ubuntu-latest, because the test-and-pack-docker.yml is also doing |
| 273 | # equivalent build (castle-engine-7.0-alpha.snapshot-linux-x86_64.zip). |
| 274 | # The Docker job is a bit better, see above about windows-latest: |
| 275 | # PasDoc version in Docker is more consistent, |
| 276 | # and the build does not rely on cge_clean_all. |
| 277 | # |
| 278 | if: ${{ matrix.runner != 'macos-12' && matrix.runner != 'windows-latest' && matrix.runner != 'ubuntu-latest' }} |
| 279 | uses: actions/upload-artifact@v4 |
| 280 | with: |
| 281 | name: ${{ matrix.runner }}-release |
| 282 | path: "castle-engine*.zip" |
| 283 | if-no-files-found: error |
| 284 | |
| 285 | - name: Download bundled FPC |
| 286 | if: ${{ matrix.runner == 'windows-latest' }} |
| 287 | uses: robinraju/[email protected] |
| 288 | with: |
| 289 | repository: "castle-engine/cge-fpc" |
| 290 | latest: true |
| 291 | fileName: "fpc-win64-x86_64.zip" |
| 292 | |
| 293 | - name: Pack Release (Windows Installer, Bundled FPC) |
| 294 | if: ${{ matrix.runner == 'windows-latest' }} |
| 295 | run: CGE_PACK_BUNDLE=yes ./tools/internal/pack_release/pack_release.sh windows_installer |
| 296 | - name: Archive Artifacts (exe) |
| 297 | if: ${{ matrix.runner == 'windows-latest' }} |
| 298 | uses: actions/upload-artifact@v4 |
| 299 | with: |
| 300 | name: ${{ matrix.runner }}-installer-release |
| 301 | path: "castle-engine-setup-*.exe" |
| 302 | if-no-files-found: error |