|
| 1 | +name: 'Locate vcvarsall and Setup Environment' |
| 2 | +description: 'Locates vcvarsall.bat, sets up the environment, and handles PATH updates.' |
| 3 | +inputs: |
| 4 | + architecture: |
| 5 | + description: 'Target architecture (x64 or x86)' |
| 6 | + required: true |
| 7 | + default: 'x64' |
| 8 | +outputs: |
| 9 | + vcvarsall_path: |
| 10 | + description: "Path to vcvarsall.bat" |
| 11 | + value: ${{ steps.find-vcvarsall.outputs.vcvarsall_path }} |
| 12 | +runs: |
| 13 | + using: "composite" |
| 14 | + steps: |
| 15 | + |
| 16 | + - name: Setup VCPKG |
| 17 | + uses: microsoft/onnxruntime-github-actions/[email protected] |
| 18 | + with: |
| 19 | + vcpkg-version: '2025.03.19' |
| 20 | + vcpkg-hash: '17e96169cd3f266c4716fcdc1bb728e6a64f103941ece463a2834d50694eba4fb48f30135503fd466402afa139abc847ef630733c442595d1c34979f261b0114' |
| 21 | + cmake-version: '3.31.6' |
| 22 | + cmake-hash: '0f1584e8666cf4a65ec514bd02afe281caabf1d45d2c963f3151c41484f457386aa03273ab25776a670be02725354ce0b46f3a5121857416da37366342a833a0' |
| 23 | + add-cmake-to-path: 'true' |
| 24 | + disable-terrapin: 'false' |
| 25 | + |
| 26 | + - name: Verify vcpkg setup |
| 27 | + shell: pwsh # Use powershell to easily access env var |
| 28 | + run: | |
| 29 | + Write-Host "VCPKG_INSTALLATION_ROOT is set to: $env:VCPKG_INSTALLATION_ROOT" |
| 30 | + & "$env:VCPKG_INSTALLATION_ROOT/vcpkg" version |
| 31 | +
|
| 32 | + - name: Find vcvarsall.bat |
| 33 | + id: find-vcvarsall |
| 34 | + shell: python # Use Python shell |
| 35 | + run: | |
| 36 | + import os |
| 37 | + import subprocess |
| 38 | +
|
| 39 | + vswhere_path = os.path.join(os.environ["ProgramFiles(x86)"], "Microsoft Visual Studio", "Installer", "vswhere.exe") |
| 40 | +
|
| 41 | + try: |
| 42 | + process = subprocess.run([vswhere_path, "-latest", "-property", "installationPath"], capture_output=True, text=True, check=True) |
| 43 | + vs_install_path = process.stdout.strip() |
| 44 | + vcvarsall_path = os.path.join(vs_install_path, "VC", "Auxiliary", "Build", "vcvarsall.bat") |
| 45 | +
|
| 46 | + if os.path.exists(vcvarsall_path): |
| 47 | + print(f"vcvarsall found at: {vcvarsall_path}") |
| 48 | + # Use GITHUB_OUTPUT environment variable |
| 49 | + with open(os.environ['GITHUB_OUTPUT'], 'a') as f: |
| 50 | + f.write(f"vcvarsall_path={vcvarsall_path}\n") |
| 51 | + else: |
| 52 | + print(f"vcvarsall.bat not found at expected path: {vcvarsall_path}") |
| 53 | + # Use 'exit(1)' for Python to properly signal failure to GitHub Actions |
| 54 | + exit(1) |
| 55 | +
|
| 56 | +
|
| 57 | + except subprocess.CalledProcessError as e: |
| 58 | + print(f"Error running vswhere.exe: {e}") |
| 59 | + print(f"vswhere output: {e.stdout}") |
| 60 | + print(f"vswhere stderr: {e.stderr}") |
| 61 | + exit(1) # Exit with a non-zero code on error |
| 62 | + except FileNotFoundError: |
| 63 | + print(f"vswhere.exe not found at: {vswhere_path}") |
| 64 | + exit(1) |
| 65 | +
|
| 66 | +
|
| 67 | + - name: Setup Environment |
| 68 | + shell: cmd |
| 69 | + run: | |
| 70 | + REM Get initial environment variables |
| 71 | + set > initial_env.txt |
| 72 | +
|
| 73 | + REM Call vcvarsall.bat using the output from the previous step |
| 74 | + call "${{ steps.find-vcvarsall.outputs.vcvarsall_path }}" ${{ inputs.architecture }} |
| 75 | +
|
| 76 | + REM Get environment variables after calling vcvarsall.bat |
| 77 | + set > final_env.txt |
| 78 | +
|
| 79 | + REM Call the Python script to update the GitHub Actions environment |
| 80 | + python ${{ github.action_path }}\update_environment.py |
0 commit comments