-
Notifications
You must be signed in to change notification settings - Fork 24
112 lines (97 loc) · 3.4 KB
/
build_wheel.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Build wheel and release into PYPI
on:
release:
types: [published]
push:
branches:
- main
- mlperf-inference
paths:
- VERSION
- setup.py
jobs:
build_wheels:
if: github.repository_owner == 'mlcommons'
name: Build wheel
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
contents: write
strategy:
fail-fast: false
steps:
# Step 1: Checkout the code
- uses: actions/checkout@v4
with:
fetch-depth: 2
ssh-key: ${{ secrets.DEPLOY_KEY }}
# Step 2: Set up Python
- uses: actions/setup-python@v3
# Step 3: Update the git hash in the repository
- name: Commit updated git hash
run: |
python3 get_git_version.py > git_commit_hash.txt
git config --global user.name mlcommons-bot
git config --global user.email "[email protected]"
git add git_commit_hash.txt
git commit -m "Updated git_commit_hash.txt"
git push
# Step 4: Check if VERSION file has changed in this push
- name: Check if VERSION file has changed
id: version_changed
run: |
if git diff --name-only HEAD~1 | grep -q "VERSION"; then
echo "VERSION file has been modified"
echo "::set-output name=version_changed::true"
new_version=$(cat VERSION)
else
echo "VERSION file has NOT been modified"
echo "::set-output name=version_changed::false"
fi
echo "::set-output name=new_version::$new_version"
# Step 5: Increment version if VERSION was not changed
- name: Increment version if necessary
id: do_version_increment
if: steps.version_changed.outputs.version_changed == 'false'
run: |
# Check if VERSION file exists, else initialize it
if [ ! -f VERSION ]; then
echo "0.0.0" > VERSION
fi
version=$(cat VERSION)
IFS='.' read -r major minor patch <<< "$version"
patch=$((patch + 1))
new_version="$major.$minor.$patch"
echo $new_version > VERSION
echo "New version: $new_version"
echo "::set-output name=new_version::$new_version"
# Step 6: Commit the updated version to the repository
- name: Commit updated version
if: steps.version_changed.outputs.version_changed == 'false'
run: |
git add VERSION
git commit -m "Increment version to ${{ steps.do_version_increment.outputs.new_version }}"
git push
# Step 7: Install required dependencies
- name: Install requirements
run: python3 -m pip install setuptools wheel build
# Step 8: Build the Python wheel
- name: Build wheels
working-directory: ./
run: python3 -m build && rm dist/*.whl
# Step 9: Install the built wheel (as a test)
- name: Install wheel
working-directory: ./
run: |
wheel_file=$(ls dist/*.whl | tail -n 1)
python3 -m pip install "$wheel_file"
# Step 10: Publish to PyPI
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verify-metadata: true
skip-existing: true
packages-dir: dist
repository-url: https://upload.pypi.org/legacy/
verbose: true