From 34ca8b695da47523e1f141447b3f18b16c82bd84 Mon Sep 17 00:00:00 2001 From: Christopher Hesse Date: Fri, 14 Jan 2022 18:17:30 -0800 Subject: [PATCH] use github_ref --- .github/workflows/main.yml | 9 ++++---- procgen-build/procgen_build/build_package.py | 4 ++-- setup.py | 22 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 434370a4..9e2d083a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -87,13 +87,14 @@ jobs: run: mkdir dist && mv artifacts/wheels/* dist/ - name: Publish distribution 📦 to Test PyPI - uses: pypa/gh-action-pypi-publish@master + uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.TEST_PYPI_API_TOKEN }} repository_url: https://test.pypi.org/legacy/ - name: Publish distribution 📦 to PyPI if: startsWith(github.ref, 'refs/tags') - uses: pypa/gh-action-pypi-publish@master - with: - password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file + run: echo "push to pypi" + # uses: pypa/gh-action-pypi-publish@release/v1 + # with: + # password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file diff --git a/procgen-build/procgen_build/build_package.py b/procgen-build/procgen_build/build_package.py index ed9c3d18..d0e06a63 100644 --- a/procgen-build/procgen_build/build_package.py +++ b/procgen-build/procgen_build/build_package.py @@ -24,11 +24,11 @@ def main(): } ) if platform.system() == "Linux": - if "TRAVIS_TAG" in os.environ: + if "GITHUB_REF" in os.environ: # pass TRAVIS_TAG to the container so that it can build wheels with the correct version number os.environ["CIBW_ENVIRONMENT"] = ( os.environ["CIBW_ENVIRONMENT"] - + " TRAVIS_TAG=" + os.environ["TRAVIS_TAG"] + + " GITHUB_REF=" + os.environ["GITHUB_REF"] ) os.environ["CIBW_ENVIRONMENT"] = ( os.environ["CIBW_ENVIRONMENT"] diff --git a/setup.py b/setup.py index 9fc7d2cd..d61f05fb 100644 --- a/setup.py +++ b/setup.py @@ -3,6 +3,7 @@ import os import sys import glob +import subprocess SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) PACKAGE_ROOT = os.path.join(SCRIPT_DIR, "procgen") @@ -10,6 +11,27 @@ # dynamically determine version number based on git commit version = open(os.path.join(PACKAGE_ROOT, "version.txt"), "r").read().strip() +sha = "unknown" + +try: + sha = ( + subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=SCRIPT_DIR) + .decode("ascii") + .strip() + ) +except Exception: + pass + +if "GITHUB_REF" in os.environ: + ref = os.environ["GITHUB_REF"] + tag = ref.split("/")[-1] + print(f"ref={ref} tag={tag}") + assert tag == version, "mismatch in tag vs version, expected: %s actual: %s" % ( + tag, + version, + ) +elif sha != "unknown": + version += "+" + sha[:7] # build shared library