@@ -67,78 +67,31 @@ jobs:
6767 - name : Install dependencies
6868 run : uv sync --dev
6969
70- # Handle workflow_dispatch (manual trigger)
71- - name : Bump version and create release
72- if : github.event_name == 'workflow_dispatch'
73- id : create_release
70+ # Compute and stage the new version locally — defer commit/tag/release
71+ # until lint+tests+build+publish all pass, so any failure leaves main untouched.
72+ - name : Compute new version
73+ id : version
7474 run : |
75- # Get current version from __init__.py using grep/sed (avoid importing)
7675 CURRENT_VERSION=$(grep -E "^__version__ = " src/unstract/api_deployments/__init__.py | sed -E 's/__version__ = "(.*)"/\1/')
7776 echo "Current version: $CURRENT_VERSION"
7877
79- # Calculate new version based on input
8078 IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
8179 MAJOR=${VERSION_PARTS[0]}
8280 MINOR=${VERSION_PARTS[1]}
8381 PATCH=${VERSION_PARTS[2]}
8482
8583 case "${{ github.event.inputs.version_bump }}" in
86- "major")
87- MAJOR=$((MAJOR + 1))
88- MINOR=0
89- PATCH=0
90- ;;
91- "minor")
92- MINOR=$((MINOR + 1))
93- PATCH=0
94- ;;
95- "patch")
96- PATCH=$((PATCH + 1))
97- ;;
84+ "major") MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
85+ "minor") MINOR=$((MINOR + 1)); PATCH=0 ;;
86+ "patch") PATCH=$((PATCH + 1)) ;;
9887 esac
9988
10089 NEW_VERSION="$MAJOR.$MINOR.$PATCH"
10190 echo "New version: $NEW_VERSION"
10291 echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
10392
104- # Update version in __init__.py
10593 sed -i "s/__version__ = \"$CURRENT_VERSION\"/__version__ = \"$NEW_VERSION\"/" src/unstract/api_deployments/__init__.py
10694
107- # Commit version changes
108- git add src/unstract/api_deployments/__init__.py
109- git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
110- git push origin main
111-
112- # Create git tag
113- git tag "v$NEW_VERSION"
114- git push origin "v$NEW_VERSION"
115-
116- # Create GitHub release
117- RELEASE_NOTES="${{ github.event.inputs.release_notes }}"
118- if [ -z "$RELEASE_NOTES" ]; then
119- gh release create "v$NEW_VERSION" \
120- --title "Release v$NEW_VERSION" \
121- --generate-notes \
122- ${{ github.event.inputs.pre_release == 'true' && '--prerelease' || '' }}
123- else
124- gh release create "v$NEW_VERSION" \
125- --title "Release v$NEW_VERSION" \
126- --notes "$RELEASE_NOTES" \
127- --generate-notes \
128- ${{ github.event.inputs.pre_release == 'true' && '--prerelease' || '' }}
129- fi
130-
131- echo "Created release v$NEW_VERSION"
132- env :
133- GITHUB_TOKEN : ${{ steps.generate-token.outputs.token }}
134-
135- # Set version for subsequent steps
136- - name : Set version output
137- id : version
138- run : |
139- echo "version=${{ steps.create_release.outputs.version }}" >> $GITHUB_OUTPUT
140-
141- # Verify the version was updated correctly
14295 - name : Verify version update
14396 run : |
14497 PACKAGE_VERSION=$(grep -E "^__version__ = " src/unstract/api_deployments/__init__.py | sed -E 's/__version__ = "(.*)"/\1/')
@@ -149,27 +102,53 @@ jobs:
149102 exit 1
150103 fi
151104
152- # Create test environment
153105 - name : Create test env
154106 run : cp tests/sample.env tests/.env
155107
156- # Run linting
157108 - name : Run linting
158109 run : uv run ruff check src/
159110
160- # Run tests
161111 - name : Run tests
162112 run : uv run pytest tests/
163113
164- # Build the package
165114 - name : Build package
166115 run : uv build
167116
168- # Publish to PyPI using Trusted Publishers
117+ # PyPI publish first because it is the only step that cannot be undone —
118+ # if a later commit/tag/release step fails, the PyPI artifact is the
119+ # source of truth and the git metadata can be retried manually.
169120 - name : Publish to PyPI
170121 run : uv publish
171122
172- # Output success message
123+ - name : Commit version bump and create release
124+ run : |
125+ NEW_VERSION="${{ steps.version.outputs.version }}"
126+
127+ git add src/unstract/api_deployments/__init__.py
128+ git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
129+ git push origin main
130+
131+ git tag "v$NEW_VERSION"
132+ git push origin "v$NEW_VERSION"
133+
134+ RELEASE_NOTES="${{ github.event.inputs.release_notes }}"
135+ if [ -z "$RELEASE_NOTES" ]; then
136+ gh release create "v$NEW_VERSION" \
137+ --title "Release v$NEW_VERSION" \
138+ --generate-notes \
139+ ${{ github.event.inputs.pre_release == 'true' && '--prerelease' || '' }}
140+ else
141+ gh release create "v$NEW_VERSION" \
142+ --title "Release v$NEW_VERSION" \
143+ --notes "$RELEASE_NOTES" \
144+ --generate-notes \
145+ ${{ github.event.inputs.pre_release == 'true' && '--prerelease' || '' }}
146+ fi
147+
148+ echo "Created release v$NEW_VERSION"
149+ env :
150+ GITHUB_TOKEN : ${{ steps.generate-token.outputs.token }}
151+
173152 - name : Success message
174153 run : |
175154 echo "Successfully published version ${{ steps.version.outputs.version }} to PyPI using uv publish with Trusted Publishers"
0 commit comments