qtgithub-actions

Cannot find prebuilt Qt binaries in github action


I'm trying to build-release a Qt-6 application through github action. It works for Ubuntu-latest and macOS-latest but fails for Windows-latest. Here is my script:

- name: Install dependencies (Windows)
      if: matrix.os == 'windows-latest'
      run: |
        choco install ninja -y
        choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' -y
    - name: Download and Extract Qt Prebuilt Binaries (Windows)
      if: matrix.os == 'windows-latest'
      run: |
        $qtDownloadUrl = "https://download.qt.io/official_releases/qt/6.5/6.5.3/qt-opensource-windows-x86-6.5.3.exe"
        $qtInstaller = "C:\\QtInstaller.exe"
        Invoke-WebRequest -Uri $qtDownloadUrl -OutFile $qtInstaller
        Start-Process -FilePath $qtInstaller -ArgumentList "--silent", "--platform", "msvc2019_64" -Wait
        Remove-Item -Path $qtInstaller
      shell: pwsh

    - name: Verify Qt Installation (Windows)
      if: matrix.os == 'windows-latest'
      run: |
        $qtPath = "C:\\Qt\\6.5.3\\msvc2019_64\\lib\\cmake"
        if (!(Test-Path $qtPath)) {
          Write-Error "Qt prebuilt binaries not found at $qtPath. Installation failed."
          exit 1
        } else {
          Write-Output "Qt installation found at $qtPath"
        }
      shell: pwsh

    - name: Configure CMake (Windows)
      if: matrix.os == 'windows-latest'
      run: |
        call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Auxiliary\\Build\\vcvars64.bat" && ^
        cmake -B D:\\a\\Notepad--\\Notepad--\\build ^
          -DCMAKE_BUILD_TYPE=Release ^
          -DCMAKE_PREFIX_PATH="C:\\Qt\\6.5.3\\msvc2019_64\\lib\\cmake" ^
          -G Ninja ^
          -S D:\\a\\Notepad--\\Notepad--
      shell: cmd

    - name: Build application (Windows)
      if: matrix.os == 'windows-latest'
      run: |
        call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Auxiliary\\Build\\vcvars64.bat" && ^
        cmake --build D:\\a\\Notepad--\\Notepad--\\build --config Release
      shell: cmd

    - name: Package application (Windows)
      if: matrix.os == 'windows-latest'
      run: |
        cd D:\\a\\Notepad--\\Notepad--\\build
        Compress-Archive -Path . -DestinationPath application.zip
      shell: cmd

The URL: https://download.qt.io/official_releases/qt/6.5/6.5.3/qt-opensource-windows-x86-6.5.3.exe is not valid and I don't know how to get the right URL.

I have tried Qt online and offline installer and build from source but all of them are very time consuming and I failed at the end.


Solution

  • Instead of building Qt from source or manually downloading/installing it, you can use https://github.com/jurplel/install-qt-action.

    It supports Qt version 6+ that you need and the functionality of caching as well.

    Qt will be installed and added to PATH automatically for subsequent steps.