From 08dd5be039d5af1861b7faf924872cf9b6d8f591 Mon Sep 17 00:00:00 2001 From: Poiuy7312 Date: Tue, 5 Dec 2023 15:07:01 -0500 Subject: [PATCH 1/7] feat: created code to update version when called --- update_version.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 update_version.py diff --git a/update_version.py b/update_version.py new file mode 100644 index 00000000..2354c2ea --- /dev/null +++ b/update_version.py @@ -0,0 +1,42 @@ +from pathlib import Path + +import toml + +# defines the max value for the version except for the first value +UPDATE_STEP = 10 + + +def updated_version(version: str) -> str: + """Updates the version based on the current version and specified step""" + # gets a list of integers by splitting the version by a period + # this is so it can separately change each part of the version + version_list = [int(x) for x in version.split(".")] + # adds 1 to the last value of version + version_list[2] += 1 + # iterates through to make sure if the value is equal + # to ten it sets it to zero and adds 1 to the next part of + # version so it would change [0,2,10] to [0,3,0] + for i in range(2, 0, -1): + if version_list[i] >= UPDATE_STEP: + version_list[i - 1] += 1 + version_list[i] = 0 + # turns the result back into a string split by a period and returns it + # ex -> [0,3,0] turns into "0.3.0" + result = ".".join([str(x) for x in version_list]) + return result + + +if __name__ == "__main__": + # Open toml file and change the version of the program. + file = Path("pyproject.toml") + # turns the toml into a dictionary to be able to find + # the specified value and not change anything else + toml_dict = toml.load(file) + version = toml_dict["tool"]["poetry"]["version"] + # reads the text as a string + content = file.read_text() + # replaces the version with the updated version using the function + # updated_version, Only replaces the first instance of it + content = content.replace(version, updated_version(version), 1) + # write the changes to the toml file + file.write_text(content) From 1b9bf3caf49fc365a73c74feb86881d04e5fe8ba Mon Sep 17 00:00:00 2001 From: Poiuy7312 Date: Tue, 5 Dec 2023 15:08:09 -0500 Subject: [PATCH 2/7] feat: added test case for update_version() --- tests/test_update_version.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/test_update_version.py diff --git a/tests/test_update_version.py b/tests/test_update_version.py new file mode 100644 index 00000000..786659ee --- /dev/null +++ b/tests/test_update_version.py @@ -0,0 +1,8 @@ +import update_version + + +def test_updated_version() -> None: + """Test case for update_version function""" + assert update_version.updated_version("0.0.9") == "0.1.0" + assert update_version.updated_version("0.9.9") == "1.0.0" + assert update_version.updated_version("0.1.0") == "0.1.1" From c0c632f90eb5b26d3013097665a721dc3d95712b Mon Sep 17 00:00:00 2001 From: Miles Date: Tue, 5 Dec 2023 19:33:45 -0800 Subject: [PATCH 3/7] added pypi automation, not sure if it will work --- .github/workflows/release_to_pypi.yml | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .github/workflows/release_to_pypi.yml diff --git a/.github/workflows/release_to_pypi.yml b/.github/workflows/release_to_pypi.yml new file mode 100644 index 00000000..e1ad9b86 --- /dev/null +++ b/.github/workflows/release_to_pypi.yml @@ -0,0 +1,60 @@ +name: Publish Chasten to PyPI / GitHub + +on: + push: + tags: + - "v*" + +jobs: + build-n-publish: + name: Build and publish to PyPI + runs-on: ubuntu-latest + + steps: + - name: Checkout source + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.11" + + - name: Build source and wheel distributions + run: | + python -m pip install --upgrade build twine + python -m build + twine check --strict dist/* + + - name: Publish distribution to PyPI + uses: pypa/gh-action-pypi-publish@master + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + + - name: Create GitHub Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + draft: false + prerelease: false + + - name: Get Asset name + run: | + export PKG=$(ls dist/ | grep tar) + set -- $PKG + echo "name=$1" >> $GITHUB_ENV + + - name: Upload Release Asset (sdist) to GitHub + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: dist/${{ env.name }} + asset_name: ${{ env.name }} + asset_content_type: application/zip From 106506a917dd09bb21212d58d4bd9a90acc35464 Mon Sep 17 00:00:00 2001 From: Miles Date: Mon, 11 Dec 2023 10:27:13 -0800 Subject: [PATCH 4/7] hopefully fixed the error, we can test in lab --- .github/workflows/release_to_pypi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release_to_pypi.yml b/.github/workflows/release_to_pypi.yml index e1ad9b86..e8e9f9db 100644 --- a/.github/workflows/release_to_pypi.yml +++ b/.github/workflows/release_to_pypi.yml @@ -26,7 +26,7 @@ jobs: twine check --strict dist/* - name: Publish distribution to PyPI - uses: pypa/gh-action-pypi-publish@master + uses: pypa/gh-action-pypi-publish@release/v1 # Updated this line with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} From 956ed8f8c6725872a53c2996cb873a56957a60f9 Mon Sep 17 00:00:00 2001 From: Poiuy7312 Date: Tue, 12 Dec 2023 15:29:31 -0500 Subject: [PATCH 5/7] Remove update_version code --- tests/test_update_version.py | 8 ------- update_version.py | 42 ------------------------------------ 2 files changed, 50 deletions(-) delete mode 100644 tests/test_update_version.py delete mode 100644 update_version.py diff --git a/tests/test_update_version.py b/tests/test_update_version.py deleted file mode 100644 index 786659ee..00000000 --- a/tests/test_update_version.py +++ /dev/null @@ -1,8 +0,0 @@ -import update_version - - -def test_updated_version() -> None: - """Test case for update_version function""" - assert update_version.updated_version("0.0.9") == "0.1.0" - assert update_version.updated_version("0.9.9") == "1.0.0" - assert update_version.updated_version("0.1.0") == "0.1.1" diff --git a/update_version.py b/update_version.py deleted file mode 100644 index 2354c2ea..00000000 --- a/update_version.py +++ /dev/null @@ -1,42 +0,0 @@ -from pathlib import Path - -import toml - -# defines the max value for the version except for the first value -UPDATE_STEP = 10 - - -def updated_version(version: str) -> str: - """Updates the version based on the current version and specified step""" - # gets a list of integers by splitting the version by a period - # this is so it can separately change each part of the version - version_list = [int(x) for x in version.split(".")] - # adds 1 to the last value of version - version_list[2] += 1 - # iterates through to make sure if the value is equal - # to ten it sets it to zero and adds 1 to the next part of - # version so it would change [0,2,10] to [0,3,0] - for i in range(2, 0, -1): - if version_list[i] >= UPDATE_STEP: - version_list[i - 1] += 1 - version_list[i] = 0 - # turns the result back into a string split by a period and returns it - # ex -> [0,3,0] turns into "0.3.0" - result = ".".join([str(x) for x in version_list]) - return result - - -if __name__ == "__main__": - # Open toml file and change the version of the program. - file = Path("pyproject.toml") - # turns the toml into a dictionary to be able to find - # the specified value and not change anything else - toml_dict = toml.load(file) - version = toml_dict["tool"]["poetry"]["version"] - # reads the text as a string - content = file.read_text() - # replaces the version with the updated version using the function - # updated_version, Only replaces the first instance of it - content = content.replace(version, updated_version(version), 1) - # write the changes to the toml file - file.write_text(content) From 87b7a5561301f47175314d70e3263a7145adf615 Mon Sep 17 00:00:00 2001 From: Poiuy7312 Date: Tue, 12 Dec 2023 15:52:53 -0500 Subject: [PATCH 6/7] feat: changed workflow to update version based on tag --- .github/workflows/publish.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7579d97d..e518871d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,6 +13,7 @@ jobs: python-version: 3.11 - run: | pip install poetry + poetry version ${GITHUB_REF##*/v} poetry build - uses: actions/upload-artifact@v3 with: @@ -31,4 +32,4 @@ jobs: - name: Publish Package Distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: - packages_dir: artifact/ + packages_dir: artifact/ \ No newline at end of file From 4a4285252f2d759a69dac3024f79c65ad6770944 Mon Sep 17 00:00:00 2001 From: Poiuy7312 Date: Tue, 12 Dec 2023 15:56:02 -0500 Subject: [PATCH 7/7] removed unneeded yaml file --- .github/workflows/release_to_pypi.yml | 60 --------------------------- 1 file changed, 60 deletions(-) delete mode 100644 .github/workflows/release_to_pypi.yml diff --git a/.github/workflows/release_to_pypi.yml b/.github/workflows/release_to_pypi.yml deleted file mode 100644 index e8e9f9db..00000000 --- a/.github/workflows/release_to_pypi.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: Publish Chasten to PyPI / GitHub - -on: - push: - tags: - - "v*" - -jobs: - build-n-publish: - name: Build and publish to PyPI - runs-on: ubuntu-latest - - steps: - - name: Checkout source - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: "3.11" - - - name: Build source and wheel distributions - run: | - python -m pip install --upgrade build twine - python -m build - twine check --strict dist/* - - - name: Publish distribution to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 # Updated this line - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} - - - name: Create GitHub Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: ${{ github.ref }} - draft: false - prerelease: false - - - name: Get Asset name - run: | - export PKG=$(ls dist/ | grep tar) - set -- $PKG - echo "name=$1" >> $GITHUB_ENV - - - name: Upload Release Asset (sdist) to GitHub - id: upload-release-asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: dist/${{ env.name }} - asset_name: ${{ env.name }} - asset_content_type: application/zip