Merge pull request #17 from deepmodeling/pocket #19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Python Package | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - actions | |
| jobs: | |
| publish_package: | |
| name: Build and Publish | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Install build tools | |
| run: | | |
| pip install setuptools wheel twine | |
| - name: Extract version info | |
| id: version | |
| run: | | |
| VERSION=$(python setup.py --version) | |
| PACKAGE_NAME=$(python setup.py --name) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "package_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT | |
| - name: Build package | |
| env: | |
| FLASH_ATTENTION_SKIP_CUDA_BUILD: "TRUE" | |
| run: | | |
| python setup.py sdist bdist_wheel --dist-dir=dist | |
| - name: Check if version exists on PyPI | |
| id: check-pypi | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| PACKAGE="${{ steps.version.outputs.package_name }}" | |
| EXISTS=$(curl --silent -f https://pypi.org/pypi/${PACKAGE}/${VERSION}/json > /dev/null && echo "yes" || echo "no") | |
| echo "exists=$EXISTS" >> "$GITHUB_OUTPUT" | |
| - name: Upload to PyPI | |
| if: steps.check-pypi.outputs.exists == 'no' | |
| env: | |
| TWINE_USERNAME: "__token__" | |
| TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} | |
| run: | | |
| twine upload dist/* | |
| - name: Check if GitHub Release exists | |
| id: check-release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| TAG="v${{ steps.version.outputs.version }}" | |
| EXISTS=$(gh release view "$TAG" > /dev/null 2>&1 && echo "yes" || echo "no") | |
| echo "exists=$EXISTS" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| if: steps.check-release.outputs.exists == 'no' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh release create v${{ steps.version.outputs.version }} dist/* \ | |
| --title "Release v${{ steps.version.outputs.version }}" \ | |
| --notes "Automated release from GitHub Actions" | |
| - name: Debug Info (optional) | |
| run: | | |
| echo "Package: ${{ steps.version.outputs.package_name }}" | |
| echo "Version: ${{ steps.version.outputs.version }}" | |
| echo "PyPI Exists: ${{ steps.check-pypi.outputs.exists }}" | |
| echo "GitHub Release Exists: ${{ steps.check-release.outputs.exists }}" |