Skip to content

[pre-commit.ci] pre-commit autoupdate (#3055) #4330

[pre-commit.ci] pre-commit autoupdate (#3055)

[pre-commit.ci] pre-commit autoupdate (#3055) #4330

Workflow file for this run

name: Build and upload to PyPI
on:
push:
pull_request:
jobs:
determine-arm64-runner:
runs-on: ubuntu-latest
permissions: read-all
outputs:
runner: ${{ steps.set-runner.outputs.runner }}
steps:
- name: Determine which runner to use for ARM64 build
id: set-runner
run: |
if [ "${{ github.repository_owner }}" == "deepmodeling" ]; then
echo "runner=[\"Linux\",\"ARM64\"]" >> $GITHUB_OUTPUT
else
echo "runner=\"ubuntu-latest\"" >> $GITHUB_OUTPUT
fi
build_wheels:
name: Build wheels for cp${{ matrix.python }}-${{ matrix.platform_id }}
needs: determine-arm64-runner
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# linux-64
- os: ubuntu-latest
python: 311
platform_id: manylinux_x86_64
dp_variant: cuda
cuda_version: 12.2
- os: ubuntu-latest
python: 311
platform_id: manylinux_x86_64
dp_variant: cuda
cuda_version: 11.8
dp_pkg_name: deepmd-kit-cu11
# macos-x86-64
- os: macos-latest
python: 311
platform_id: macosx_x86_64
dp_variant: cpu
# macos-arm64
- os: macos-latest
python: 311
platform_id: macosx_arm64
dp_variant: cpu
# win-64
- os: windows-2019
python: 311
platform_id: win_amd64
dp_variant: cpu
# linux-aarch64
- os: ${{ fromJson(needs.determine-arm64-runner.outputs.runner) }}
python: 310
platform_id: manylinux_aarch64
dp_variant: cpu
steps:
- uses: actions/checkout@v4
with:
# https://github.com/pypa/setuptools_scm/issues/480
fetch-depth: 0
- uses: docker/setup-qemu-action@v3
name: Setup QEMU
if: matrix.platform_id == 'manylinux_aarch64' && matrix.os == 'ubuntu-latest'
- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_BUILD_VERBOSITY: 1
CIBW_ARCHS: all
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }}
DP_VARIANT: ${{ matrix.dp_variant }}
CUDA_VERSION: ${{ matrix.cuda_version }}
DP_PKG_NAME: ${{ matrix.dp_pkg_name }}
- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: '3.11'
cache: 'pip'
- run: python -m pip install build
- name: Build sdist
run: python -m build --sdist
- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz
upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
build_docker:
# use the already built wheels to build docker
needs: [build_wheels]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- variant: ""
cuda_version: "12"
- variant: "_cu11"
cuda_version: "11"
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: artifact
path: source/install/docker/dist
- name: Log in to the Container registry
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@31cebacef4805868f9ce9a0cb03ee36c32df2ac4
with:
images: ghcr.io/deepmodeling/deepmd-kit
- name: Build and push Docker image
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
with:
context: source/install/docker
push: ${{ github.repository_owner == 'deepmodeling' && github.event_name == 'push' && github.actor != 'dependabot[bot]' }}
tags: ${{ steps.meta.outputs.tags }}${{ matrix.variant }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VARIANT=${{ matrix.variant }}
CUDA_VERSION=${{ matrix.cuda_version }}
build_pypi_index:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist/packages
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: '3.11'
- run: pip install dumb-pypi
- run: |
ls dist/packages > package_list.txt
dumb-pypi --output-dir dist --packages-url ../../packages --package-list package_list.txt --title "DeePMD-kit Developed Packages"
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v2
with:
path: dist
deploy_pypi_index:
needs: build_pypi_index
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/devel' && github.repository_owner == 'deepmodeling'
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v3
pass:
name: Pass testing build wheels
needs: [build_wheels, build_sdist, build_docker, build_pypi_index]
runs-on: ubuntu-latest
if: always()
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}