11name : Version Bump
2- run-name : Version bump ${{ inputs.bump_type }}${{ inputs.test_mode && ' (TEST)' || '' }}
2+ run-name : Version bump ${{ github.event_name == 'workflow_dispatch' && inputs.bump_type || 'patch' }}${{ github.event_name == 'workflow_dispatch' && inputs.test_mode && ' (TEST)' || '' }}
33
44on :
55 workflow_dispatch :
1818 required : true
1919 default : false
2020 type : boolean
21+ pull_request :
22+ types : [opened, synchronize, reopened]
2123
2224permissions :
2325 contents : write
@@ -40,25 +42,48 @@ jobs:
4042 with :
4143 python-version : " 3.9"
4244
43- - name : Configure Git
45+ - name : Install dependencies with retry
46+ uses : nick-invision/retry@7152eba30c6575329ac0576536151aca5a72780e
47+ with :
48+ timeout_minutes : 10
49+ max_attempts : 3
50+ command : |
51+ bash -c "pip install poetry pytest && \
52+ poetry install --no-interaction --no-root -vvv --all-extras && \
53+ poetry install --no-interaction --no-root --all-extras -vvv && \
54+ pip install wheel && \
55+ pip install --upgrade setuptools && \
56+ pip install --editable '.[test,ml,medical,dev, ocv]'"
57+
58+ - name : Set bump type and test mode
4459 run : |
45- git config user.name github-actions[bot]
46- git config user.email github-actions[bot]@users.noreply.github.com
60+ if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
61+ BUMP_TYPE="${{ inputs.bump_type }}"
62+ TEST_MODE="${{ inputs.test_mode }}"
63+ else
64+ BUMP_TYPE="patch" # Default to "patch" for pull requests
65+ TEST_MODE="true" # Always run in test mode for pull requests
66+ fi
67+ echo "BUMP_TYPE=${BUMP_TYPE}" >> $GITHUB_ENV
68+ echo "TEST_MODE=${TEST_MODE}" >> $GITHUB_ENV
4769
4870 - name : Bump version
4971 run : |
50- python deploy/increase_version.py --${{ inputs.bump_type }}
51- BASE_VERSION=$(cat . version)
72+ python deploy/increase_version.py --${{ env.BUMP_TYPE }} --auto-confirm y
73+ BASE_VERSION=$(grep '__version__' darwin/ version/__init__.py | cut -d '"' -f 2)
5274
53- if [[ "${{ inputs.test_mode }}" == "true" ]]; then
75+ if [[ "${{ env.TEST_MODE }}" == "true" ]]; then
5476 TIMESTAMP=$(date +%Y%m%d%H%M%S)
5577 TEST_VERSION="${BASE_VERSION}-test.${TIMESTAMP}"
56- # Update version in pyproject.toml and __init__.py
57- sed -i "s/^version = .*/version = \"${TEST_VERSION}\"/" pyproject.toml
58- sed -i "s/__version__ = .*/__version__ = \"${TEST_VERSION}\"/" darwin/__init__.py
78+ echo "Adding test suffix"
79+ # Update version in pyproject.toml and in __init__.py
80+ awk -v new_version="$TEST_VERSION" '/^version = / {$0 = "version = \"" new_version "\""} 1' pyproject.toml > pyproject.tmp && mv pyproject.tmp pyproject.toml
81+ 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
82+
5983 NEW_VERSION="${BASE_VERSION}-test.${TIMESTAMP}"
84+ echo $NEW_VERSION
6085 TAG_PREFIX="test-"
61- BRANCH_NAME="test/version-bump"
86+ BRANCH_NAME="test/version-bump-${NEW_VERSION} "
6287 else
6388 NEW_VERSION="${BASE_VERSION}"
6489 TAG_PREFIX="v"
@@ -68,20 +93,35 @@ jobs:
6893 echo "TAG_PREFIX=${TAG_PREFIX}" >> $GITHUB_ENV
6994 echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
7095
96+ - name : Configure Git
97+ run : |
98+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
99+ git config --global user.name "GitHub Actions"
100+ env :
101+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
102+
71103 - name : Commit and push changes
72- if : ${{ inputs.test_mode != 'true' }}
104+ if : ${{ env.TEST_MODE != 'true' }}
73105 run : |
106+ echo "Commit and push version changes"
74107 git add pyproject.toml darwin/__init__.py
75108 git commit -m "Version bump to ${{ env.NEW_VERSION }}"
76109 git push origin HEAD:${BRANCH_NAME}
110+ env :
111+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
77112
78113 - name : Create test branch
79- if : ${{ inputs.test_mode == 'true' }}
114+ if : ${{ env.TEST_MODE == 'true' }}
80115 run : |
116+ echo "Create test branch"
81117 git checkout -b ${BRANCH_NAME}
82118 git push origin ${BRANCH_NAME}
119+ env :
120+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
83121
84122 - name : Create and push tag
85123 run : |
86124 git tag -a "${TAG_PREFIX}${NEW_VERSION}" -m "bump version to ${TAG_PREFIX}${NEW_VERSION}"
87125 git push origin "${TAG_PREFIX}${NEW_VERSION}"
126+ env :
127+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments