Increment Versions #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |