@@ -3,37 +3,141 @@ name: Build loadgen wheels and release them into PYPI
33on :
44 release :
55 types : [published]
6+ push :
7+ branches :
8+ - master
9+ - loadgen-release
10+ - dev
11+ paths :
12+ - loadgen/**
613
714jobs :
15+ update_version :
16+ name : Update version only on ubuntu but used by windows and macos
17+ if : github.repository_owner == 'mlcommons'
18+ runs-on : ubuntu-latest
19+ steps :
20+ - uses : actions/checkout@v4
21+ with :
22+ fetch-depth : 2
23+ ssh-key : ${{ secrets.DEPLOY_KEY }}
24+
25+ # Check if VERSION.txt file has changed in this push
26+ - name : Check if VERSION.txt file has changed
27+ id : version_changed
28+ run : |
29+ echo "version_changed=false" >> $GITHUB_ENV
30+ echo "new_version=" >> $GITHUB_ENV # Initialize with empty value
31+ if git diff --name-only HEAD~1 | grep -q "VERSION.txt"; then
32+ echo "VERSION.txt file has been modified"
33+ echo "version_changed=true" >> $GITHUB_ENV
34+ new_version=$(cat loadgen/VERSION.txt)
35+ echo "new_version=$new_version" >> $GITHUB_ENV
36+ else
37+ echo "VERSION.txt file has NOT been modified"
38+ fi
39+
40+ # Step 4: Increment version if VERSION.txt was not changed
41+ - name : Increment version if necessary
42+ id : do_version_increment
43+ if : env.version_changed == 'false'
44+ run : |
45+ cd loadgen
46+ # Check if VERSION file exists, else initialize it
47+ if [ ! -f VERSION.txt ]; then
48+ echo "0.0.0" > VERSION.txt
49+ fi
50+
51+ version=$(cat VERSION.txt)
52+ IFS='.' read -r major minor patch <<< "$version"
53+ patch=$((patch + 1))
54+ new_version="$major.$minor.$patch"
55+ echo $new_version > VERSION.txt
56+ echo "New version: $new_version"
57+ echo "new_version=$new_version" >> $GITHUB_ENV
58+
59+ # Step 5: Commit the updated version to the repository
60+ - name : Commit updated version
61+ if : env.version_changed == 'false'
62+ run : |
63+ cd loadgen
64+ git config --global user.name "${{ github.actor }}"
65+ git config --global user.email "${{ github.actor }}@users.noreply.github.com"
66+ git add VERSION.txt
67+ git commit -m "Increment version to $new_version"
68+ git push
69+
870 build_wheels :
971 name : Build wheels on ${{ matrix.os }}
72+ needs : update_version
1073 runs-on : ${{ matrix.os }}
1174 strategy :
75+ fail-fast : false
1276 matrix :
13- os : [ubuntu-latest, windows-latest, macOS -latest]
77+ os : [ubuntu-latest, windows-latest, macos -latest, macos-13 ]
1478
1579 steps :
1680 - uses : actions/checkout@v3
1781
1882 - uses : actions/setup-python@v3
1983
2084 - name : Install requirements
21- run : python -m pip install cibuildwheel==2.11.4 twine==4.0.2
85+ run : python -m pip install cibuildwheel twine build
2286
23- - name : Init pybind11 submodule
87+ - name : Build src dist
88+ if : ${{ matrix.os == 'ubuntu-latest' }}
2489 run : |
25- git submodule init third_party/pybind
26- git submodule update third_party/pybind
90+ python -m build --sdist --outdir wheels loadgen
2791
2892 - name : Build wheels
29- run : python -m cibuildwheel loadgen/ --output-dir wheels
30- env :
31- CIBW_ENVIRONMENT : " CFLAGS='-std=c++14'"
32- CIBW_BUILD : ' cp3{6,7,8,9,10}-*'
93+ run : git pull && python -m cibuildwheel loadgen/ --output-dir wheels
3394
34- - uses : actions/upload-artifact@v3
95+ # Save wheels as artifacts
96+ - name : Upload built wheels
97+ uses : actions/upload-artifact@v4
3598 with :
36- path : ./wheels/*.whl
99+ name : wheels-${{ matrix.os }}
100+ path : wheels
37101
38- - name : Publish package to PyPI
39- run : python -m twine upload wheels/* -u __token__ -p ${{ secrets.PYPI_API_TOKEN }}
102+ publish_wheels :
103+ needs : build_wheels # Wait for the build_wheels job to complete
104+ runs-on : ubuntu-latest # Only run this job on Linux
105+ environment : release
106+ permissions :
107+ # IMPORTANT: this permission is mandatory for trusted publishing
108+ id-token : write
109+ steps :
110+ - uses : actions/checkout@v3
111+
112+ # Download the built wheels from ubuntu
113+ - name : Download Ubuntu wheels
114+ uses : actions/download-artifact@v4
115+ with :
116+ name : wheels-ubuntu-latest
117+ path : wheels
118+ # Download the built wheels from macOS-latest
119+ - name : Download macOS-latest wheels
120+ uses : actions/download-artifact@v4
121+ with :
122+ name : wheels-macos-latest
123+ path : wheels
124+ # Download the built wheels from macOS-13 (x86)
125+ - name : Download macOS-13 (x86) wheels
126+ uses : actions/download-artifact@v4
127+ with :
128+ name : wheels-macos-13
129+ path : wheels
130+ # Download the built wheels from Windows
131+ - name : Download Windows wheels
132+ uses : actions/download-artifact@v4
133+ with :
134+ name : wheels-windows-latest
135+ path : wheels
136+ - name : Publish
137+ uses : pypa/gh-action-pypi-publish@release/v1
138+ with :
139+ verify-metadata : true
140+ skip-existing : true
141+ packages-dir : wheels
142+ repository-url : https://upload.pypi.org/legacy/
143+ verbose : true
0 commit comments