aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/test.yml
blob: 0ecc63a537e9671e27f308163ef128735a9e9db8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
name: test

on:
  push:
    branches: main
    paths-ignore:
      - "docs"
      - "**/*.md"
  pull_request:
    branches: '*'
    paths-ignore:
      - "docs"
      - "**/*.md"
  workflow_dispatch:
    branches: '*'

jobs:
  ##############################################################################
  ShellLint:
    runs-on: "ubuntu-latest"

    steps:
    - uses: actions/checkout@master

    - name: Prep
      run: |
        sudo apt-get install -y shellcheck

    - name: Shellcheck
      run: |
        shellcheck ./configure

  ##############################################################################
  TestMatrix:
    strategy:
      matrix:
        lua-version: ["5.4", "luajit-2.1"]
        os: ["ubuntu-latest", "macos-latest"]
    runs-on: ${{ matrix.os }}

    steps:
    - uses: actions/checkout@master

    - uses: hishamhm/gh-actions-lua@master
      with:
        luaVersion: ${{ matrix.lua-version }}

    - uses: leafo/gh-actions-luarocks@v5

    - name: 'Setup macOS deps'
      if: ${{ contains(matrix.os, 'macos') }}
      run: brew install openssl bzip2

    - name: 'Setup Ubuntu deps'
      if: ${{ contains(matrix.os, 'ubuntu') }}
      run: sudo apt-get install libbz2-dev

    - name: Prep
      run: |
        luarocks install compat53
        luarocks install busted
        luarocks install cluacov
        luarocks install busted-htest

    - name: Unit Test
      run: |
        busted -o htest --exclude-tags=git,integration --verbose -Xhelper "lua_dir=$(luarocks config variables.LUA_DIR),ci"
        busted -o htest --exclude-tags=git,integration --verbose -Xhelper "lua_dir=$(luarocks config variables.LUA_DIR),ci,env=full"

    - name: Integration Test
      run: |
        busted -o htest --exclude-tags=ssh,gpg,git,unit,quick --verbose -Xhelper "lua_dir=$(luarocks config variables.LUA_DIR),ci"
        busted -o htest --exclude-tags=ssh,gpg,git,unit,quick --verbose -Xhelper "lua_dir=$(luarocks config variables.LUA_DIR),ci,env=full"

    - name: Generate Coverage Report
      run: luacov -c "testrun/luacov.config"

    - name: Setup Python
      uses: actions/setup-python@v5
      with:
        python-version: '3.11'

    - name: Install Codecov
      run: pip install codecov

    - name: Upload Coverage Report
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
      run: codecov -t "$CODECOV_TOKEN" -f "testrun/luacov.report.out" -X gcov

  ##############################################################################
  SmokeTest:
    runs-on: "ubuntu-latest"
    steps:
    - uses: actions/checkout@master

    - uses: hishamhm/gh-actions-lua@master
      with:
        luaVersion: "5.4"

    - name: Smoke Test
      run: |
        ./configure
        ./makedist dev $(dirname $(dirname $(which lua)))
        ./smoke_test.sh luarocks-dev.tar.gz

  ##############################################################################
  BinaryBuild:
    runs-on: "ubuntu-latest"
    steps:
    - uses: actions/checkout@master

    - uses: hishamhm/gh-actions-lua@master
      with:
        luaVersion: "5.4"

    - name: 'Setup Ubuntu deps'
      run: sudo apt-get install libbz2-dev

    - name: Binary Build Smoke Test
      run: |
        ./configure
        ./makedist dev $(dirname $(dirname $(which lua)))
        ./smoke_test.sh luarocks-dev.tar.gz binary

  ##############################################################################
  WindowsTest:
    runs-on: "windows-latest"
    defaults:
      run:
        shell: cmd
    strategy:
      fail-fast: false
      matrix:
        include:
          #
          # Visual Studio x64
          #

          # quick tests
          - LUAV: "2.1"
            LUAT: "luajit"
            COMPILER: "vs"
            FILES: ""
            EXCLUDE: "integration,unit"
            TESTTYPE: ""
            ARCH: x64
          # Lua 5.4 tests
          - LUAV: "5.4"
            LUAT: "lua"
            COMPILER: "vs"
            FILES: ""
            EXCLUDE: "integration,quick"
            TESTTYPE: "unit"
            ARCH: x64
          - LUAV: "5.4"
            LUAT: "lua"
            COMPILER: "vs"
            FILES: ""
            EXCLUDE: "unit,quick"
            TESTTYPE: ""
            ARCH: x64
          - LUAV: "5.4"
            LUAT: "lua"
            COMPILER: "vs"
            FILES: "spec//build_spec.lua"
            EXCLUDE: ""
            TESTTYPE: ""
            ARCH: x64
          # LuaJIT 2.1 tests
          - LUAV: "2.1"
            LUAT: "luajit"
            COMPILER: "vs"
            FILES: ""
            EXCLUDE: "integration,quick"
            TESTTYPE: "unit"
            ARCH: x64
          - LUAV: "2.1"
            LUAT: "luajit"
            COMPILER: "vs"
            FILES: ""
            EXCLUDE: "unit,quick"
            TESTTYPE: ""
            ARCH: x64
          - LUAV: "2.1"
            LUAT: "luajit"
            COMPILER: "vs"
            FILES: "spec//build_spec.lua"
            EXCLUDE: ""
            TESTTYPE: ""
            ARCH: x64

          #
          # Visual Studio x86
          #

          # quick tests
          - LUAV: "2.1"
            LUAT: "luajit"
            COMPILER: "vs"
            FILES: ""
            EXCLUDE: "integration,unit"
            TESTTYPE: ""
            ARCH: x86
          # Lua 5.4 tests
          - LUAV: "5.4"
            LUAT: "lua"
            COMPILER: "vs"
            FILES: ""
            EXCLUDE: "integration,quick"
            TESTTYPE: "unit"
            ARCH: x86
          - LUAV: "5.4"
            LUAT: "lua"
            COMPILER: "vs"
            FILES: ""
            EXCLUDE: "unit,quick"
            TESTTYPE: ""
            ARCH: x86
          - LUAV: "5.4"
            LUAT: "lua"
            COMPILER: "vs"
            FILES: "spec//build_spec.lua"
            EXCLUDE: ""
            TESTTYPE: ""
            ARCH: x86
          # LuaJIT 2.1 tests
          - LUAV: "2.1"
            LUAT: "luajit"
            COMPILER: "vs"
            FILES: ""
            EXCLUDE: "integration,quick"
            TESTTYPE: "unit"
            ARCH: x86
          - LUAV: "2.1"
            LUAT: "luajit"
            COMPILER: "vs"
            FILES: ""
            EXCLUDE: "unit,quick"
            TESTTYPE: ""
            ARCH: x86
          - LUAV: "2.1"
            LUAT: "luajit"
            COMPILER: "vs"
            FILES: "spec//build_spec.lua"
            EXCLUDE: ""
            TESTTYPE: ""
            ARCH: x86

          #
          # MinGW-w64 with Universal C Run Time
          # provided by MSYS2
          #

          # quick tests
          - LUAV: "2.1"
            LUAT: "luajit"
            COMPILER: "mingw"
            FILES: ""
            EXCLUDE: "integration,unit"
            TESTTYPE: ""
          # Lua 5.4 tests
          - LUAV: "5.4"
            LUAT: "lua"
            COMPILER: "mingw"
            FILES: ""
            EXCLUDE: "integration,quick"
            TESTTYPE: "unit"
          - LUAV: "5.4"
            LUAT: "lua"
            COMPILER: "mingw"
            FILES: ""
            EXCLUDE: "unit,quick"
            TESTTYPE: ""
          - LUAV: "5.4"
            LUAT: "lua"
            COMPILER: "mingw"
            FILES: "spec//build_spec.lua"
            EXCLUDE: ""
            TESTTYPE: ""
          # LuaJIT 2.1 tests
          - LUAV: "2.1"
            LUAT: "luajit"
            COMPILER: "mingw"
            FILES: ""
            EXCLUDE: "integration,quick"
            TESTTYPE: "unit"
          - LUAV: "2.1"
            LUAT: "luajit"
            COMPILER: "mingw"
            FILES: ""
            EXCLUDE: "unit,quick"
            TESTTYPE: ""
          - LUAV: "2.1"
            LUAT: "luajit"
            COMPILER: "mingw"
            FILES: "spec//build_spec.lua"
            EXCLUDE: ""
            TESTTYPE: ""
    env:
      # The following env variables
      # only applies to Visual Studio
      LUAROCKS_DEPS_DIR: c:\external
      LUAROCKS_DEPS_OPENSSL_VER: "3.4.1"
      LUAROCKS_DEPS_ZLIB_VER: "1.3.1"
      # The following env variable
      # applies to both Visual Studio and MinGW-w64
      LUAROCKS_WINDOWS_GH_CI: "ci-windows"
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup MSVC dev prompt
        if: ${{ matrix.COMPILER == 'vs' }}
        uses: ilammy/msvc-dev-cmd@v1
        with:
          arch: ${{ matrix.ARCH }}

      - name: Add bin directory of dependencies to system PATH environment variable
        if: ${{ matrix.COMPILER == 'vs' }}
        run: echo ${{ env.LUAROCKS_DEPS_DIR }}\bin>>${{ github.path }}

      - name: Restore zlib tarball
        if: ${{ matrix.COMPILER == 'vs' }}
        id: restore-zlib-tarball
        uses: actions/cache/restore@v4
        with:
          path: zlib-${{ env.LUAROCKS_DEPS_ZLIB_VER }}.tar.gz
          key: zlib-${{ env.LUAROCKS_DEPS_ZLIB_VER }}

      - name: Download zlib
        if: ${{ matrix.COMPILER == 'vs' && steps.restore-zlib-tarball.outputs.cache-hit != 'true' }}
        run: |
          curl -o "${{ github.workspace }}\zlib-${{ env.LUAROCKS_DEPS_ZLIB_VER }}.tar.gz" ^
              "https://zlib.net/zlib-${{ env.LUAROCKS_DEPS_ZLIB_VER }}.tar.gz"

      - name: Save zlib tarball
        if: ${{ matrix.COMPILER == 'vs' && steps.restore-zlib-tarball.outputs.cache-hit != 'true' }}
        uses: actions/cache/save@v4
        with:
          path: zlib-${{ env.LUAROCKS_DEPS_ZLIB_VER }}.tar.gz
          key: zlib-${{ env.LUAROCKS_DEPS_ZLIB_VER }}

      - name: Install dependency (zlib)
        if: ${{ matrix.COMPILER == 'vs' }}
        run: |
          cd "${{ runner.temp }}" && mkdir zlib && cd zlib && ^
          tar -xf "${{ github.workspace }}\zlib-${{ env.LUAROCKS_DEPS_ZLIB_VER }}.tar.gz"

          IF "${{ matrix.COMPILER }}"=="vs" (
            SET CMAKE_GENERATOR=NMake Makefiles
            SET CC=cl
          ) ELSE (
            SET CMAKE_GENERATOR=MinGW Makefiles
            SET CC=gcc
          )

          cmake -G "%CMAKE_GENERATOR%" ^
            -DCMAKE_C_COMPILER=%CC% ^
            -DCMAKE_BUILD_TYPE=Release ^
            -DBUILD_SHARED_LIBS=ON ^
            -DBUILD_STATIC_LIBS=OFF ^
            --install-prefix "${{ env.LUAROCKS_DEPS_DIR }}" ^
            -S zlib-${{ env.LUAROCKS_DEPS_ZLIB_VER }} ^
            -B _build-zlib && ^
          cmake --build _build-zlib --config Release && ^
          cmake --install _build-zlib --config Release

          IF "${{ matrix.COMPILER }}"=="vs" (
            copy "${{ env.LUAROCKS_DEPS_DIR }}\lib\zlib.lib" ^
              "${{ env.LUAROCKS_DEPS_DIR }}\lib\z.lib"
          )

      - name: Restore bzip2 tarball
        if: ${{ matrix.COMPILER == 'vs' }}
        id: restore-bzip2-tarball
        uses: actions/cache/restore@v4
        with:
          path: bzip2.tar.gz
          key: bzip2

      - name: Download bzip2
        if: ${{ matrix.COMPILER == 'vs' && steps.restore-bzip2-tarball.outputs.cache-hit != 'true' }}
        run: |
          cd "${{ runner.temp }}" && ^
          git clone https://gitlab.com/bzip2/bzip2 && ^
          tar -czvf "${{ github.workspace }}\bzip2.tar.gz" bzip2

      - name: Save bzip2 tarball
        if: ${{ matrix.COMPILER == 'vs' && steps.restore-bzip2-tarball.outputs.cache-hit != 'true' }}
        uses: actions/cache/save@v4
        with:
          path: bzip2.tar.gz
          key: bzip2

      - name: Install dependency (libbz2)
        if: ${{ matrix.COMPILER == 'vs' }}
        run: |
          cd "${{ runner.temp }}" && ^
          tar -xf "${{ github.workspace }}\bzip2.tar.gz"

          IF "${{ matrix.COMPILER }}"=="vs" (
            SET CMAKE_GENERATOR=NMake Makefiles
            SET CC=cl
          ) ELSE (
            SET CMAKE_GENERATOR=MinGW Makefiles
            SET CC=gcc
          )

          cmake -G "%CMAKE_GENERATOR%" ^
            -DCMAKE_C_COMPILER=%CC% ^
            -DCMAKE_BUILD_TYPE=Release ^
            -DENABLE_SHARED_LIB=ON ^
            -DENABLE_LIB_ONLY=ON ^
            --install-prefix "${{ env.LUAROCKS_DEPS_DIR }}" ^
            -S bzip2 ^
            -B _build-bz2 && ^
          cmake --build _build-bz2 --config Release && ^
          cmake --install _build-bz2 --config Release

          IF EXIST "${{ env.LUAROCKS_DEPS_DIR }}\lib\bz2.dll" (
            copy /Y "${{ env.LUAROCKS_DEPS_DIR }}\lib\bz2.dll" ^
              "${{ env.LUAROCKS_DEPS_DIR }}\bin"
          )

      - name: Restore OpenSSL installer
        if: ${{ matrix.COMPILER == 'vs' }}
        id: restore-openssl-installer
        uses: actions/cache/restore@v4
        with:
          path: build\openssl-installer-${{ env.LUAROCKS_DEPS_OPENSSL_VER }}-${{ matrix.ARCH }}.exe
          key: openssl-${{ env.LUAROCKS_DEPS_OPENSSL_VER }}-${{ matrix.ARCH }}

        # On Windows, up to date (OpenSSL 3.4.1), the process
        # to build OpenSSL from source code is quite slow (20min ~ 30min).
        # In order to get pre-built binaries (CI purposes) for the OpenSSL library
        # ABI-compatible with MSVC, a faster approach can be achieved
        # by downloading the binaries from a known third-party.
        # slproweb ( https://slproweb.com/products/Win32OpenSSL.html ) is a long
        # time third-party providing pre-built OpenSSL binaries through
        # Windows installers.
        # Note: AppVeyor pre-built binaries for OpenSSL
        #       also come from this provider.

        # Below, we follow the idea contained at
        # https://github.com/actions/runner-images/blob/a88fc4db06ae2350cb3128627b7fe4b5ee847f8e/images/windows/scripts/build/Install-OpenSSL.ps1
        # to install OpenSSL from slproweb in a suitable directory.
      - name: Download OpenSSL installer
        if: ${{ matrix.COMPILER == 'vs' && steps.restore-openssl-installer.outputs.cache-hit != 'true' }}
        shell: pwsh
        run: |
          $installerName = "${{ github.workspace }}\build\openssl-installer-${{ env.LUAROCKS_DEPS_OPENSSL_VER }}-${{ matrix.ARCH }}.exe";

          $arch = 'INTEL';

          if ("${{ matrix.ARCH }}" -eq "x86")
          {
            $bits = '32';
          }
          else
          {
            $bits = '64';
          }

          $light = $false;
          $version = "${{ env.LUAROCKS_DEPS_OPENSSL_VER }}";

          # Fetch available installers list
          $jsonUrl = 'https://raw.githubusercontent.com/slproweb/opensslhashes/master/win32_openssl_hashes.json';

          $installersAvailable = (Invoke-RestMethod $jsonUrl).files;
          $installerNames = $installersAvailable | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name;

          $installerUrl = $null;
          $installerHash = $null;

          foreach ($key in $installerNames) {
            $installer = $installersAvailable.$key;
            if (($installer.light -eq $light) -and ($installer.arch -eq $arch) -and ($installer.bits -eq $bits) -and ($installer.installer -eq "exe") -and ($installer.basever -eq $version)) {
              $installerUrl = $installer.url;
              $installerHash = $installer.sha512.Replace("-", "").ToLower();
              break;
            }
          }

          if ($installerUrl -eq $null) {
            throw "Installer not found for version $version";
          }

          # Download the installer
          curl "--create-dirs" "-o" "${installerName}" "${installerUrl}";

          # Validate sha512 checksum
          $downloadedHash = Get-FileHash -Path "${installerName}" -Algorithm "SHA512" |
            Select-Object -ExpandProperty Hash;

          $downloadedHash = $downloadedHash.Replace("-", "").ToLower();

          if ("${downloadedHash}" -ne "${installerHash}")
          {
            throw "Installer SHA512 hash mismatch: (Expected ${installerHash}), (Got ${downloadedHash})";
          }

      - name: Save OpenSSL installer
        if: ${{ matrix.COMPILER == 'vs' && steps.restore-openssl-installer.outputs.cache-hit != 'true' }}
        uses: actions/cache/save@v4
        with:
          path: build\openssl-installer-${{ env.LUAROCKS_DEPS_OPENSSL_VER }}-${{ matrix.ARCH }}.exe
          key: openssl-${{ env.LUAROCKS_DEPS_OPENSSL_VER }}-${{ matrix.ARCH }}

      - name: Install dependency (OpenSSL)
        if: ${{ matrix.COMPILER == 'vs' }}
        shell: pwsh
        run: |
          Start-Process `
            -FilePath "${{ github.workspace }}\build\openssl-installer-${{ env.LUAROCKS_DEPS_OPENSSL_VER }}-${{ matrix.ARCH }}.exe" `
            -ArgumentList "/verysilent", "/sp-", "/suppressmsgboxes", "/DIR=`"${{ env.LUAROCKS_DEPS_DIR }}`"" `
            -Wait;

          $deps_lib_dir = Join-Path -Path "${{ env.LUAROCKS_DEPS_DIR }}" -ChildPath "lib";
          if (Test-Path -Path $deps_lib_dir)
          {
            foreach ($imp_lib in "libssl.lib", "libcrypto.lib")
            {
              $current_imp_lib = Join-Path -Path "${deps_lib_dir}" -ChildPath "${imp_lib}";
              if (-not (Test-Path -Path $current_imp_lib))
              {
                $current_imp_lib = Get-ChildItem -Path $deps_lib_dir -Recurse -File |
                  Where-Object Name -EQ "${imp_lib}" |
                  Select-Object -ExpandProperty FullName -First 1;

                Copy-Item -Path $current_imp_lib -Destination $deps_lib_dir;
              }
            }
          }

      # When running many concurrent jobs,
      # pacman might fail to download packages
      # from MSYS2 servers due a high load.
      # So, retry the installation a few times
      - name: Setup mingw-w64 and dependencies
        if: ${{ matrix.COMPILER == 'mingw' }}
        run: |
          SET PKGS_TO_INSTALL=mingw-w64-ucrt-x86_64-cc ^
            mingw-w64-ucrt-x86_64-make ^
            mingw-w64-ucrt-x86_64-zlib ^
            mingw-w64-ucrt-x86_64-bzip2 ^
            mingw-w64-ucrt-x86_64-openssl

          SET "TRIES=0"
          SET "MAX_TRIES=5"
          SET "SECS_TO_WAIT=1"

          GOTO :INSTALL_FROM_MSYS2

          :INSTALL_FROM_MSYS2
          C:\msys64\usr\bin\bash "-lc" ^
            "pacman -S %PKGS_TO_INSTALL% --noconfirm"

          IF %ERRORLEVEL% EQU 0 (
            echo C:\msys64\ucrt64\bin>>${{ github.path }}
          ) ELSE (
            SET /A "TRIES=TRIES+1"
            IF %TRIES% LSS %MAX_TRIES% (
              echo Attempt %TRIES% out of %MAX_TRIES% to install packages failed
              SET /A "SECS_TO_WAIT*=2"
              echo Waiting %SECS_TO_WAIT% seconds to retry
              SLEEP %SECS_TO_WAIT%
              GOTO :INSTALL_FROM_MSYS2
            ) ELSE (
              echo Failed to install mingw-w64 and dependencies from MSYS2
              EXIT /B 1
            )
          )

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          # employ the latest Python version
          # described at https://pypi.org/project/hererocks/
          python-version: '3.11'

      - name: Install SSL certificate
        run: |
          pip install --upgrade certifi
          FOR /F "tokens=* USEBACKQ" %%F IN (`python -c "import certifi;print(certifi.where())"`) DO (
            echo SSL_CERT_FILE=%%F>>${{ github.env }}
          )

      - name: Install ${{ matrix.LUAT }} ${{ matrix.LUAV }}
        run: |
          SET "CURRENT_LUA_DIRNAME=lua_install-${{ matrix.LUAV }}"
          SET "CURRENT_LUA_DIR=${{ github.workspace }}\%CURRENT_LUA_DIRNAME%"
          SET "CURRENT_LUA_BIN=%CURRENT_LUA_DIR%\bin"
          SET "CURRENT_LUA_INTERPRETER=%CURRENT_LUA_BIN%\lua.exe"

          pip install hererocks && ^
          hererocks ^
            "%CURRENT_LUA_DIRNAME%" ^
            "--${{ matrix.LUAT }}" "${{ matrix.LUAV }}" ^
            --luarocks latest ^
            "--target=${{ matrix.COMPILER }}"

          IF %ERRORLEVEL% NEQ 0 (
            echo Failed to install Lua / LuaRocks
            EXIT /B 1
          )

          echo %CURRENT_LUA_BIN%>>${{ github.path }}
          echo CURRENT_LUA_DIR=%CURRENT_LUA_DIR%>>${{ github.env }}
          echo CURRENT_LUA_BIN=%CURRENT_LUA_BIN%>>${{ github.env }}
          echo CURRENT_LUA_INTERPRETER=%CURRENT_LUA_INTERPRETER%>>${{ github.env }}
          echo BUSTED_BAT=%CURRENT_LUA_BIN%\busted.bat>>${{ github.env }}
          echo LUACOV_BAT=%CURRENT_LUA_BIN%\luacov.bat>>${{ github.env }}

      - name: Configure MSVCRT to build dependencies
        if: ${{ matrix.COMPILER == 'mingw' }}
        run: |
          SET MSVCRT_LUA_CODE=local pe = require [[win32.pe-parser]]; ^
            local rt, _ = pe.msvcrt [[${{ env.CURRENT_LUA_INTERPRETER }}]]; ^
            print(rt or 'nil')

          FOR /F "tokens=* USEBACKQ" %%I IN (`lua -e "%MSVCRT_LUA_CODE%"`) DO (
            IF NOT "%%I"=="nil" (
              luarocks config variables.MSVCRT "%%I"
            )
          )

      - name: Install compat53
        run: luarocks install compat53

      - name: Install busted
        run: IF NOT EXIST "${{ env.BUSTED_BAT }}" luarocks install busted

      - name: Install cluacov
        run: IF NOT EXIST "${{ env.LUACOV_BAT }}" luarocks install cluacov

      - name: Install busted-htest
        run: luarocks install busted-htest

      - name: Run test
        run: |
          busted ^
            -o htest ^
            -v "--lpath=.//?.lua" ^
            "--exclude-tags=ssh,unix,${{ matrix.EXCLUDE }}" ^
            -Xhelper ^
            "lua_dir=${{ env.CURRENT_LUA_DIR }},${{ env.LUAROCKS_WINDOWS_GH_CI }},${{ matrix.COMPILER }}" ^
            ${{ matrix.FILES }}

      - name: Run unit test
        if: ${{ matrix.TESTTYPE == 'unit' }}
        run: |
          busted ^
            -o htest ^
            -v "--lpath=.//?.lua" ^
            "--exclude-tags=ssh,unix,${{ matrix.EXCLUDE }}" ^
            -Xhelper ^
            "lua_dir=${{ env.CURRENT_LUA_DIR }},${{ env.LUAROCKS_WINDOWS_GH_CI }},${{ matrix.COMPILER }},env=full" ^
            ${{ matrix.FILES }}

      - name: Generate coverage report
        run: luacov -c "testrun/luacov.config"

      - name: Install Codecov
        run: pip install codecov

      - name: Upload coverage report
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
        run: codecov -t "%CODECOV_TOKEN%" -f "testrun/luacov.report.out" -X gcov