Skip to content

Commit 694adff

Browse files
Fix workflow to create separate commit and pass version explicitly
Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
1 parent 3c612b3 commit 694adff

5 files changed

Lines changed: 70 additions & 41 deletions

File tree

.github/scripts/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ Updates version numbers in documentation examples during the release process.
1010

1111
**Usage**:
1212
```bash
13-
# Automatically called by .github/workflows/manual-release.yml
13+
# With explicit version (recommended during release)
14+
bash .github/scripts/update-example-versions.sh "1.2.0"
15+
16+
# Without version argument (extracts from pom.xml)
1417
bash .github/scripts/update-example-versions.sh
1518
```
1619

1720
**What it does**:
18-
1. Extracts the current version from the root `pom.xml` (skipping parent version)
19-
2. Strips `-SNAPSHOT` suffix to get the release version
21+
1. Accepts an optional version argument (recommended to avoid confusion after release:prepare)
22+
2. If no argument, extracts the current version from the root `pom.xml` (skipping parent version) and strips `-SNAPSHOT` suffix
2023
3. Updates all `<version>` tags within `<dependency>` blocks in README.md
2124
4. Reports changes made via git diff
2225

.github/scripts/test-update-example-versions.sh

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,29 @@ test_snapshot_stripping() {
153153
fi
154154
}
155155

156-
# Test 3: Full script execution in test environment
156+
# Test 3: Script accepts version argument
157+
test_version_argument() {
158+
TESTS_RUN=$((TESTS_RUN + 1))
159+
info "Test 3: Script accepts version argument"
160+
161+
# Change to test directory to ensure we're not in repo root
162+
cd "$TEST_DIR"
163+
164+
# Run script with explicit version argument
165+
local output=$(bash "$SCRIPT_UNDER_TEST" "9.9.9" 2>&1)
166+
167+
if echo "$output" | grep -q "Using version from argument: 9.9.9"; then
168+
pass "Script accepts and uses version argument"
169+
else
170+
fail "Version argument handling" "script should accept version argument" "script did not recognize argument"
171+
echo " Output was: $output" | head -5
172+
fi
173+
}
174+
175+
# Test 4: Full script execution in test environment
157176
test_full_script_execution() {
158177
TESTS_RUN=$((TESTS_RUN + 1))
159-
info "Test 3: Full script execution"
178+
info "Test 4: Full script execution"
160179

161180
# Create a modified version of the script that operates in TEST_DIR
162181
local test_script="/tmp/test-script-$$.sh"
@@ -180,10 +199,10 @@ test_full_script_execution() {
180199
rm -f /tmp/test-output-$$.log "$test_script"
181200
}
182201

183-
# Test 4: Version pattern matching
202+
# Test 5: Version pattern matching
184203
test_version_pattern_matching() {
185204
TESTS_RUN=$((TESTS_RUN + 1))
186-
info "Test 4: Version pattern matching"
205+
info "Test 5: Version pattern matching"
187206

188207
# Test the sed pattern used in the script on a sample
189208
local sample='<dependency><version>1.0.0</version></dependency>'
@@ -197,10 +216,10 @@ test_version_pattern_matching() {
197216
fi
198217
}
199218

200-
# Test 5: Selective replacement (only in dependency blocks)
219+
# Test 6: Selective replacement (only in dependency blocks)
201220
test_selective_replacement() {
202221
TESTS_RUN=$((TESTS_RUN + 1))
203-
info "Test 5: Selective replacement"
222+
info "Test 6: Selective replacement"
204223

205224
# Create a test file
206225
cat > /tmp/test-selective-$$.md << 'EOF'
@@ -231,10 +250,10 @@ EOF
231250
fi
232251
}
233252

234-
# Test 6: Script handles errors gracefully
253+
# Test 7: Script handles errors gracefully
235254
test_error_handling() {
236255
TESTS_RUN=$((TESTS_RUN + 1))
237-
info "Test 6: Script handles errors gracefully"
256+
info "Test 7: Script handles errors gracefully"
238257

239258
# Test that script handles missing files gracefully
240259
cd "$TEST_DIR"
@@ -271,6 +290,7 @@ main() {
271290
# Run tests
272291
test_version_extraction
273292
test_snapshot_stripping
293+
test_version_argument
274294
test_full_script_execution
275295
test_version_pattern_matching
276296
test_selective_replacement

.github/scripts/update-example-versions.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,27 @@ main() {
3232

3333
echo "Updating example version numbers in documentation..."
3434

35-
# Get the current version from the root pom.xml
36-
CURRENT_VERSION=$(get_version_from_pom "pom.xml")
37-
38-
if [ -z "$CURRENT_VERSION" ]; then
39-
echo "ERROR: Could not extract version from pom.xml"
40-
exit 1
35+
# Check if version was passed as argument
36+
if [ $# -gt 0 ] && [ -n "$1" ]; then
37+
# Use version from command line argument
38+
RELEASE_VERSION="$1"
39+
echo "Using version from argument: $RELEASE_VERSION"
40+
else
41+
# Get the current version from the root pom.xml
42+
CURRENT_VERSION=$(get_version_from_pom "pom.xml")
43+
44+
if [ -z "$CURRENT_VERSION" ]; then
45+
echo "ERROR: Could not extract version from pom.xml"
46+
exit 1
47+
fi
48+
49+
echo "Current version from pom.xml: $CURRENT_VERSION"
50+
51+
# Strip -SNAPSHOT suffix if present (we want the release version)
52+
RELEASE_VERSION="${CURRENT_VERSION%-SNAPSHOT}"
53+
echo "Release version: $RELEASE_VERSION"
4154
fi
4255

43-
echo "Current version: $CURRENT_VERSION"
44-
45-
# Strip -SNAPSHOT suffix if present (we want the release version)
46-
RELEASE_VERSION="${CURRENT_VERSION%-SNAPSHOT}"
47-
4856
echo "Updating documentation to use version: $RELEASE_VERSION"
4957

5058
# Files to update

.github/workflows/manual-release.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,25 +188,24 @@ jobs:
188188
run: |
189189
echo "Updating example version numbers in documentation..."
190190
191-
# Run the script to update version numbers in README.md and other docs
192-
bash .github/scripts/update-example-versions.sh
191+
VERSION="${{ steps.release.outputs.version }}"
192+
193+
# Run the script with the explicit release version
194+
# Pass version directly to avoid reading from pom.xml which now has SNAPSHOT
195+
bash .github/scripts/update-example-versions.sh "$VERSION"
193196
194197
# Check if there are any changes
195198
if git diff --quiet; then
196199
echo "No version updates needed"
197200
else
198-
echo "Documentation examples updated with release version"
201+
echo "Documentation examples updated with release version $VERSION"
199202
200-
# Amend the release commit created by release:prepare to include doc updates
201-
# Only add README.md since that's what the script updates
203+
# Create a third commit for documentation updates
204+
# This is safer than amending either of the release:prepare commits
202205
git add README.md
203-
git commit --amend --no-edit
204-
205-
# Update the tag to point to the amended commit
206-
TAG_NAME="${{ steps.release.outputs.tag_name }}"
207-
git tag -f "$TAG_NAME"
206+
git commit -m "[release] Update documentation examples to version $VERSION"
208207
209-
echo "✅ Release commit amended with documentation updates"
208+
echo "✅ Documentation updated in separate commit"
210209
fi
211210
212211
- name: Run Maven release:perform

RELEASING.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ Once you trigger the workflow, the "Manual Draft Release" workflow will:
5353
- Commit the next development iteration
5454
5.**Update example version numbers in documentation**:
5555
- Automatically update version numbers in README.md dependency examples
56-
- Amend the release commit to include documentation updates
57-
- Update the tag to point to the amended commit
56+
- Create a third commit with the documentation updates
5857
- Ensures documentation examples always match the release version
5958
6.**Run Maven release:perform** to:
6059
- Check out the release tag
@@ -89,16 +88,15 @@ Workflow: Runs release:prepare on main branch
8988
Workflow: Updates example versions in documentation
9089
9190
- Updates README.md with version 1.2.0
92-
- Amends Commit A to include documentation updates
93-
- Updates tag v1.2.0 → amended Commit A
91+
- Commit C: Documentation updates
9492
9593
Workflow: Runs release:perform
9694
9795
- Checks out tag v1.2.0 (commit A)
9896
- Builds and tests
9997
- Deploys to Maven Central
10098
101-
Workflow: Pushes commits A & B to main
99+
Workflow: Pushes commits A, B & C to main
102100
103101
Workflow: Pushes tag v1.2.0 → commit A
104102
@@ -108,7 +106,7 @@ Workflow: Publishes the GitHub Release
108106
109107
Result:
110108
- Tag v1.2.0 → commit A (release version: 1.2.0)
111-
- Main branch → commit B (next SNAPSHOT: 1.2.1-SNAPSHOT)
109+
- Main branch → commit C (next SNAPSHOT: 1.2.1-SNAPSHOT, with updated docs)
112110
- Artifacts deployed to Maven Central
113111
- GitHub Release published with JAR files
114112
```
@@ -117,9 +115,10 @@ Result:
117115

118116
1. Check the [Actions tab](https://github.com/BerryCloud/xapi-java/actions) to ensure the workflow completed successfully
119117
- The workflow will show a summary of the release including version, tag, and status
120-
2. Verify the target branch (e.g., `main`) has two new commits:
121-
- Release commit: `[maven-release-plugin] prepare release vX.Y.Z` (amended to include documentation updates)
118+
2. Verify the target branch (e.g., `main`) has three new commits:
119+
- Release commit: `[maven-release-plugin] prepare release vX.Y.Z`
122120
- Development commit: `[maven-release-plugin] prepare for next development iteration`
121+
- Documentation commit: `[release] Update documentation examples to version X.Y.Z`
123122
3. Verify the GitHub Release was published at the [Releases page](https://github.com/BerryCloud/xapi-java/releases)
124123
- The release should no longer be in draft state
125124
- JAR artifacts should be attached to the release

0 commit comments

Comments
 (0)