Skip to content

Commit 0bf68df

Browse files
ci: Update bump-version workflow to regenerate snapshot tests (#552)
* ci: Update bump-version workflow to regenerate snapshot tests The bump-version workflow now includes: 1. Verification that pyproject.toml has exactly one line changed 2. A step to update snapshot tests when bumping the version 3. Verification that each snapshot SVG file has exactly one line changed This ensures that version bumps are clean and only affect the version string in pyproject.toml and the splash screen version in snapshot files. Changes: - Add verification that pyproject.toml diff has exactly 1 line change - Add 'Update snapshot tests' step that runs pytest with --snapshot-update - Add 'Verify snapshot diffs' step to check each SVG has exactly 1 line diff - Stage tests/snapshots/ files in the commit step - Update PR description to show diff verification status Co-authored-by: openhands <openhands@all-hands.dev> * fix: Remove || true from pytest to not hide snapshot failures Removing the error suppression ensures the workflow fails if snapshot regeneration encounters any issues, preventing broken state from being committed. * refactor: Remove unused PYPROJECT_DIFF_ESCAPED variable The variable was captured and exported to env but never used - the PR body uses a hardcoded template instead. Removing dead code to reduce complexity. * refactor: Rename LINES_CHANGED to DIFF_LINES in pyproject.toml check The variable name now accurately reflects what it measures - the numstat total (added + deleted lines), not logical lines changed. Also improved the log message to clarify the expectation. * refactor: Rename LINES_CHANGED to DIFF_LINES in snapshot verification For consistency with the pyproject.toml check, renamed the variable to accurately reflect what it measures - the numstat total (added + deleted). Also improved log messages to clarify the diff lines terminology. * fix: Replace brittle line-count check with version value verification Instead of checking that exactly 1 line changed (which fails in legitimate scenarios like updating dependencies during release), verify that the version field has the expected value. This checks what matters, not how many lines changed. * fix: Remove brittle snapshot diff verification step The per-file diff line check was over-specified and would break when: - pytest-textual-snapshot changes SVG generation formatting - Version string appears in multiple SVG elements - Whitespace normalization occurs The workflow already runs snapshot tests - if they're broken, the tests will fail. Trust the actual test run to catch broken snapshots instead of over-specifying validation based on implementation details. --------- Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 3ffa60f commit 0bf68df

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

.github/workflows/bump-version.yml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ jobs:
6464
# Update version in pyproject.toml
6565
sed -i "s/^version = \"$CURRENT_VERSION\"/version = \"$VERSION\"/" pyproject.toml
6666
67-
# Verify the change was made
68-
echo "Updated version line:"
69-
grep '^version = ' pyproject.toml
67+
# Verify the version field has the expected value
68+
ACTUAL_VERSION=$(grep "^version = " pyproject.toml | sed -E 's/version = "(.+)"/\1/')
69+
if [ "$ACTUAL_VERSION" != "$VERSION" ]; then
70+
echo "❌ Error: Version in pyproject.toml is $ACTUAL_VERSION, expected $VERSION"
71+
exit 1
72+
fi
73+
echo "✅ Verified: pyproject.toml version is $VERSION"
7074
7175
echo "current_version=$CURRENT_VERSION" >> $GITHUB_ENV
7276
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
@@ -83,24 +87,41 @@ jobs:
8387
# Ensure lock file is up to date
8488
uv lock
8589
90+
- name: Update snapshot tests
91+
run: |
92+
# Update snapshot tests to reflect the new version
93+
# The version appears in the splash screen SVG snapshots
94+
echo "Updating snapshot tests for version ${{ inputs.version }}..."
95+
uv run pytest tests/snapshots/ --snapshot-update -v
96+
97+
# List the updated snapshot files
98+
echo "Updated snapshot files:"
99+
git status --short tests/snapshots/
100+
86101
- name: Commit and push changes
87102
run: |
88103
VERSION="${{ inputs.version }}"
89104
BRANCH_NAME="${{ env.branch_name }}"
90105
91-
# Stage all changes (pyproject.toml and uv.lock)
106+
# Stage all changes (pyproject.toml, uv.lock, and snapshot files)
92107
git add pyproject.toml uv.lock
108+
git add tests/snapshots/
93109
94110
# Check if there are changes to commit
95111
if git diff --cached --quiet; then
96112
echo "❌ No changes detected. Version might already be set to $VERSION."
97113
exit 1
98114
fi
99115
116+
# Count updated snapshot files and export for PR description
117+
SNAPSHOT_COUNT=$(git diff --cached --name-only -- 'tests/snapshots/' | wc -l)
118+
echo "snapshot_count=$SNAPSHOT_COUNT" >> $GITHUB_ENV
119+
100120
# Commit changes
101121
git commit -m "Bump version to $VERSION" \
102122
-m "- Updated version in pyproject.toml from ${{ env.current_version }} to $VERSION" \
103-
-m "- Regenerated uv.lock file"
123+
-m "- Regenerated uv.lock file" \
124+
-m "- Updated $SNAPSHOT_COUNT snapshot test file(s)"
104125
105126
# Push branch
106127
git push origin "$BRANCH_NAME"
@@ -131,6 +152,7 @@ jobs:
131152
run: |
132153
VERSION="${{ inputs.version }}"
133154
BRANCH_NAME="${{ env.branch_name }}"
155+
SNAPSHOT_COUNT="${{ env.snapshot_count }}"
134156
135157
# Create draft PR using GitHub API
136158
PR_RESPONSE=$(curl -s -X POST \
@@ -141,7 +163,7 @@ jobs:
141163
"title": "Bump version to '"$VERSION"'",
142164
"head": "'"$BRANCH_NAME"'",
143165
"base": "main",
144-
"body": "## Summary\n\nThis PR bumps the project version to **'"$VERSION"'**.\n\n## Changes\n\n- Updated `version` in `pyproject.toml` from `'"${{ env.current_version }}"'` to `'"$VERSION"'`\n- Regenerated `uv.lock` file\n\n## Triggered by\n\nManual workflow dispatch by @'"${{ github.actor }}"'",
166+
"body": "## Summary\n\nThis PR bumps the project version to **'"$VERSION"'**.\n\n## Changes\n\n### pyproject.toml\n```diff\n-version = \"'"${{ env.current_version }}"'\"\n+version = \"'"$VERSION"'\"\n```\n\n### Other changes\n- Regenerated `uv.lock` file\n- Updated '"$SNAPSHOT_COUNT"' snapshot test file(s)\n\n## Triggered by\n\nManual workflow dispatch by @'"${{ github.actor }}"'",
145167
"draft": true
146168
}')
147169

0 commit comments

Comments
 (0)