From 926c009965f31d41cae3fd7cf8f0e369b015b334 Mon Sep 17 00:00:00 2001 From: luzhan <513964121@qq.com> Date: Tue, 16 Apr 2024 15:18:17 +0100 Subject: [PATCH] CI:add publish to testpypi --- .github/workflows/publish-test.yml | 108 +++++++++++++++++++++++++++++ setup.py | 2 +- 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish-test.yml diff --git a/.github/workflows/publish-test.yml b/.github/workflows/publish-test.yml new file mode 100644 index 0000000..3184af5 --- /dev/null +++ b/.github/workflows/publish-test.yml @@ -0,0 +1,108 @@ +# This workflow will upload a Python Package to Release asset +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions + +name: Publish to Test PyPI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +# Needed to create release and upload assets +permissions: + contents: write + + +jobs: + setup-version: + runs-on: ubuntu-latest + steps: + - name: Generate version number + run: | + VERSION_HASH=$(date +"%Y%m%d%H%M%S") + echo "Generated version hash: $VERSION_HASH" + echo $VERSION_HASH > version.txt + + - name: Upload version number as artifact + uses: actions/upload-artifact@v2 + with: + name: version + path: version.txt + + wheel: + name: Build Wheel + runs-on: ${{ matrix.os }} + permissions: write-all + + strategy: + fail-fast: false + matrix: + os: ['ubuntu-20.04'] + python-version: ['3.8', '3.9', '3.10', '3.11'] + cuda-version: ['11.7'] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + # - name: Set up Linux Env + # if: ${{ runner.os == 'Linux' }} + # run: | + # bash -x .github/workflows/scripts/env.sh + + # https://github.com/orgs/community/discussions/26313 + - name: Download version value artifact + uses: actions/download-artifact@v2 + with: + name: version + path: artifact + + - name: Free disk space + run: | + sudo rm -rf /usr/local/cuda-* /opt/cuda + sudo rm -rf /usr/local/cuda + bash -x .github/workflows/scripts/free-disk-space.sh + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install CUDA ${{ matrix.cuda-version }} + run: | + bash -x .github/workflows/scripts/cuda-install.sh ${{ matrix.cuda-version }} ${{ matrix.os }} + + - name: Build wheel + shell: bash + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install build + VERSION_HASH=$(cat artifact/version.txt) + MOEINF_VERSION=0.0.1dev${VERSION_HASH} BUILD_OPS=1 python -m build --wheel + wheel_name=$(ls dist/*whl | xargs -n 1 basename) + asset_name=${wheel_name//"linux"/"manylinux1"} + echo "wheel_name=${wheel_name}" >> $GITHUB_ENV + echo "asset_name=${asset_name}" >> $GITHUB_ENV + + + # only build source when the python version is 3.8 + - name: Build Source + if: ${{ matrix.python-version == '3.8' }} + run: | + VERSION_HASH=$(cat artifact/version.txt) + MOEINF_VERSION=0.0.1dev${VERSION_HASH} python -m build --sdist + + - name: Rename wheel + run: | + mv dist/${{ env.wheel_name }} dist/${{ env.asset_name }} + + # (Danielkinz): This last step will publish the .whl to pypi. Warning: untested + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1.8 + with: + repository-url: https://test.pypi.org/legacy/ + skip-existing: true \ No newline at end of file diff --git a/setup.py b/setup.py index 35242a5..936da6e 100644 --- a/setup.py +++ b/setup.py @@ -76,7 +76,7 @@ def read_readme() -> str: # install all files in the package, rather than just the egg setup( name='moe_infinity', - version='0.0.1', + version=os.getenv('MOEINF_VERSION', '0.0.1'), packages=find_packages(exclude=['op_builder', 'op_builder.*', 'moe_infinity.ops.core.*']), package_data={ 'moe_infinity.ops.prefetch': ['**/*.so'],