Repository: epignatelli/helx (language: python)

Issue:
Fix CD workflow
Which is breaking due to missing authorization for publishing releases


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml
index 9a419ea..4dcbb6d 100644
--- a/.github/workflows/CD.yml
+++ b/.github/workflows/CD.yml
@@ -9,30 +9,75 @@ jobs:
   release:
     runs-on: ubuntu-latest
     steps:
+      - uses: actions/checkout@v3
+        with:
+          fetch-depth: 0
       - name: Bump version and push tag
         id: tag_version
         uses: mathieudutour/github-tag-action@v6.1
         with:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
           default_bump: "minor"
+          dry_run: true
+      - name: Fix tag name
+        run: |
+          CURRENT_TAG_NAME="${{ steps.tag_version.outputs.new_tag }}"
+          FIXED_TAG_NAME="$(echo $CURRENT_TAG_NAME | grep -Eo '([0-9]+.[0-9]+\.[0-9]+)')"
+          CHANGELOG="${{ steps.tag_version.outputs.changelog }}"
+
+          echo 'CHANGELOG<<EOF' >> $GITHUB_ENV
+          echo "$CHANGELOG" >> $GITHUB_ENV
+          echo 'EOF' >> $GITHUB_ENV
+
+          echo 'FIXED_TAG_NAME<<EOF' >> $GITHUB_ENV
+          echo "$FIXED_TAG_NAME" >> $GITHUB_ENV
+          echo 'EOF' >> $GITHUB_ENV
       - name: Create GitHub release
         uses: ncipollo/release-action@v1
         with:
-          tag: ${{ steps.tag_version.outputs.new_tag }}
-          name: Release ${{ steps.tag_version.outputs.new_tag }}
-          body: ${{ steps.tag_version.outputs.changelog }}
+          tag: ${{ env.FIXED_TAG_NAME }}
+          name: ${{ env.FIXED_TAG_NAME }}
+          body: ${{ env.CHANGELOG }}
 
+# see:
+# https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/
+# https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
+# for
   publish:
+    needs: release
     runs-on: ubuntu-latest
+    continue-on-error: true
     strategy:
-      max-parallel: 5
+      max-parallel: 3
       matrix:
-        python_version: ["3.8", "3.9", "3.10", "3.11"]
+        python_version: ["3.9"]
     steps:
       - uses: actions/checkout@v3
-
-      - name: Build package
-        run: python3 -m pip install --upgrade build && python3 -m build
-
-      - uses: pypa/gh-action-pypi-publish@release/v1
         with:
-          password: ${{ secrets.PYPI_API_KEY }}
+          fetch-depth: 0
+      - uses: actions/setup-python@v4
+        with:
+          python-version: ${{ matrix.python_version }}
+      - name: Install pypa/build
+        run: |
+          python -m
+          pip install
+          build
+      - name: Build wheel and sdist
+        run: >-
+          python -m
+          build
+          --sdist
+          --wheel
+          --outdir dist/
+          .
+      - name: Publish distribution 📦 to Test PyPI
+        uses: pypa/gh-action-pypi-publish@release/v1
+        with:
+          password: ${{ secrets.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@release/v1
+        with:
+          password: ${{ secrets.PYPI_API_TOKEN }}
diff --git a/README.md b/README.md
index a23f062..3e9a489 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,10 @@
-[![Test](https://github.com/epignatelli/helx/actions/workflows/test.yml/badge.svg)](https://github.com/epignatelli/helx/actions/workflows/test.yml)
+[![CI](https://github.com/epignatelli/helx/actions/workflows/CI.yml/badge.svg)](https://github.com/epignatelli/helx/actions/workflows/CI.yml)
+[![CD](https://github.com/epignatelli/helx/actions/workflows/CD.yml/badge.svg)](https://github.com/epignatelli/helx/actions/workflows/CD.yml)
+
+![GitHub release (latest by date)](https://img.shields.io/github/v/release/epignatelli/helx?color=%23216477&label=Release)
+![PyPI - Python Version](https://img.shields.io/pypi/pyversions/helx)
+![PyPI - Wheel](https://img.shields.io/pypi/wheel/helx)
+
 [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
 [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
 
@@ -39,15 +45,15 @@ import gym
 
 import helx.environment
 import helx.experiment
-from helx.agents import RandomAgent, Hparams
+import helx.agents
 
 # create the enviornment in you favourite way
 env = bsuite.load_from_id("catch/0")
 # convert it to an helx environment
 env = helx.environment.to_helx(env)
 # create the agent
-hparams = Hparams(env.obs_space(), env.action_space())
-agent = RandomAgent(hparams)
+hparams = helx.agents.Hparams(env.obs_space(), env.action_space())
+agent = helx.agents.Random(hparams)
 
 # run the experiment
 helx.experiment.run(env, agent, episodes=100)
@@ -63,7 +69,7 @@ import gym
 
 import helx.environment
 import helx.experiment
-from helx.agents import RandomAgent, Hparams
+import helx.agents
 
 # create the enviornment in you favourite way
 -env = bsuite.load_from_id("catch/0")
@@ -71,8 +77,8 @@ from helx.agents import RandomAgent, Hparams
 # convert it to an helx environment
 env = helx.environment.to_helx(env)
 # create the agent
-hparams = Hparams(env.obs_space(), env.action_space())
-agent = RandomAgent(hparams)
+hparams = helx.agents.Hparams(env.obs_space(), env.action_space())
+agent = helx.agents.Random(hparams)
 
 # run the experiment
 helx.experiment.run(env, agent, episodes=100)
diff --git a/pyproject.toml b/pyproject.toml
index 942a5c8..55ec2a0 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -2,7 +2,7 @@
 # However, setuptools support for these is only in Beta
 # For now, `setup.py` is still the first option for pip
 [build-system]
-build_backend = "setuptools.build_meta"
+build-backend = "setuptools.build_meta"
 requires = ["setuptools >= 50", "setuptools-scm[toml]>=6.2", "wheel"]
 
 [project]
@@ -82,6 +82,10 @@ include = ["helx*"]
 exclude = ["test", "examples"]
 
 
+[tool.distutils.bdist_wheel]
+universal = true
+
+
 [tool.setuptools_scm]
 write_to = "helx/version.py"
 


Test patch:
diff --git a/test/test_atari.py b/test/test_atari.py
index bd2e030..eb943a3 100644
--- a/test/test_atari.py
+++ b/test/test_atari.py
@@ -50,7 +50,3 @@ def test_env(env_id):
             logging.debug("Skipping excluded env: {}".format(env_id))
             continue
         test_env(env_id)
-
-
-if __name__ == "__main__":
-    test_atari()
diff --git a/test/test_bsuite.py b/test/test_bsuite.py
index f221b99..710503a 100644
--- a/test/test_bsuite.py
+++ b/test/test_bsuite.py
@@ -38,7 +38,3 @@ def test_env(env_id):
     # get all bsuite envs
     for i, env_id in enumerate(BSUITE_IDS):
         test_env(env_id)
-
-
-if __name__ == "__main__":
-    test_bsuite()
diff --git a/test/test_flags.py b/test/test_flags.py
index 43b0849..37ec857 100644
--- a/test/test_flags.py
+++ b/test/test_flags.py
@@ -37,7 +37,3 @@ def test_flag_type():
         )
         logging.debug(hparams)
         flagsaver.restore_flag_values(saved_flag_values)
-
-
-if __name__ == "__main__":
-    test_flag_type()
diff --git a/test/test_gym3_procgen.py b/test/test_gym3_procgen.py
index 6002edc..9ce2ccb 100644
--- a/test/test_gym3_procgen.py
+++ b/test/test_gym3_procgen.py
@@ -42,7 +42,3 @@ def test_env(env_id):
 
     for i, env_id in enumerate(mujoco_env_ids):
         test_env(env_id)
-
-
-if __name__ == "__main__":
-    test_procgen()
diff --git a/test/test_gym_minigrid.py b/test/test_gym_minigrid.py
index aeb7dcb..4c7405e 100644
--- a/test/test_gym_minigrid.py
+++ b/test/test_gym_minigrid.py
@@ -40,7 +40,3 @@ def test_env(env_id):
 
     for i, env_id in enumerate(minigrid_env_ids):
         test_env(env_id)
-
-
-if __name__ == "__main__":
-    test_gym_minigrid()
diff --git a/test/test_gym_mujoco.py b/test/test_gym_mujoco.py
index 89faa76..96c2abc 100644
--- a/test/test_gym_mujoco.py
+++ b/test/test_gym_mujoco.py
@@ -39,7 +39,3 @@ def test_env(env_id):
 
     for i, env_id in enumerate(mujoco_env_ids):
         test_env(env_id)
-
-
-if __name__ == "__main__":
-    test_mujoco()