From 9569bef220e640f719c02ad086f2a343c95b8473 Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 18:43:58 +0100 Subject: [PATCH 01/12] F --- .github/workflows/JOB_python_checks.yml | 2 ++ .github/workflows/version_bump.yml | 30 ++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/workflows/JOB_python_checks.yml b/.github/workflows/JOB_python_checks.yml index 8f2f15c47..1a1a9a3a1 100644 --- a/.github/workflows/JOB_python_checks.yml +++ b/.github/workflows/JOB_python_checks.yml @@ -22,3 +22,5 @@ jobs: run_tests: name: Run tests uses: ./.github/workflows/JOB_tests.yml + with: + files: ${{ inputs.files }} diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index 38d7c6495..61f85c121 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -1,5 +1,5 @@ name: Version Bump -run-name: Version bump ${{ inputs.bump_type }}${{ inputs.test_mode && ' (TEST)' || '' }} +run-name: Version bump ${{ github.event_name == 'workflow_dispatch' && inputs.bump_type || 'patch' }}${{ github.event_name == 'workflow_dispatch' && inputs.test_mode && ' (TEST)' || '' }} on: workflow_dispatch: @@ -18,6 +18,8 @@ on: required: true default: false type: boolean + pull_request: + types: [opened, synchronize, reopened] permissions: contents: write @@ -40,17 +42,29 @@ jobs: with: python-version: "3.9" - - name: Configure Git + - name: Install dependencies run: | - git config user.name github-actions[bot] - git config user.email github-actions[bot]@users.noreply.github.com + python -m pip install --upgrade pip + pip install requests + + - name: Set bump type and test mode + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + BUMP_TYPE="${{ inputs.bump_type }}" + TEST_MODE="${{ inputs.test_mode }}" + else + BUMP_TYPE="patch" # Default to "patch" for pull requests + TEST_MODE="true" # Always run in test mode for pull requests + fi + echo "BUMP_TYPE=${BUMP_TYPE}" >> $GITHUB_ENV + echo "TEST_MODE=${TEST_MODE}" >> $GITHUB_ENV - name: Bump version run: | - python deploy/increase_version.py --${{ inputs.bump_type }} + python deploy/increase_version.py --${{ env.BUMP_TYPE }} BASE_VERSION=$(cat .version) - if [[ "${{ inputs.test_mode }}" == "true" ]]; then + if [[ "${{ env.TEST_MODE }}" == "true" ]]; then TIMESTAMP=$(date +%Y%m%d%H%M%S) TEST_VERSION="${BASE_VERSION}-test.${TIMESTAMP}" # Update version in pyproject.toml and __init__.py @@ -69,14 +83,14 @@ jobs: echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV - name: Commit and push changes - if: ${{ inputs.test_mode != 'true' }} + if: ${{ env.TEST_MODE != 'true' }} run: | git add pyproject.toml darwin/__init__.py git commit -m "Version bump to ${{ env.NEW_VERSION }}" git push origin HEAD:${BRANCH_NAME} - name: Create test branch - if: ${{ inputs.test_mode == 'true' }} + if: ${{ env.TEST_MODE == 'true' }} run: | git checkout -b ${BRANCH_NAME} git push origin ${BRANCH_NAME} From 1b2f3df16cd9f13a6bf21927da4f8d99aff0d4c9 Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 18:50:50 +0100 Subject: [PATCH 02/12] fix --- .github/workflows/version_bump.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index 61f85c121..0c2144f6c 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -45,7 +45,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install requests + pip install requests toml validate-pyproject poetry pytest - name: Set bump type and test mode run: | From e6367d01ba2d67f9c40fc395fb194facedbda2ed Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 18:58:51 +0100 Subject: [PATCH 03/12] fix --- .github/workflows/version_bump.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index 0c2144f6c..d55309488 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -42,10 +42,18 @@ jobs: with: python-version: "3.9" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install requests toml validate-pyproject poetry pytest + - name: Install dependencies with retry + uses: nick-invision/retry@7152eba30c6575329ac0576536151aca5a72780e + with: + timeout_minutes: 10 + max_attempts: 3 + command: | + bash -c "pip install poetry pytest && \ + poetry install --no-interaction --no-root -vvv --all-extras && \ + poetry install --no-interaction --no-root --all-extras -vvv && \ + pip install wheel && \ + pip install --upgrade setuptools && \ + pip install --editable '.[test,ml,medical,dev, ocv]'" - name: Set bump type and test mode run: | From 6997511126bf9a3a8fd437e418d8b99439bcabfb Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 19:09:26 +0100 Subject: [PATCH 04/12] fix --- .github/workflows/version_bump.yml | 2 +- deploy/increase_version.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index d55309488..961818489 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -69,7 +69,7 @@ jobs: - name: Bump version run: | - python deploy/increase_version.py --${{ env.BUMP_TYPE }} + python deploy/increase_version.py --${{ env.BUMP_TYPE }} --auto-confirm y BASE_VERSION=$(cat .version) if [[ "${{ env.TEST_MODE }}" == "true" ]]; then diff --git a/deploy/increase_version.py b/deploy/increase_version.py index 8c7bc3d67..b2732905d 100755 --- a/deploy/increase_version.py +++ b/deploy/increase_version.py @@ -96,7 +96,10 @@ def __str__(self) -> str: return f"{self.major}.{self.minor}.{self.patch}" -def confirm(question: str) -> bool: +def confirm(question: str, auto_answer: str = None) -> bool: + if auto_answer is not None: + return auto_answer.lower() in ["y", "yes"] + while True: answer = input(f"{question} [y/n]: ").lower().strip() if answer in ["y", "yes"]: @@ -245,7 +248,6 @@ def arguments() -> argparse.Namespace: action="store_true", help="run in CI/CD mode (no confirmation, assume failure unless --force specified)", ) - parser.add_argument( "-v", "--version", @@ -268,6 +270,12 @@ def arguments() -> argparse.Namespace: type=str, help="set new version number (overrides -M, -m, -p)", ) + parser.add_argument( + "--auto-confirm", + type=str, + choices=["y", "n"], + help="Automatically confirm the action (y/n)", + ) return parser.parse_args() @@ -337,7 +345,7 @@ def main() -> None: if new_version.was_changed() and ( force_actions or cicd_mode - or confirm(f"Update version from {str(LOCAL_VERSION)} to {str(new_version)}?") + or confirm(f"Update version from {str(LOCAL_VERSION)} to {str(new_version)}?", args.auto_confirm) ): _update_version(new_version) _update_pyproject_version(new_version) From 4addad5e70b857d752b3da3d03592da598ab4964 Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 19:17:57 +0100 Subject: [PATCH 05/12] fix --- .github/workflows/JOB_python_checks.yml | 2 -- .github/workflows/version_bump.yml | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/JOB_python_checks.yml b/.github/workflows/JOB_python_checks.yml index 1a1a9a3a1..8f2f15c47 100644 --- a/.github/workflows/JOB_python_checks.yml +++ b/.github/workflows/JOB_python_checks.yml @@ -22,5 +22,3 @@ jobs: run_tests: name: Run tests uses: ./.github/workflows/JOB_tests.yml - with: - files: ${{ inputs.files }} diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index 961818489..4f1e0854b 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -70,7 +70,7 @@ jobs: - name: Bump version run: | python deploy/increase_version.py --${{ env.BUMP_TYPE }} --auto-confirm y - BASE_VERSION=$(cat .version) + BASE_VERSION=$(grep -oP '(?<=^version = ")[^"]*' pyproject.toml) if [[ "${{ env.TEST_MODE }}" == "true" ]]; then TIMESTAMP=$(date +%Y%m%d%H%M%S) From 316db6eea15e0318fd802a526fcf4f42f6eaa410 Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 19:32:16 +0100 Subject: [PATCH 06/12] fix --- .github/workflows/version_bump.yml | 7 ++++--- deploy/increase_version.py | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index 4f1e0854b..3f879bd5b 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -75,9 +75,10 @@ jobs: if [[ "${{ env.TEST_MODE }}" == "true" ]]; then TIMESTAMP=$(date +%Y%m%d%H%M%S) TEST_VERSION="${BASE_VERSION}-test.${TIMESTAMP}" - # Update version in pyproject.toml and __init__.py - sed -i "s/^version = .*/version = \"${TEST_VERSION}\"/" pyproject.toml - sed -i "s/__version__ = .*/__version__ = \"${TEST_VERSION}\"/" darwin/__init__.py + # Update version in pyproject.toml and in __init__.py + awk -v new_version="$TEST_VERSION" '/^version = / {$0 = "version = \"" new_version "\""} 1' pyproject.toml > pyproject.tmp && mv pyproject.tmp pyproject.toml + awk -v new_version="$TEST_VERSION" '/^__version__ = / {$0 = "__version__ = \"" new_version "\""} 1' darwin/__init__.py > darwin/__init__.tmp && mv darwin/__init__.tmp darwin/__init__.py + NEW_VERSION="${BASE_VERSION}-test.${TIMESTAMP}" TAG_PREFIX="test-" BRANCH_NAME="test/version-bump" diff --git a/deploy/increase_version.py b/deploy/increase_version.py index b2732905d..ebff3865f 100755 --- a/deploy/increase_version.py +++ b/deploy/increase_version.py @@ -99,7 +99,7 @@ def __str__(self) -> str: def confirm(question: str, auto_answer: str = None) -> bool: if auto_answer is not None: return auto_answer.lower() in ["y", "yes"] - + while True: answer = input(f"{question} [y/n]: ").lower().strip() if answer in ["y", "yes"]: @@ -345,7 +345,10 @@ def main() -> None: if new_version.was_changed() and ( force_actions or cicd_mode - or confirm(f"Update version from {str(LOCAL_VERSION)} to {str(new_version)}?", args.auto_confirm) + or confirm( + f"Update version from {str(LOCAL_VERSION)} to {str(new_version)}?", + args.auto_confirm, + ) ): _update_version(new_version) _update_pyproject_version(new_version) From ba276c883230d5a1e9bd1cda2cfe47f4e6ce0fe3 Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 19:37:23 +0100 Subject: [PATCH 07/12] fix --- .github/CODEOWNERS | 2 +- .github/workflows/version_bump.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 5008a658a..1640f5c3a 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,2 @@ # Notify code owners about changes to GitHub actions -.github/ @JBWilkie \ No newline at end of file +.github/ @umbertoDifa \ No newline at end of file diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index 3f879bd5b..d0f458ce3 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -75,9 +75,9 @@ jobs: if [[ "${{ env.TEST_MODE }}" == "true" ]]; then TIMESTAMP=$(date +%Y%m%d%H%M%S) TEST_VERSION="${BASE_VERSION}-test.${TIMESTAMP}" - # Update version in pyproject.toml and in __init__.py - awk -v new_version="$TEST_VERSION" '/^version = / {$0 = "version = \"" new_version "\""} 1' pyproject.toml > pyproject.tmp && mv pyproject.tmp pyproject.toml - awk -v new_version="$TEST_VERSION" '/^__version__ = / {$0 = "__version__ = \"" new_version "\""} 1' darwin/__init__.py > darwin/__init__.tmp && mv darwin/__init__.tmp darwin/__init__.py + # Update version in pyproject.toml and in __init__.py + awk -v new_version="$TEST_VERSION" '/^version = / {$0 = "version = \"" new_version "\""} 1' pyproject.toml > pyproject.tmp && mv pyproject.tmp pyproject.toml + awk -v new_version="$TEST_VERSION" '/^__version__ = / {$0 = "__version__ = \"" new_version "\""} 1' darwin/__init__.py > darwin/__init__.tmp && mv darwin/__init__.tmp darwin/__init__.py NEW_VERSION="${BASE_VERSION}-test.${TIMESTAMP}" TAG_PREFIX="test-" From c28a47df77455b42b4b19cb73dcee9881d8cc67e Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 19:44:53 +0100 Subject: [PATCH 08/12] fix --- .github/workflows/version_bump.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index d0f458ce3..86b2b1e46 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -75,11 +75,13 @@ jobs: if [[ "${{ env.TEST_MODE }}" == "true" ]]; then TIMESTAMP=$(date +%Y%m%d%H%M%S) TEST_VERSION="${BASE_VERSION}-test.${TIMESTAMP}" + echo "Adding test suffix" # Update version in pyproject.toml and in __init__.py awk -v new_version="$TEST_VERSION" '/^version = / {$0 = "version = \"" new_version "\""} 1' pyproject.toml > pyproject.tmp && mv pyproject.tmp pyproject.toml awk -v new_version="$TEST_VERSION" '/^__version__ = / {$0 = "__version__ = \"" new_version "\""} 1' darwin/__init__.py > darwin/__init__.tmp && mv darwin/__init__.tmp darwin/__init__.py NEW_VERSION="${BASE_VERSION}-test.${TIMESTAMP}" + echo $NEW_VERSION TAG_PREFIX="test-" BRANCH_NAME="test/version-bump" else @@ -94,6 +96,7 @@ jobs: - name: Commit and push changes if: ${{ env.TEST_MODE != 'true' }} run: | + echo "Commit and push version changes" git add pyproject.toml darwin/__init__.py git commit -m "Version bump to ${{ env.NEW_VERSION }}" git push origin HEAD:${BRANCH_NAME} @@ -101,6 +104,7 @@ jobs: - name: Create test branch if: ${{ env.TEST_MODE == 'true' }} run: | + echo "Create test branch" git checkout -b ${BRANCH_NAME} git push origin ${BRANCH_NAME} From 835c14c8a9e4c6793ada0a3df7fa9e6138362ab2 Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 19:51:41 +0100 Subject: [PATCH 09/12] fix --- .github/workflows/version_bump.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index 86b2b1e46..22e056239 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -70,7 +70,7 @@ jobs: - name: Bump version run: | python deploy/increase_version.py --${{ env.BUMP_TYPE }} --auto-confirm y - BASE_VERSION=$(grep -oP '(?<=^version = ")[^"]*' pyproject.toml) + BASE_VERSION=$(grep '__version__' darwin/version/__init__.py | cut -d '"' -f 2) if [[ "${{ env.TEST_MODE }}" == "true" ]]; then TIMESTAMP=$(date +%Y%m%d%H%M%S) From c634adf06479ea9ae4b3018c075fad0132445f7a Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 19:56:50 +0100 Subject: [PATCH 10/12] fix --- .github/workflows/version_bump.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index 22e056239..512425b7b 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -93,6 +93,11 @@ jobs: echo "TAG_PREFIX=${TAG_PREFIX}" >> $GITHUB_ENV echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV + - name: Configure Git + run: | + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "GitHub Actions" + - name: Commit and push changes if: ${{ env.TEST_MODE != 'true' }} run: | From 9ec627f9f84b0310167ba10c4d4200bcbf5ed239 Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 20:03:38 +0100 Subject: [PATCH 11/12] fix --- .github/workflows/version_bump.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index 512425b7b..81507c837 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -97,6 +97,9 @@ jobs: run: | git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "GitHub Actions" + git fetch origin + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Commit and push changes if: ${{ env.TEST_MODE != 'true' }} @@ -105,6 +108,8 @@ jobs: git add pyproject.toml darwin/__init__.py git commit -m "Version bump to ${{ env.NEW_VERSION }}" git push origin HEAD:${BRANCH_NAME} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create test branch if: ${{ env.TEST_MODE == 'true' }} @@ -112,8 +117,12 @@ jobs: echo "Create test branch" git checkout -b ${BRANCH_NAME} git push origin ${BRANCH_NAME} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create and push tag run: | git tag -a "${TAG_PREFIX}${NEW_VERSION}" -m "bump version to ${TAG_PREFIX}${NEW_VERSION}" git push origin "${TAG_PREFIX}${NEW_VERSION}" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 9f838ca53f3d34d79727fd551dfa99ad660a255d Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 20:10:38 +0100 Subject: [PATCH 12/12] fix --- .github/workflows/version_bump.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index 81507c837..b4ae2d28e 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -83,7 +83,7 @@ jobs: NEW_VERSION="${BASE_VERSION}-test.${TIMESTAMP}" echo $NEW_VERSION TAG_PREFIX="test-" - BRANCH_NAME="test/version-bump" + BRANCH_NAME="test/version-bump-${NEW_VERSION}" else NEW_VERSION="${BASE_VERSION}" TAG_PREFIX="v" @@ -97,7 +97,6 @@ jobs: run: | git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "GitHub Actions" - git fetch origin env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}