66 push :
77 branches :
88 - master
9+ - loadgen-release
10+ - dev
911 paths :
10- - loadgen/setup.py
12+ - loadgen/**
1113
1214jobs :
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+
1370 build_wheels :
1471 name : Build wheels on ${{ matrix.os }}
72+ needs : update_version
1573 runs-on : ${{ matrix.os }}
1674 strategy :
1775 fail-fast : false
1876 matrix :
19- os : [ubuntu-latest, windows-latest, macOS -latest]
77+ os : [ubuntu-latest, windows-latest, macos -latest]
2078
2179 steps :
2280 - uses : actions/checkout@v3
@@ -27,12 +85,48 @@ jobs:
2785 run : python -m pip install cibuildwheel twine
2886
2987 - name : Build wheels
30- run : python -m cibuildwheel loadgen/ --output-dir wheels
88+ run : git pull && python -m cibuildwheel loadgen/ --output-dir wheels
3189
32- - uses : actions/upload-artifact@v3
90+ # Save wheels as artifacts
91+ - name : Upload built wheels
92+ uses : actions/upload-artifact@v4
3393 with :
34- path : ./wheels/*.whl
94+ name : wheels-${{ matrix.os }}
95+ path : wheels
3596
36- - name : Publish package to PyPI
37- run : python -m twine upload wheels/* -u __token__ -p ${{ secrets.PYPI_API_TOKEN }}
97+ publish_wheels :
98+ needs : build_wheels # Wait for the build_wheels job to complete
99+ runs-on : ubuntu-latest # Only run this job on Linux
100+ environment : release
101+ permissions :
102+ # IMPORTANT: this permission is mandatory for trusted publishing
103+ id-token : write
104+ steps :
105+ - uses : actions/checkout@v3
38106
107+ # Download the built wheels from ubuntu
108+ - name : Download Ubuntu wheels
109+ uses : actions/download-artifact@v4
110+ with :
111+ name : wheels-ubuntu-latest
112+ path : wheels
113+ # Download the built wheels from macOS
114+ - name : Download macOS wheels
115+ uses : actions/download-artifact@v4
116+ with :
117+ name : wheels-macos-latest
118+ path : wheels
119+ # Download the built wheels from Windows
120+ - name : Download Windows wheels
121+ uses : actions/download-artifact@v4
122+ with :
123+ name : wheels-windows-latest
124+ path : wheels
125+ - name : Publish
126+ uses : pypa/gh-action-pypi-publish@release/v1
127+ with :
128+ verify-metadata : true
129+ skip-existing : true
130+ packages-dir : wheels
131+ repository-url : https://upload.pypi.org/legacy/
132+ verbose : true
0 commit comments