From 5aec4f835ffc91c91c2c25cc2a7d683d3f1ca8dc Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Sat, 10 Feb 2024 10:12:21 +0100 Subject: [PATCH 1/6] Incremetn version --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 20e40b0..f18b987 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "fancy_gym" -version = "0.1.4" +version = "0.3.0" description = "Fancy Gym: Unifying interface for various RL benchmarks with support for Black Box approaches." readme = "README.md" authors = [ @@ -26,6 +26,7 @@ classifiers = [ ] dependencies = [ + "toml", "mp_pytorch<=0.1.3", "mujoco==2.3.3", "gymnasium[mujoco]>=0.26.0" From 259b13baa1a76bdf7f20369367f054c27bb13ad9 Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Sat, 10 Feb 2024 10:13:17 +0100 Subject: [PATCH 2/6] Version in pyproject.toml is now single source of truth --- docs/source/conf.py | 10 +++++++--- setup.py | 7 ++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 8ce3d31..0f17ef9 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,13 +1,17 @@ # This conf.py is in large parts inspired by the oen used by stable-baselines 3 +import toml import datetime project = 'Fancy Gym' author = 'Fabian Otto, Onur Celik, Dominik Roth, Hongyi Zhou' copyright = f'2020-{datetime.date.today().year}, {author}' -release = '0.2' # The full version, including alpha/beta/rc tags -version = '0.2' # The short X.Y version +pyproject_content = toml.load("../../pyproject.toml") +proj_version = pyproject_content["project"]["version"] + +release = proj_version # The full version, including alpha/beta/rc tags +version = proj_version # The short X.Y version extensions = [ 'myst_parser', @@ -50,4 +54,4 @@ html_context = { } def setup(app): - app.add_css_file("style.css") \ No newline at end of file + app.add_css_file("style.css") diff --git a/setup.py b/setup.py index 2bd077d..2a533fa 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ # We still provide a setup.py for backwards compatability. # But the pyproject.toml should be prefered. +import toml import itertools from pathlib import Path from typing import List @@ -8,6 +9,9 @@ from setuptools import setup, find_packages print('[!] You are currently installing/building fancy_gym via setup.py. This is only provided for backwards-compatability. Please use the pyproject.toml instead.') +pyproject_content = toml.load("pyproject.toml") +project_version = pyproject_content["project"]["version"] + # Environment-specific dependencies for dmc and metaworld extras = { 'dmc': ['shimmy[dm-control]', 'Shimmy==1.0.0'], @@ -38,7 +42,7 @@ def find_package_data(extensions_to_include: List[str]) -> List[str]: setup( author='Fabian Otto, Onur Celik, Dominik Roth, Hongyi Zhou', name='fancy_gym', - version='0.1.0', + version=project_version, classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Science/Research', @@ -55,6 +59,7 @@ setup( ], extras_require=extras, install_requires=[ + 'toml', 'mp_pytorch<=0.1.3', 'mujoco==2.3.3', 'gymnasium[mujoco]>=0.26.0' From 3c7fdc8d5b79d10329cc75f72a8fd2ce79d1ec9e Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Sat, 10 Feb 2024 10:13:37 +0100 Subject: [PATCH 3/6] Update workflows to also validate version number consistency --- .github/workflows/ensure-release-tagged.yaml | 26 ----------- .../workflows/ensure-version-consistency.yaml | 46 +++++++++++++++++++ .github/workflows/publish-to-pypi.yml | 22 +++++---- 3 files changed, 58 insertions(+), 36 deletions(-) delete mode 100644 .github/workflows/ensure-release-tagged.yaml create mode 100644 .github/workflows/ensure-version-consistency.yaml diff --git a/.github/workflows/ensure-release-tagged.yaml b/.github/workflows/ensure-release-tagged.yaml deleted file mode 100644 index e58e31e..0000000 --- a/.github/workflows/ensure-release-tagged.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: Ensure Tagged Commits on Release - -on: - pull_request: - branches: - - release - -jobs: - check_tag: - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Check if base commit of PR is tagged - run: | - BASE_COMMIT=$(jq -r .pull_request.base.sha < "$GITHUB_EVENT_PATH") - TAG=$(git tag --contains $BASE_COMMIT) - if [ -z "$TAG" ]; then - echo "Base commit of PR is not tagged. PRs onto release must be tagged with the version number." - exit 1 - fi - echo "Base commit of PR is tagged. Check passed." - diff --git a/.github/workflows/ensure-version-consistency.yaml b/.github/workflows/ensure-version-consistency.yaml new file mode 100644 index 0000000..1b02e6b --- /dev/null +++ b/.github/workflows/ensure-version-consistency.yaml @@ -0,0 +1,46 @@ +name: Ensure Version Consistency on PR to Release + +on: + pull_request: + branches: + - release + +jobs: + check_version_and_tag: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Necessary to fetch all tags for comparison + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Extract version from pyproject.toml + run: | + echo "Extracting version from pyproject.toml" + VERSION=$(python -c 'import toml; print(toml.load("pyproject.toml")["project"]["version"])') + echo "Version in pyproject.toml is $VERSION" + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Get tag for the PR's head commit + run: | + PR_HEAD_SHA=$(jq -r .pull_request.head.sha < "$GITHUB_EVENT_PATH") + TAG=$(git tag --contains $PR_HEAD_SHA) + echo "Tag on PR's head commit is $TAG" + echo "TAG=$TAG" >> $GITHUB_ENV + + - name: Compare version and tag + run: | + if [ -z "$TAG" ]; then + echo "Head commit of PR is not tagged. Ensure the head commit of PRs onto release is tagged with the version number." + exit 1 + elif [ "$VERSION" != "$TAG" ]; then + echo "Version in pyproject.toml ($VERSION) does not match the git tag ($TAG)." + exit 1 + else + echo "Version and git tag match. Check passed." + diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 1b5fa08..dc25bbc 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -15,19 +15,24 @@ jobs: with: fetch-depth: 0 # This fetches all history for all branches and tags - - name: Check if commit is tagged + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + + - name: Validate version against tag run: | + VERSION=$(python -c 'import toml; print(toml.load("pyproject.toml")["project"]["version"])') TAG=$(git tag --contains HEAD) if [ -z "$TAG" ]; then echo "Commit is not tagged. Failing the workflow." exit 1 fi - echo "Commit is tagged. Proceeding with the workflow." - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.x" + if [ "$VERSION" != "$TAG" ]; then + echo "Version in pyproject.toml ($VERSION) does not match the git tag ($TAG). Failing the workflow." + exit 1 + fi + echo "Version and commit tag match. Proceeding with the workflow." - name: Install pypa/build/setuptools/twine run: >- @@ -36,9 +41,6 @@ jobs: build setuptools twine --user - - name: Prevent fallback onto setup.py - run: rm setup.py - - name: Build a binary wheel and a source tarball run: python3 -m build From 31b9182b53093186e6b50a849ff176290a5e6b92 Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Sat, 10 Feb 2024 10:48:01 +0100 Subject: [PATCH 4/6] Fix: Workflow python envs missing toml dependency --- .github/workflows/ensure-version-consistency.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ensure-version-consistency.yaml b/.github/workflows/ensure-version-consistency.yaml index 1b02e6b..50e4325 100644 --- a/.github/workflows/ensure-version-consistency.yaml +++ b/.github/workflows/ensure-version-consistency.yaml @@ -19,6 +19,10 @@ jobs: with: python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install toml + - name: Extract version from pyproject.toml run: | echo "Extracting version from pyproject.toml" From 4d0ef519d083f27986e06ba1dedaab62286b9b3c Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Sat, 10 Feb 2024 11:07:02 +0100 Subject: [PATCH 5/6] Ensure following steps are skipped if any one fails --- .github/workflows/ensure-version-consistency.yaml | 2 ++ .github/workflows/publish-to-pypi.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/ensure-version-consistency.yaml b/.github/workflows/ensure-version-consistency.yaml index 50e4325..fab5cd7 100644 --- a/.github/workflows/ensure-version-consistency.yaml +++ b/.github/workflows/ensure-version-consistency.yaml @@ -8,6 +8,8 @@ on: jobs: check_version_and_tag: runs-on: ubuntu-latest + strategy: + fail-fast: true # Terminate the job immediately if any step fails steps: - name: Check out code uses: actions/checkout@v4 diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index dc25bbc..902cec5 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -8,6 +8,8 @@ on: jobs: publish: name: Publish to PyPI + strategy: + fail-fast: true # Terminate the job immediately if any step fails runs-on: ubuntu-latest steps: - name: Check out code From 41c5ca1120624eb9d7bacdb25c6819428dbac46d Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Sat, 10 Feb 2024 11:10:14 +0100 Subject: [PATCH 6/6] Fix: Forgot 'fi' to end if clause in bash snippet --- .github/workflows/ensure-version-consistency.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ensure-version-consistency.yaml b/.github/workflows/ensure-version-consistency.yaml index fab5cd7..c3c85df 100644 --- a/.github/workflows/ensure-version-consistency.yaml +++ b/.github/workflows/ensure-version-consistency.yaml @@ -49,4 +49,4 @@ jobs: exit 1 else echo "Version and git tag match. Check passed." - + fi