Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge from GO #41

Merged
merged 13 commits into from
Jan 27, 2025
96 changes: 96 additions & 0 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Build wheel and release into PYPI

on:
release:
types: [published]
push:
branches:
- dev
paths:
- VERSION

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 }}
ref: ${{ github.ref_name }}

# Step 2: Set up Python
- uses: actions/setup-python@v3

# Step 3: Check if VERSION file has changed in this push
- name: Check if VERSION file has changed
id: version_changed
run: |
git config --global user.name mlcommons-bot
git config --global user.email "[email protected]"
if git diff --name-only $(git merge-base HEAD 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 4: 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 5: 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 pull --rebase
git push

# Step 6: Install required dependencies
- name: Install requirements
run: python3 -m pip install setuptools wheel build

# Step 7: Build the Python wheel
- name: Build wheels
working-directory: ./
run: python3 -m build && rm dist/*.whl

# Step 8: 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
Loading
Loading