From 1a488ebfe4774d51ef9331f1a8f92bc8f25e1365 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Wed, 9 Mar 2022 16:34:20 +0800 Subject: [PATCH] Upload after build and tests succeed --- .github/workflows/release.yml | 111 +++++++++++++++------------------- misc/upload_release.py | 55 ++++++++++------- 2 files changed, 82 insertions(+), 84 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dd10a0e4e4964..3c89389f87903 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -55,7 +55,7 @@ jobs: echo '::set-output name=matrix_osx::{"include":[{"name":"taichi-nightly","python":"3.8"},{"name":"taichi-nightly","python":"3.10"}]}"' fi - build_and_upload_linux: + build_and_test_linux: name: Build and Upload (linux only) needs: matrix_prep strategy: @@ -81,11 +81,11 @@ jobs: docker create --user dev --name taichi_build --gpus all -v /tmp/.X11-unix:/tmp/.X11-unix \ -e DISPLAY -e PY -e GPU_BUILD -e TAICHI_CMAKE_ARGS -e PROJECT_NAME \ registry.taichigraphics.com/taichidev-ubuntu18.04:v0.2.1 \ - /home/dev/taichi/.github/workflows/scripts/unix_build.sh + /home/dev/${{ github.event.repository.name }}/.github/workflows/scripts/unix_build.sh tar -cf - ../${{ github.event.repository.name }} --mode u=+rwx,g=+rwx,o=+rwx --owner 1000 --group 1000 | docker cp - taichi_build:/home/dev/ docker start -a taichi_build - docker cp taichi_build:/home/dev/taichi/dist shared/dist - docker cp taichi_build:/home/dev/taichi/build shared/build + docker cp taichi_build:/home/dev/${{ github.event.repository.name }}/dist shared/dist + docker cp taichi_build:/home/dev/${{ github.event.repository.name }}/build shared/build env: PY: ${{ matrix.conda_python }} GPU_BUILD: ON @@ -94,9 +94,9 @@ jobs: DISPLAY: ":1" - name: Archive Wheel Artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: - name: ${{ matrix.name }}-py${{ matrix.python }}-linux.whl + name: dist path: shared/dist/*.whl retention-days: 20 @@ -116,20 +116,12 @@ jobs: GPU_TEST: ON DISPLAY: ":1" - - name: Upload PyPI - env: - PROJECT_NAME: ${{ matrix.name }} - run: | - cd shared - pip install twine requests==2.26 - python3 ../misc/upload_release.py - - name: clean docker container if: always() run: | docker rm taichi_build taichi_test -f - build_and_upload_mac: + build_and_test_mac: name: Build and Upload (macOS only) needs: matrix_prep strategy: @@ -170,9 +162,9 @@ jobs: CXX: clang++ - name: Archive Wheel Artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: - name: ${{ matrix.name }}-py${{ matrix.python }}-macos.whl + name: dist path: dist/*.whl retention-days: 20 @@ -181,13 +173,7 @@ jobs: env: TI_WANTED_ARCHS: "cpu" - - name: Upload PyPI - env: - # https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets#using-encrypted-secrets-in-a-workflow - PROJECT_NAME: ${{ matrix.name }} - run: python misc/upload_release.py - - build_and_upload_m1: + build_and_test_m1: name: Build and Upload (Apple M1) needs: matrix_prep strategy: @@ -226,9 +212,9 @@ jobs: CXX: clang++ - name: Archive Wheel Artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: - name: ${{ matrix.name }}-py${{ matrix.python }}-macos-m1.whl + name: dist path: dist/*.whl retention-days: 20 @@ -241,15 +227,7 @@ jobs: PYTHON: ${{ matrix.python }} GPU_TEST: ON - - name: Upload PyPI - env: - PROJECT_NAME: ${{ matrix.name }} - PYTHON: ${{ matrix.python }} - run: | - export PATH=/Users/github/miniforge3/envs/$PYTHON/bin:$PATH - python misc/upload_release.py - - build_and_upload_macos_1014: + build_and_test_macos_1014: name: Build and Upload (macos 1014) needs: matrix_prep strategy: @@ -285,9 +263,9 @@ jobs: CXX: clang++ - name: Archive Wheel Artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: - name: ${{ matrix.name }}-py${{ matrix.python }}-macos-1014.whl + name: dist path: dist/*.whl retention-days: 20 @@ -299,15 +277,7 @@ jobs: TI_WANTED_ARCHS: "cpu" PYTHON: ${{ matrix.python }} - - name: Upload PyPI - env: - PROJECT_NAME: ${{ matrix.name }} - PYTHON: ${{ matrix.python }} - run: | - export PATH=/Users/buildbot6/miniconda3/envs/$PYTHON/bin:$PATH - python misc/upload_release.py - - build_and_upload_windows: + build_and_test_windows: name: Build and Upload (Windows only) needs: matrix_prep strategy: @@ -347,7 +317,7 @@ jobs: - name: Archive Wheel Artifacts uses: actions/upload-artifact@v2 with: - name: ${{ matrix.name }}-py${{ matrix.python }}-windows.whl + name: dist path: dist/*.whl retention-days: 20 @@ -363,24 +333,43 @@ jobs: env: TI_SKIP_VERSION_CHECK: ON - - name: Upload PyPI - shell: powershell - env: - PROJECT_NAME: ${{ matrix.name }} + upload_to_pypi: + name: Upload release to PyPI + needs: + [ + build_and_test_linux, + build_and_test_mac, + build_and_test_m1, + build_and_test_macos_1014, + build_and_test_windows, + ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3.9 + + - name: Get dist files + uses: actions/download-artifact@v3 + with: + name: dist + path: dist + + - name: Upload to PyPI run: | - python -m pip install twine - venv\Scripts\python misc/upload_release.py + ls -l dist/ + if [ -z "$RELEASE_VERSION" ]; then + export PROJECT_NAME="taichi-nightly" + else + export PROJECT_NAME="taichi" + fi + python -m pip install requests twine + python misc/upload_release.py create_release: name: Create tag and publish release - needs: - [ - build_and_upload_linux, - build_and_upload_mac, - build_and_upload_m1, - build_and_upload_macos_1014, - build_and_upload_windows, - ] + needs: upload_to_pypi runs-on: ubuntu-latest if: github.event_name == 'workflow_dispatch' steps: diff --git a/misc/upload_release.py b/misc/upload_release.py index c14828891aed9..d240c7b4bc201 100644 --- a/misc/upload_release.py +++ b/misc/upload_release.py @@ -9,28 +9,33 @@ def upload_taichi_version(): username = os.getenv('METADATA_USERNAME') password = os.getenv('METADATA_PASSWORD') url = os.getenv('METADATA_URL') - filename = os.listdir('./dist')[0] - filename = filename[:len(filename) - 4] - parts = filename.split('-') - payload = {'version': parts[1], 'platform': parts[4], 'python': parts[2]} - try: - response = requests.post(f'https://{url}/add_version/detail', - json=payload, - auth=(username, password), - timeout=5) - response.raise_for_status() - except requests.exceptions.ConnectionError as err: - sys.exit('Updating latest version failed: No internet, ' + str(err)) - except requests.exceptions.HTTPError as err: - sys.exit('Updating latest version failed: Server error, ' + str(err)) - except requests.exceptions.Timeout as err: - sys.exit( - 'Updating latest version failed: Time out when connecting server, ' - + str(err)) - except requests.exceptions.RequestException as err: - sys.exit('Updating latest version failed: ' + str(err)) - response = response.json() - print(response['message']) + for filename in os.listdir('./dist'): + filename = filename[:len(filename) - 4] + parts = filename.split('-') + payload = { + 'version': parts[1], + 'platform': parts[4], + 'python': parts[2] + } + try: + response = requests.post(f'https://{url}/add_version/detail', + json=payload, + auth=(username, password), + timeout=5) + response.raise_for_status() + except requests.exceptions.ConnectionError as err: + print('Updating latest version failed: No internet,', err) + except requests.exceptions.HTTPError as err: + print('Updating latest version failed: Server error,', err) + except requests.exceptions.Timeout as err: + print( + 'Updating latest version failed: Time out when connecting server,', + err) + except requests.exceptions.RequestException as err: + print('Updating latest version failed:', err) + else: + response = response.json() + print(response['message']) def upload_artifact(is_taichi): @@ -38,7 +43,7 @@ def upload_artifact(is_taichi): twine_password = os.getenv(pwd_env) if not twine_password: sys.exit(f'Missing password env var {pwd_env}') - command = ["python3", "-m", "twine", "upload"] + command = [sys.executable, '-m', 'twine', 'upload'] if not is_taichi: command.extend(['--repository', 'testpypi']) command.extend( @@ -50,6 +55,10 @@ def upload_artifact(is_taichi): if __name__ == '__main__': + if os.getenv('GITHUB_REPOSITORY', + 'taichi-dev/taichi') != 'taichi-dev/taichi': + print('This script should be run from taichi repo') + sys.exit(0) is_taichi = os.getenv('PROJECT_NAME', 'taichi') == 'taichi' upload_artifact(is_taichi) if is_taichi: