From cfb7f90146806bbcf7a74c8b1d2c4c0d1de71564 Mon Sep 17 00:00:00 2001 From: sjpark608 Date: Thu, 19 Dec 2024 14:28:40 -0800 Subject: [PATCH 1/3] new staging workflow separted into 3 jobs - bump version, build and publish the test package - delete the tag when fails - install published test package, perform hardware test - delete the tag when fails - cherrypick the bumped version to dev --- .bumpversion.cfg | 2 +- .../workflows/build-and-publish-TestPyPI.yml | 136 ++++++++++++++---- setup.py | 2 +- 3 files changed, 109 insertions(+), 31 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index da0c5a3a..82c60a37 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,3 +1,3 @@ [bumpversion] tag_name = rc/v{new_version} -current_version = 1.2.21 +current_version = 1.2.27 diff --git a/.github/workflows/build-and-publish-TestPyPI.yml b/.github/workflows/build-and-publish-TestPyPI.yml index e919244d..3dd3f08d 100644 --- a/.github/workflows/build-and-publish-TestPyPI.yml +++ b/.github/workflows/build-and-publish-TestPyPI.yml @@ -22,18 +22,20 @@ jobs: with: persist-credentials: false # cut assumes version number is surrounded by double-quotes. - - name: Get Current Version - run: echo "current_version=$(grep "version" setup.py | cut -d '"' -f2)" >> $GITHUB_ENV + - name: Get Original Version + run: echo "original_version=$(grep "version" setup.py | cut -d '"' -f2)" >> $GITHUB_ENV - name: Auto Bump Package Version uses: FragileTech/bump-version@main with: - current_version: "${{ env.current_version }}" + current_version: "${{ env.original_version }}" files: setup.py part: patch commit_name: bot-edgepi commit_email: bot@edgepi.com login: bot-edgepi token: "${{ secrets.ACTIONS_BOT_TOKEN }}" + - name: Get Current Version + run: echo "current_version=$(grep "version" setup.py | cut -d '"' -f2)" >> $GITHUB_ENV - name: Set up Python uses: actions/setup-python@v3 with: @@ -48,8 +50,109 @@ jobs: - name: Publish Distribution to TestPyPI uses: pypa/gh-action-pypi-publish@v1.9.0 with: + verbose: true password: ${{ secrets.TEST_PYPI_API_TOKEN }} repository_url: https://test.pypi.org/legacy/ + - name: Handling Failure Delete tag + if: failure() + env: + commit_name: bot-edgepi + commit_email: bot@edgepi.com + login: bot-edgepi + token: "${{ secrets.ACTIONS_BOT_TOKEN }}" + run: | + set -x + # Setup Git env and user + git config user.name ${{ env.commit_name }} + git config user.email ${{ env.commit_email }} + git config --global pull.rebase false + BRANCH=${GITHUB_REF#refs/heads/} + git pull --no-edit ${{ env.login }} $BRANCH + git config --global url."https://${{ env.login }}:${{ env.token }}@github.com/".insteadOf "https://github.com/" + # merge done by git pull does not update submodules changed in $BRANCH + git submodule update --init --recursive + + # Delete Git tags + git tag -d rc/v${{ env.current_version }} + git push origin --delete rc/v${{ env.current_version }} + git config --global --unset url."https://${{ env.login }}:${{ env.token }}@github.com/".insteadOf + +# Decrementing the current version number, this may be needed later. +# my_var=$(echo $(grep "version" setup.py | cut -d '"' -f2 | cut -d '.' -f3)) +# my_var=$(echo $((my_var-1))) +# Write the reverted version number back to setup file and +# sed -i "s/\(version=\"[0-9]\+\.[0-9]\+\.\)[0-9]\+\"/\1$my_var\"/" setup.py +# sed -i "s/\(current_version = [0-9]\+\.[0-9]\+\.\)[0-9]\+/\1$my_var/" .bumpversion.cfg +# git add . && git commit -m "Failed Publish Job --- decremented version" && git push + + Hardware_Test: + needs: publish + name: Hardware Tests + runs-on: [self-hosted, linux, ARM64, integration] + strategy: + fail-fast: false + matrix: + python-version: ["3.9"] + steps: + # Wait for 1 minutes for TestPyPI to be updated + - name: Sleep for 1 minute + run: sleep 60s + shell: bash + - name: Checkout + uses: actions/checkout@v3 + with: + ref: staging + token: ${{ secrets.ACTIONS_BOT_TOKEN }} + fetch-depth: 0 + - name: Install Dependencies and check SDK versions + run: | + python -m venv venv_hardware_test + source venv_hardware_test/bin/activate + python -m pip install --upgrade pip + python -m pip install pytest + if [ -f requirements_hw_test.txt ]; then pip install -r requirements_hw_test.txt; fi + echo "actual_sdk_version=$(pip list | grep edgepi | cut -d ' ' -f2)" >> $GITHUB_ENV + echo "expected_sdk_version=$(grep "version" setup.py | cut -d '"' -f2)" >> $GITHUB_ENV + - name: Compare versions + run: | + if [ ${{env.expected_sdk_version}} != ${{env.actual_sdk_version}} ]; then + echo "SDK Version Mismatch" + exit 1 + fi + - name: Test with pytest + run: | + source venv_hardware_test/bin/activate + python -m pytest ./tests/hardware_tests + - name: Handling Failure Delete tag + if: failure() + env: + commit_name: bot-edgepi + commit_email: bot@edgepi.com + login: bot-edgepi + token: "${{ secrets.ACTIONS_BOT_TOKEN }}" + run: | + set -x + # Setup Git env and user + git config user.name ${{ env.commit_name }} + git config user.email ${{ env.commit_email }} + git config --global pull.rebase false + BRANCH=${GITHUB_REF#refs/heads/} + git remote add ${{ env.login }} https://${{ env.login }}:${{ env.token }}@github.com/$GITHUB_REPOSITORY + git pull --no-edit ${{ env.login }} $BRANCH + git config --global url."https://${{ env.login }}:${{ env.token }}@github.com/".insteadOf "https://github.com/" + # merge done by git pull does not update submodules changed in $BRANCH + git submodule update --init --recursive + + # Delete Git tags + git tag -d rc/v${{ env.expected_sdk_version }} + git push origin --delete rc/v${{ env.expected_sdk_version }} + git config --global --unset url."https://${{ env.login }}:${{ env.token }}@github.com/".insteadOf + + Bump_version_on_dev: + name: Bump version numbers in Dev + needs: Hardware_Test + runs-on: ubuntu-latest + steps: - name: Checkout Dev uses: actions/checkout@v3 with: @@ -68,29 +171,4 @@ jobs: git config user.name ${{ env.commit_name }} git config user.email ${{ env.commit_email }} git cherry-pick ${{ env.bump_commit }} - git push origin dev - - - # Hardware_Test: - # needs: publish - # name: Hardware Tests - # runs-on: [self-hosted, linux, ARM64, hw-test] - # strategy: - # fail-fast: false - # matrix: - # python-version: ["3.9"] - - # steps: - # - name: Checkout - # uses: actions/checkout@v3 - # - name: Install Dependencies - # run: | - # python -m venv venv_hardware_test - # source venv_hardware_test/bin/activate - # python -m pip install --upgrade pip - # python -m pip install pytest - # if [ -f requirements_hw_test.txt ]; then pip install -r requirements_hw_test.txt; fi - # - name: Test with pytest - # run: | - # source venv_hardware_test/bin/activate - # python -m pytest ./tests/hardware_tests + git push origin dev \ No newline at end of file diff --git a/setup.py b/setup.py index 46719b7e..5ff42ca0 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setuptools.setup( name="edgepi-python-sdk", - version="1.2.21", + version="1.2.27", author="S.Park", author_email="spark@osensa.com", description="EdgePi Python SDK package", From abec96302f048003d218ba73cba4979c05783f75 Mon Sep 17 00:00:00 2001 From: sjpark608 Date: Thu, 19 Dec 2024 14:33:43 -0800 Subject: [PATCH 2/3] Update .pylintrc --- .pylintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.pylintrc b/.pylintrc index 3109e2f5..a10f277c 100644 --- a/.pylintrc +++ b/.pylintrc @@ -8,6 +8,7 @@ disable=logging-fstring-interpolation, duplicate-code, no-else-return, no-else-raise, + too-many-positional-arguments, logging-fstring-interpolation [LOGGING] From 85e44b3340e6af4c1d514896649dc5a1cc9a8372 Mon Sep 17 00:00:00 2001 From: sjpark608 Date: Thu, 19 Dec 2024 14:53:29 -0800 Subject: [PATCH 3/3] Update build-and-publish-TestPyPI.yml added comment explaining newly added job --- .github/workflows/build-and-publish-TestPyPI.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build-and-publish-TestPyPI.yml b/.github/workflows/build-and-publish-TestPyPI.yml index 3dd3f08d..9faf44a3 100644 --- a/.github/workflows/build-and-publish-TestPyPI.yml +++ b/.github/workflows/build-and-publish-TestPyPI.yml @@ -53,6 +53,8 @@ jobs: verbose: true password: ${{ secrets.TEST_PYPI_API_TOKEN }} repository_url: https://test.pypi.org/legacy/ + # Handling Failure Delete Tag: this step only gets executed when there's a failed step. + # When the job finishes with failed step, the tag created from bump version acrtion gets deleted - name: Handling Failure Delete tag if: failure() env: @@ -123,6 +125,8 @@ jobs: run: | source venv_hardware_test/bin/activate python -m pytest ./tests/hardware_tests + # Handling Failure Delete Tag: this step only gets executed when there's a failed step. + # When the job finishes with failed step, the tag created from bump version acrtion gets deleted - name: Handling Failure Delete tag if: failure() env: