-
Notifications
You must be signed in to change notification settings - Fork 43
84 lines (65 loc) · 2.5 KB
/
increment_version_dev.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Increment Versions
on:
workflow_dispatch:
jobs:
increment-versions:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install TOML editor
run: |
python -m pip install --upgrade pip
pip install tomlkit
- name: Increment versions in pyproject.toml
run: |
set -x
echo "Incrementing versions..."
find . -name "pyproject.toml" | while read -r pyproject; do
echo "Processing $pyproject"
# Extract current version
CURRENT_VERSION=$(python -c "
import tomlkit
try:
with open('$pyproject', 'r') as f:
data = tomlkit.parse(f.read())
print(data['tool']['poetry']['version'])
except KeyError:
print(f'Error: Version key not found in {pyproject}', end='')
exit(1)
except Exception as e:
print(f'Error reading version from {pyproject}: {e}', end='')
exit(1)
")
echo "Extracted CURRENT_VERSION: $CURRENT_VERSION"
if [ -z "$CURRENT_VERSION" ]; then
echo "Error: Could not extract the current version from $pyproject"
cat "$pyproject"
continue
fi
# Increment version
BASE_VERSION=$(echo "$CURRENT_VERSION" | sed -E 's/(.*)-dev.*/\1/')
DEV_PART=$(echo "$CURRENT_VERSION" | grep -oE 'dev[0-9]+$' | grep -oE '[0-9]+')
# Fallback if no DEV_PART is found
if [ -z "$DEV_PART" ]; then
DEV_PART=0
fi
NEW_DEV_PART=$((DEV_PART + 1))
NEW_VERSION="${BASE_VERSION}-dev${NEW_DEV_PART}"
echo "Updating version from $CURRENT_VERSION to $NEW_VERSION"
done
- name: Commit changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Incremented versions in pyproject.toml files"
- name: Push changes
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref_name }}