Skip to content

Commit 46065bd

Browse files
committed
tip
1 parent 440d4b0 commit 46065bd

File tree

1 file changed

+48
-56
lines changed

1 file changed

+48
-56
lines changed

.github/workflows/manual-release.yml

Lines changed: 48 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ jobs:
2626
TITLE_INPUT="${{ inputs.title }}"
2727
2828
echo "Resolving draft release by title in $REPO_FULL_NAME..."
29+
30+
# Validate title format (should be vX.Y.Z where X.Y.Z is a semver version)
31+
if [[ ! "$TITLE_INPUT" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
32+
echo "::error::Invalid title format. Expected format: vX.Y.Z (e.g., v1.2.3)"
33+
echo "Title must be a semver version number prepended with 'v'."
34+
exit 1
35+
fi
36+
37+
echo "Title format validated: $TITLE_INPUT"
38+
39+
# Get the version number without the 'v' prefix
40+
VERSION="${TITLE_INPUT:1}"
2941
3042
# Find an existing draft release by exact title match
3143
if gh api \
@@ -87,8 +99,9 @@ jobs:
8799
echo "target_commitish=$TARGET_COMMITISH" >> "$GITHUB_OUTPUT"
88100
echo "body=$BODY" >> "$GITHUB_OUTPUT"
89101
echo "draft=$DRAFT" >> "$GITHUB_OUTPUT"
102+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
90103
91-
echo "Resolved: tag=$TAG_NAME, name=$NAME, target_commitish=$TARGET_COMMITISH, draft=$DRAFT"
104+
echo "Resolved: tag=$TAG_NAME, name=$NAME, target_commitish=$TARGET_COMMITISH, draft=$DRAFT version=$VERSION"
92105
93106
- name: Manual dispatch triggered
94107
run: |
@@ -132,12 +145,12 @@ jobs:
132145
133146
- name: Run Maven release:prepare
134147
run: |
135-
VERSION="${{ steps.validate_tag.outputs.version }}"
136-
TAG_NAME="${{ github.event.release.tag_name }}"
137-
148+
VERSION="${{ steps.release.outputs.version }}"
149+
TAG_NAME="${{ steps.release.outputs.tag_name }}"
150+
138151
echo "Preparing release version: $VERSION"
139152
echo "Tag name: $TAG_NAME"
140-
153+
141154
# Run release:prepare with explicit release version
142155
# Maven will automatically calculate the next development version
143156
# Only prepare production modules, exclude all sample modules
@@ -170,8 +183,8 @@ jobs:
170183

171184
- name: Push changes to originating branch
172185
run: |
173-
TARGET_BRANCH="${{ steps.target_branch.outputs.target_branch }}"
174-
TAG_NAME="${{ github.event.release.tag_name }}"
186+
TARGET_BRANCH="${{ steps.release.outputs.target_commitish }}"
187+
TAG_NAME="${{ steps.release.outputs.tag_name }}"
175188
176189
echo "Pushing changes to branch: $TARGET_BRANCH"
177190
@@ -188,56 +201,8 @@ jobs:
188201
git push origin "$TAG_NAME"
189202
190203
echo "Pushed release commits and tag to $TARGET_BRANCH"
191-
# This step updates the changelog and commits changes.
192-
# In a Maven environment, you might run `mvn release:prepare` here.
193-
# In an npm environment, you might run `npm version` or use semantic-release.
194-
# For other build systems, integrate their release tooling at this stage.
195204
env:
196205
GH_TOKEN: ${{ steps.app-token.outputs.token }}
197-
run: |
198-
set -euo pipefail # Exit on error, undefined vars, and pipeline failures
199-
200-
REPO_FULL_NAME="${{ github.repository }}"
201-
TAG="${{ steps.release.outputs.tag_name }}"
202-
RELEASE_NAME="${{ steps.release.outputs.name }}"
203-
BODY_TEXT_RAW="${{ steps.release.outputs.body }}"
204-
205-
echo "Repository: $REPO_FULL_NAME"
206-
echo "Tag: $TAG"
207-
echo "Release name: $RELEASE_NAME"
208-
209-
# Ensure git safe directory & committer identity (github-actions[bot])
210-
git config --global --add safe.directory "$GITHUB_WORKSPACE" || true
211-
git config user.name "github-actions[bot]"
212-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
213-
214-
# Ensure CHANGELOG.md exists
215-
if [ ! -f CHANGELOG.md ]; then
216-
echo "CHANGELOG.md not found — creating with heading"
217-
printf "%s\n\n" "# Changelog" > CHANGELOG.md
218-
git add CHANGELOG.md
219-
git commit -m "chore(changelog): add CHANGELOG.md"
220-
fi
221-
222-
# Build changelog entry. Use the raw body but ensure it's not 'null'
223-
if [ "$BODY_TEXT_RAW" = "null" ] || [ -z "$BODY_TEXT_RAW" ]; then
224-
BODY_TEXT="No release notes provided."
225-
else
226-
BODY_TEXT="$BODY_TEXT_RAW"
227-
fi
228-
229-
ENTRY_TMP="$(mktemp)"
230-
printf "## %s - %s - %s\n\n%s\n\n" "$TAG" "$RELEASE_NAME" "$BODY_TEXT" > "$ENTRY_TMP"
231-
# Prepend: write entry then existing file
232-
cat CHANGELOG.md >> "$ENTRY_TMP"
233-
mv "$ENTRY_TMP" CHANGELOG.md
234-
235-
git add CHANGELOG.md
236-
# Always commit; this workflow prepends a new entry for each draft release
237-
git commit -m "chore(release): add changelog entry for $TAG"
238-
239-
echo "Pushing commit..."
240-
git push origin HEAD
241206

242207
- name: Upload artifacts to draft release
243208
env:
@@ -292,4 +257,31 @@ jobs:
292257
293258
echo "Draft release updated successfully!"
294259
echo "Review the release and publish when ready at:"
295-
echo "https://github.com/$REPO_FULL_NAME/releases/tag/$TAG"
260+
echo "https://github.com/$REPO_FULL_NAME/releases/tag/$TAG"
261+
262+
- name: Publish GitHub release
263+
env:
264+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
265+
run: |
266+
set -euo pipefail
267+
268+
REPO_FULL_NAME="${{ github.repository }}"
269+
TAG="${{ steps.release.outputs.tag_name }}"
270+
VERSION="${{ steps.release.outputs.version }}"
271+
272+
echo "Publishing GitHub release for $TAG..."
273+
274+
# Publish the release (remove draft status)
275+
gh release edit "$TAG" --repo "$REPO_FULL_NAME" --draft=false
276+
277+
echo "✅ Release $VERSION published successfully!"
278+
echo "View at: https://github.com/$REPO_FULL_NAME/releases/tag/$TAG"
279+
280+
- name: Workflow Summary
281+
if: always()
282+
run: |
283+
echo "## Draft Release Workflow Summary" >> $GITHUB_STEP_SUMMARY
284+
echo "**Version:** ${{ steps.release.outputs.version }}" >> $GITHUB_STEP_SUMMARY
285+
echo "**Tag:** ${{ steps.release.outputs.tag_name }}" >> $GITHUB_STEP_SUMMARY
286+
echo "**Branch:** ${{ steps.release.outputs.target_commitish }}" >> $GITHUB_STEP_SUMMARY
287+
echo "**Status:** ${{ job.status }}" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)