Skip to content

Commit 47bd046

Browse files
authored
Convert Windows CPU CI Pipeline to Github Actions (#23996)
1 parent 6dd6ef9 commit 47bd046

19 files changed

+1119
-492
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
- name: Find vcvarsall.bat
16+
id: find-vcvarsall
17+
shell: python # Use Python shell
18+
run: |
19+
import os
20+
import subprocess
21+
22+
vswhere_path = os.path.join(os.environ["ProgramFiles(x86)"], "Microsoft Visual Studio", "Installer", "vswhere.exe")
23+
24+
try:
25+
process = subprocess.run([vswhere_path, "-latest", "-property", "installationPath"], capture_output=True, text=True, check=True)
26+
vs_install_path = process.stdout.strip()
27+
vcvarsall_path = os.path.join(vs_install_path, "VC", "Auxiliary", "Build", "vcvarsall.bat")
28+
29+
if os.path.exists(vcvarsall_path):
30+
print(f"vcvarsall found at: {vcvarsall_path}")
31+
# Use GITHUB_OUTPUT environment variable
32+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
33+
f.write(f"vcvarsall_path={vcvarsall_path}\n")
34+
else:
35+
print(f"vcvarsall.bat not found at expected path: {vcvarsall_path}")
36+
# Use 'exit(1)' for Python to properly signal failure to GitHub Actions
37+
exit(1)
38+
39+
40+
except subprocess.CalledProcessError as e:
41+
print(f"Error running vswhere.exe: {e}")
42+
print(f"vswhere output: {e.stdout}")
43+
print(f"vswhere stderr: {e.stderr}")
44+
exit(1) # Exit with a non-zero code on error
45+
except FileNotFoundError:
46+
print(f"vswhere.exe not found at: {vswhere_path}")
47+
exit(1)
48+
49+
50+
- name: Setup Environment
51+
shell: cmd
52+
run: |
53+
REM Get initial environment variables
54+
set > initial_env.txt
55+
56+
REM Call vcvarsall.bat using the output from the previous step
57+
call "${{ steps.find-vcvarsall.outputs.vcvarsall_path }}" ${{ inputs.architecture }}
58+
59+
REM Get environment variables after calling vcvarsall.bat
60+
set > final_env.txt
61+
62+
REM Call the Python script to update the GitHub Actions environment
63+
python ${{ github.action_path }}\update_environment.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@echo off
2+
setlocal
3+
4+
set vswherepath="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
5+
set vcvarsall_arch=%1
6+
if "%vcvarsall_arch%" == "x86" (
7+
set vcvarsall_arch=x86
8+
) else (
9+
set vcvarsall_arch=x64
10+
)
11+
12+
for /f "usebackq delims=" %%i in (`%vswherepath% -latest -property installationPath`) do (
13+
if exist "%%i\VC\Auxiliary\Build\vcvars%vcvarsall_arch%.bat" (
14+
set "vcvarsall=%%i\VC\Auxiliary\Build\vcvars%vcvarsall_arch%.bat"
15+
)
16+
)
17+
18+
echo "Get initial environment variables"
19+
set > initial_env.txt
20+
21+
echo "Call vcvarsall.bat"
22+
call "%vcvarsall%"
23+
24+
echo "Get environment variables after calling vcvarsall.bat"
25+
set > final_env.txt
26+
27+
echo "Call the Python script to update the GitHub Actions environment"
28+
python "%~dp0\update_environment.py"
29+
30+
endlocal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import re
3+
4+
5+
def read_env_file(filepath):
6+
env_vars = {}
7+
with open(filepath) as f:
8+
for line in f:
9+
match = re.match(r"^(.*?)=(.*)$", line.strip())
10+
if match:
11+
env_vars[match.group(1).upper()] = match.group(2)
12+
return env_vars
13+
14+
15+
initial_env = read_env_file("initial_env.txt")
16+
final_env = read_env_file("final_env.txt")
17+
18+
for key, value in final_env.items():
19+
if key not in initial_env or initial_env[key] != value:
20+
if key.startswith("_"):
21+
continue
22+
if key.upper() == "PATH":
23+
new_paths = value.split(";")
24+
initial_paths = initial_env.get("PATH", "").split(";")
25+
added_paths = [p for p in new_paths if p not in initial_paths and p]
26+
27+
if added_paths:
28+
print("Adding paths")
29+
with open(os.environ["GITHUB_PATH"], "a") as f:
30+
for path in added_paths:
31+
print(f"Adding PATH: {path}")
32+
f.write(path + os.linesep)
33+
else:
34+
# Use GITHUB_ENV
35+
with open(os.environ["GITHUB_ENV"], "a") as f:
36+
print(f"Setting {key}={value}\n")
37+
f.write(f"{key}={value}\n")

.github/workflows/ios.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: iOS_CI_on_Mac
2+
3+
on:
4+
push:
5+
branches: [ main, 'rel-*']
6+
pull_request:
7+
branches: [ main ]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
iOS_CI_on_Mac:
15+
runs-on: macos-13
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v3
19+
with:
20+
submodules: false
21+
- name: Use Xcode ${{ env.XCODE_VERSION }}
22+
shell: bash
23+
run: |
24+
set -e -x
25+
XCODE_DEVELOPER_DIR="/Applications/Xcode_${{ env.XCODE_VERSION }}.app/Contents/Developer"
26+
sudo xcode-select --switch "${XCODE_DEVELOPER_DIR}"
27+
28+
- name: Export GitHub Actions cache environment variables
29+
uses: actions/github-script@v7
30+
with:
31+
script: |
32+
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
33+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
34+
35+
- name: (CPU, CoreML, XNNPACK EPs) Build onnxruntime for iOS x86_64 and run tests using simulator
36+
shell: bash
37+
run: |
38+
python3 ${{ github.workspace }}/tools/ci_build/build.py \
39+
--skip_submodule_sync \
40+
--build_dir ${{ github.workspace }}/iOS \
41+
--build_shared_lib \
42+
--use_coreml \
43+
--use_xnnpack \
44+
--ios \
45+
--apple_sysroot iphonesimulator \
46+
--osx_arch x86_64 \
47+
--apple_deploy_target=15.1 \
48+
--use_xcode \
49+
--config RelWithDebInfo \
50+
--build_apple_framework \
51+
--parallel \
52+
--use_binskim_compliant_compile_flags
53+
env:
54+
ORT_GET_SIMULATOR_DEVICE_INFO_REQUESTED_RUNTIME_VERSION: ${{ env.IOS_SIMULATOR_RUNTIME_VERSION }}
55+
56+
timeout-minutes: 150
57+
env:
58+
XCODE_VERSION: 14.3.1
59+
IOS_SIMULATOR_RUNTIME_VERSION: 16.4

.github/workflows/mac.yml

+95-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Mac_CI
1+
name: "MacOS CI Pipeline"
22

33
on:
44
push:
@@ -19,6 +19,100 @@ env:
1919
python_version: 3.11
2020

2121
jobs:
22+
MacOS_C_API_Packaging_CPU_x86_64:
23+
runs-on: macos-13
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v3
27+
with:
28+
submodules: false
29+
30+
- name: Use Python
31+
uses: actions/setup-python@v5
32+
with:
33+
python-version: ${{ env.python_version }}
34+
35+
- name: Use Node.js 20.x
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version: '20.x'
39+
40+
- name: Install Java 17
41+
uses: actions/setup-java@v4
42+
with:
43+
distribution: 'temurin'
44+
java-version: '17'
45+
architecture: x64
46+
47+
- name: Set version number variables for Unix
48+
shell: bash
49+
run: |
50+
# Do not output ##vso[] commands with `set -x` or they may be parsed again and include a trailing quote.
51+
set +x
52+
53+
_OnnxRuntimeVersion=$(head -1 ${{ github.workspace }}/VERSION_NUMBER)
54+
echo "OnnxRuntimeVersion=$_OnnxRuntimeVersion"
55+
56+
_OnnxRuntimeGitCommitHash=$(git rev-parse HEAD)
57+
echo "OnnxRuntimeGitCommitHash=$_OnnxRuntimeGitCommitHash"
58+
59+
_OnnxRuntimeGitCommitHash=$(git rev-parse --short=8 HEAD)
60+
echo "OnnxRuntimeGitCommitHashShort=$_OnnxRuntimeGitCommitHash"
61+
working-directory: ${{ github.workspace }}
62+
63+
- name: Use Xcode 14.3.1
64+
shell: bash
65+
run: |
66+
set -e -x
67+
XCODE_DEVELOPER_DIR="/Applications/Xcode_14.3.1.app/Contents/Developer"
68+
sudo xcode-select --switch "${XCODE_DEVELOPER_DIR}"
69+
70+
- name: Setup environment variables
71+
shell: bash
72+
run: |
73+
set -e -x
74+
export PATH=${{ github.workspace }}/installed/bin:$PATH
75+
export ONNX_ML=1
76+
export CMAKE_ARGS="-DONNX_GEN_PB_TYPE_STUBS=ON -DONNX_WERROR=OFF"
77+
python3 -m pip install -r '${{ github.workspace }}/tools/ci_build/github/linux/docker/scripts/requirements.txt'
78+
79+
- name: Export GitHub Actions cache environment variables
80+
uses: actions/github-script@v7
81+
with:
82+
script: |
83+
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
84+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
85+
86+
- name: Configure Build (build.py --update)
87+
shell: bash
88+
run: |
89+
set -e -x
90+
rm -rf ${{ github.workspace }}/Release
91+
python3 ${{ github.workspace }}/tools/ci_build/build.py --update --build_objc --build_wheel --use_xnnpack --build_nodejs --build_java --use_coreml --use_webgpu --build_dir ${{ github.workspace }} --skip_submodule_sync --parallel --use_vcpkg --use_vcpkg_ms_internal_asset_cache --use_binskim_compliant_compile_flags --build_shared_lib --config Release --use_vcpkg --use_vcpkg_ms_internal_asset_cache
92+
93+
- name: Build (build.py --build)
94+
shell: bash
95+
run: |
96+
set -e -x
97+
python3 ${{ github.workspace }}/tools/ci_build/build.py --build --build_objc --build_wheel --use_xnnpack --build_nodejs --build_java --use_coreml --use_webgpu --build_dir ${{ github.workspace }} --skip_submodule_sync --parallel --use_vcpkg --use_vcpkg_ms_internal_asset_cache --use_binskim_compliant_compile_flags --build_shared_lib --config Release --use_vcpkg --use_vcpkg_ms_internal_asset_cache
98+
99+
- name: Install
100+
shell: bash
101+
run: |
102+
set -e -x
103+
cd ${{ github.workspace }}/Release
104+
make install DESTDIR=${{ github.workspace }}/installed
105+
106+
- name: Running Tests (build.py --test)
107+
shell: bash
108+
run: |
109+
set -e -x
110+
python3 ${{ github.workspace }}/tools/ci_build/build.py --test --build_objc --build_wheel --use_xnnpack --build_nodejs --build_java --use_coreml --use_webgpu --build_dir ${{ github.workspace }} --skip_submodule_sync --parallel --use_binskim_compliant_compile_flags --build_shared_lib --config Release --use_vcpkg --use_vcpkg_ms_internal_asset_cache
111+
timeout-minutes: 300
112+
env:
113+
MACOSX_DEPLOYMENT_TARGET: '13.3'
114+
ALLOW_RELEASED_ONNX_OPSET_ONLY: '0'
115+
22116
ARM64-Xcode16:
23117
runs-on: macos-15
24118

.github/workflows/macos_coreml.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: "CoreML CI Pipeline"
2+
3+
on:
4+
push:
5+
branches: [ main, 'rel-*']
6+
pull_request:
7+
branches: [ main ]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build_with_coreml:
15+
runs-on: macos-13
16+
strategy:
17+
matrix:
18+
use_coreml: [true, false]
19+
20+
env:
21+
MACOSX_DEPLOYMENT_TARGET: '13.3'
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v3
26+
27+
- name: Install coreutils and ninja
28+
run: brew install coreutils ninja
29+
30+
- name: Use Xcode 14.3.1
31+
run: |
32+
XCODE_DEVELOPER_DIR="/Applications/Xcode_14.3.1.app/Contents/Developer"
33+
sudo xcode-select --switch "${XCODE_DEVELOPER_DIR}"
34+
35+
- name: Export GitHub Actions cache environment variables
36+
uses: actions/github-script@v7
37+
with:
38+
script: |
39+
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
40+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
41+
42+
- name: CoreML EP, Build and Test on macOS
43+
run: |
44+
python3 tools/ci_build/build.py \
45+
--build_dir build \
46+
--skip_submodule_sync \
47+
--cmake_generator=Ninja \
48+
--parallel --use_vcpkg --use_vcpkg_ms_internal_asset_cache --use_binskim_compliant_compile_flags \
49+
--build_shared_lib \
50+
--config Debug \
51+
${{ matrix.use_coreml && '--use_coreml' || '' }}

0 commit comments

Comments
 (0)