name: Bump Version # Trigger the workflow on any push to main on: push: branches: - main permissions: contents: write # Required for pushing commits and tags concurrency: group: bump-version-main cancel-in-progress: false jobs: bump-version: runs-on: ubuntu-latest name: Bump Version Workflow steps: # --- Step 1: Checkout the repository --- - name: Checkout repo uses: actions/checkout@v4 with: fetch-depth: 0 # Needed to create tags and see full history # --- Step 2: Set up Python --- - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.11" # --- Step 3: Calculate version dynamically --- - name: Calculate version id: calc run: | VERSION=$(python scripts/get_version.py) echo "version=$VERSION" >> "$GITHUB_OUTPUT" echo "Computed version: $VERSION" # --- Step 4: Skip workflow for development versions --- - name: Skip if version contains 'dev' if: contains(steps.calc.outputs.version, 'dev') run: | echo "Version contains 'dev'. Skipping release-related steps." # --- Step 5: Update files and commit if necessary --- - name: Update files and commit id: commit_release if: "!contains(steps.calc.outputs.version, 'dev')" run: | git config user.name "github-actions" git config user.email "actions@github.com" # Files that contain the version string UPDATE_FILES="config.yaml .env" # Update versions python scripts/update_version.py "${{ steps.calc.outputs.version }}" $UPDATE_FILES # Commit changes if any git add $UPDATE_FILES if git diff --cached --quiet; then echo "No files changed. Skipping commit." echo "committed=false" >> "$GITHUB_OUTPUT" else git commit -m "chore: bump version to ${{ steps.calc.outputs.version }}" git push echo "committed=true" >> "$GITHUB_OUTPUT" fi # --- Step 6: Create release tag --- - name: Create release tag if it does not exist id: tagging if: steps.commit_release.outputs.committed == 'true' run: | TAG="v${{ steps.calc.outputs.version }}" if git rev-parse --verify "$TAG" >/dev/null 2>&1; then echo "Tag $TAG already exists. Skipping tag creation." else git tag -a "$TAG" -m "Release ${{ steps.calc.outputs.version }}" git push origin "$TAG" fi # --- Step 7: Bump to development version --- - name: Bump dev version id: bump_dev if: steps.commit_release.outputs.committed == 'true' run: | git config user.name "github-actions" git config user.email "actions@github.com" VERSION_BASE=$(python scripts/bump_dev_version.py | tail -n1) if [ -z "$VERSION_BASE" ]; then echo "Error: bump_dev_version.py returned an empty version." exit 1 fi git add src/akkudoktoreos/core/version.py if git diff --cached --quiet; then echo "version.py not changed. Skipping commit." else git commit -m "chore: bump dev version to ${VERSION_BASE}" git push fi