Skip to content

Commit 3f289f4

Browse files
committed
IMPROVEMENT: validate the version number before taging
1 parent 889ceb9 commit 3f289f4

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

.github/workflows/bump_version_and_tag.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,41 @@ jobs:
2323
- name: Checkout repository
2424
uses: actions/checkout@v4
2525

26+
- name: Set up Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: 3.x
30+
31+
- name: Install dependencies
32+
run: |
33+
python -m pip install --upgrade pip
34+
pip install packaging
35+
2636
- name: Validate version format
2737
run: |
2838
if ! [[ ${{ github.event.inputs.version }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
2939
echo "Invalid version format. Must be X.Y.Z"
3040
exit 1
3141
fi
3242
43+
- name: Get current version
44+
id: current_version
45+
run: |
46+
CURRENT_VERSION=$(grep -oP '__version__ = "\K[^"]+' ardupilot_methodic_configurator/__init__.py)
47+
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
48+
49+
- name: Compare versions
50+
run: |
51+
python3 - <<EOF
52+
from packaging import version
53+
current = version.parse("${{ steps.current_version.outputs.current_version }}")
54+
new = version.parse("${{ github.event.inputs.version }}")
55+
if new <= current:
56+
print(f"Error: New version {new} must be greater than current version {current}")
57+
exit(1)
58+
print(f"Version increase valid: {current} -> {new}")
59+
EOF
60+
3361
- name: Update version in __init__.py
3462
run: |
3563
sed -i 's/__version__ = ".*"/__version__ = "${{ github.event.inputs.version }}"/' ardupilot_methodic_configurator/__init__.py
@@ -45,4 +73,4 @@ jobs:
4573
- name: Create and push tag
4674
run: |
4775
git tag -a "v${{ github.event.inputs.version }}" -m "${{ github.event.inputs.tag_message }}"
48-
git push origin "v${{ github.event.inputs.version }}"
76+
git push origin "v${{ github.event.inputs.version }}"

0 commit comments

Comments
 (0)