Skip to content
Merged

test #1014

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Notify code owners about changes to GitHub actions
.github/ @JBWilkie
.github/ @umbertoDifa
66 changes: 53 additions & 13 deletions .github/workflows/version_bump.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -18,6 +18,8 @@ on:
required: true
default: false
type: boolean
pull_request:
types: [opened, synchronize, reopened]

permissions:
contents: write
Expand All @@ -40,25 +42,48 @@ jobs:
with:
python-version: "3.9"

- name: Configure Git
- 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: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
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 }}
BASE_VERSION=$(cat .version)
python deploy/increase_version.py --${{ env.BUMP_TYPE }} --auto-confirm y
BASE_VERSION=$(grep '__version__' darwin/version/__init__.py | cut -d '"' -f 2)

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
sed -i "s/^version = .*/version = \"${TEST_VERSION}\"/" pyproject.toml
sed -i "s/__version__ = .*/__version__ = \"${TEST_VERSION}\"/" darwin/__init__.py
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"
BRANCH_NAME="test/version-bump-${NEW_VERSION}"
else
NEW_VERSION="${BASE_VERSION}"
TAG_PREFIX="v"
Expand All @@ -68,20 +93,35 @@ 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"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Commit and push changes
if: ${{ inputs.test_mode != 'true' }}
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}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create test branch
if: ${{ inputs.test_mode == 'true' }}
if: ${{ env.TEST_MODE == 'true' }}
run: |
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 }}
17 changes: 14 additions & 3 deletions deploy/increase_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down Expand Up @@ -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",
Expand All @@ -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()

Expand Down Expand Up @@ -337,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)}?")
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)
Expand Down
Loading