From 3bf27107eb3bf01916ec703b9ae697dd87a92ad7 Mon Sep 17 00:00:00 2001 From: Jinjing Zhou Date: Mon, 13 Jun 2022 13:32:33 +0800 Subject: [PATCH] action: Add pypi release pipeline (#277) * try * try * fix * add dependency * add list * fix * fix * fix permission * typo * fix * add way to specify manually * use dispatch * try fix * fix * remove * remove --- .github/workflows/release.yml | 52 ++++++++++++++++++++++++++++++++++- Makefile | 2 +- setup.py | 25 +++++++++++------ 3 files changed, 69 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 67c7f795a..e4fe4d96f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,4 +35,54 @@ jobs: version: latest args: release --rm-dist env: - GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + - name: upload gobin + uses: actions/upload-artifact@v3 + with: + name: gobin_${{ github.event.release.tag_name }} + retention-days: 1 + path: | + dist/envd_linux_amd64_v1/envd + dist/envd-ssh_linux_amd64_v1/envd-ssh + if-no-files-found: error + pypi_publish: + needs: goreleaser + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') # only trigger when tag starts with v + steps: + - uses: actions/checkout@v3 + - name: Get gobin + uses: actions/download-artifact@v3 + with: + name: gobin_${{ github.event.release.tag_name }} + path: dist/ + - name: Move file to + run: | + mkdir -p bin + mv dist/envd_linux_amd64_v1/envd bin/envd + mv dist/envd-ssh_linux_amd64_v1/envd-ssh bin/envd-ssh + chmod +x bin/envd + chmod +x bin/envd-ssh + - uses: actions/setup-python@v2 + with: + python-version: 3.9 + - name: Build wheel + run: | + ls bin/ + python -m pip install --upgrade pip + python -m pip install twine wheel auditwheel setuptools_scm + python setup.py bdist_wheel + auditwheel repair dist/*.whl + ls wheelhouse/ + pushd wheelhouse + for file in *.whl ; do mv $file ${file//"cp39-cp39"/"py2.py3-none"} ; done + popd + - name: Upload to Pypi + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} + run: | + twine upload wheelhouse/* + + + diff --git a/Makefile b/Makefile index 7b2283212..2bee7e13e 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ DEBUG_DIR := ./debug-bin BUILD_DIR := ./build # Current version of the project. -VERSION ?= $(shell git describe --match 'v[0-9]*' --always --tags) +VERSION ?= $(shell git describe --match 'v[0-9]*' --always --tags --abbrev=0) BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') GIT_COMMIT=$(shell git rev-parse HEAD) GIT_TAG=$(shell if [ -z "`git status --porcelain`" ]; then git describe --exact-match --tags HEAD 2>/dev/null; fi) diff --git a/setup.py b/setup.py index 3edf4a208..2fba52d60 100644 --- a/setup.py +++ b/setup.py @@ -17,12 +17,18 @@ from setuptools import setup, Extension, find_packages from setuptools.command.build_ext import build_ext import subprocess - +import logging with open("README.md", "r", encoding="utf-8") as f: readme = f.read() +def build_envd_if_not_found(): + if not os.path.exists("bin/envd"): + logging.info("envd not found. Build from scratch") + errno = subprocess.call(["make", "build"]) + assert errno == 0, "Failed to build envd" + class EnvdExtension(Extension): """Extension for `envd`""" @@ -33,32 +39,35 @@ def build_extension(self, ext: Extension) -> None: return super().build_extension(ext) bin_path = os.path.join(self.build_lib, "envd", "bin") - errno = subprocess.call(["make", "build"]) - assert errno == 0, "Failed to build envd" + build_envd_if_not_found() os.makedirs(bin_path, exist_ok=True) shutil.copy("bin/envd", bin_path) def get_version(): - subprocess.call(["make", "build"]) + # Remove prefix v in versioning + build_envd_if_not_found() version = subprocess.check_output( - ["./bin/envd", "-v"], universal_newlines=True + ["./bin/envd", "version", "--short"], universal_newlines=True ).strip() - return version.rsplit(" ", 1)[-1] + ver = version.rsplit(" ", 1)[-1][1:] + return ver setup( name="envd", version=get_version(), + use_scm_version = True, + setup_requires=['setuptools_scm'], description="A development environment management tool for data scientists.", - long_description=readme, + long_description=readme, + long_description_content_type="text/markdown", url="https://github.com/tensorchord/envd", license="Apache License 2.0", author="TensorChord", author_email="envd-maintainers@tensorchord.ai", packages=find_packages(), include_package_data=True, - python_requires=">=3.6", entry_points={ "console_scripts": [ "envd=envd.cmd:envd",