|
| 1 | +name: Manual Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version_bump: |
| 7 | + description: 'Version bump type' |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - patch |
| 12 | + - minor |
| 13 | + - major |
| 14 | + |
| 15 | +jobs: |
| 16 | + release: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Configure Git |
| 26 | + run: | |
| 27 | + git config user.name "github-actions[bot]" |
| 28 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 29 | +
|
| 30 | + - name: Validate changelog has unreleased content |
| 31 | + run: | |
| 32 | + # Extract content between [Unreleased] and next ## [ |
| 33 | + UNRELEASED_CONTENT=$(sed -n '/^## \[Unreleased\]/,/^## \[/p' CHANGELOG.md | sed '1d;$d' | sed '/^$/d') |
| 34 | +
|
| 35 | + if [ -z "$UNRELEASED_CONTENT" ]; then |
| 36 | + echo "Error: No content in [Unreleased] section. Nothing to release." |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | +
|
| 40 | + echo "Found unreleased content:" |
| 41 | + echo "$UNRELEASED_CONTENT" |
| 42 | +
|
| 43 | + - name: Calculate new version |
| 44 | + id: version |
| 45 | + env: |
| 46 | + VERSION_BUMP: ${{ inputs.version_bump }} |
| 47 | + run: | |
| 48 | + PLUGIN_JSON=".claude-plugin/plugin.json" |
| 49 | + CURRENT_VERSION=$(jq -r '.version' "$PLUGIN_JSON") |
| 50 | +
|
| 51 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" |
| 52 | +
|
| 53 | + case "$VERSION_BUMP" in |
| 54 | + major) |
| 55 | + NEW_VERSION="$((MAJOR + 1)).0.0" |
| 56 | + ;; |
| 57 | + minor) |
| 58 | + NEW_VERSION="$MAJOR.$((MINOR + 1)).0" |
| 59 | + ;; |
| 60 | + patch) |
| 61 | + NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))" |
| 62 | + ;; |
| 63 | + esac |
| 64 | +
|
| 65 | + echo "Current version: $CURRENT_VERSION" |
| 66 | + echo "New version: $NEW_VERSION" |
| 67 | + echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 68 | + echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 69 | +
|
| 70 | + - name: Extract release notes from changelog |
| 71 | + run: | |
| 72 | + # Extract content between [Unreleased] and next ## [ heading |
| 73 | + # Remove the first line ([Unreleased]) and last line (next version header) |
| 74 | + RELEASE_NOTES=$(sed -n '/^## \[Unreleased\]/,/^## \[/p' CHANGELOG.md | sed '1d;$d') |
| 75 | +
|
| 76 | + # Write to file for use in release (handles multiline properly) |
| 77 | + echo "$RELEASE_NOTES" > release_notes.md |
| 78 | +
|
| 79 | + echo "Release notes extracted:" |
| 80 | + cat release_notes.md |
| 81 | +
|
| 82 | + - name: Update CHANGELOG.md |
| 83 | + env: |
| 84 | + NEW_VERSION: ${{ steps.version.outputs.new }} |
| 85 | + CURRENT_VERSION: ${{ steps.version.outputs.current }} |
| 86 | + run: | |
| 87 | + TODAY=$(date +%Y-%m-%d) |
| 88 | +
|
| 89 | + # Replace [Unreleased] with new version, and add new [Unreleased] section |
| 90 | + sed -i "s/^## \[Unreleased\]$/## [Unreleased]\n\n## [$NEW_VERSION] - $TODAY/" CHANGELOG.md |
| 91 | +
|
| 92 | + # Update the comparison links at the bottom |
| 93 | + # Change: [Unreleased]: .../compare/vX.Y.Z...HEAD |
| 94 | + # To: [Unreleased]: .../compare/vNEW...HEAD |
| 95 | + sed -i "s|\[Unreleased\]: \(.*\)/compare/v${CURRENT_VERSION}\.\.\.HEAD|[Unreleased]: \1/compare/v${NEW_VERSION}...HEAD|" CHANGELOG.md |
| 96 | +
|
| 97 | + # Add new version link after [Unreleased] link |
| 98 | + # Find the [Unreleased] link line and add new version link after it |
| 99 | + sed -i "/^\[Unreleased\]:.*HEAD$/a [$NEW_VERSION]: https://github.com/itk-dev/itkdev-claude-plugins/compare/v${CURRENT_VERSION}...v${NEW_VERSION}" CHANGELOG.md |
| 100 | +
|
| 101 | + echo "Updated CHANGELOG.md:" |
| 102 | + head -30 CHANGELOG.md |
| 103 | + echo "..." |
| 104 | + tail -10 CHANGELOG.md |
| 105 | +
|
| 106 | + - name: Update plugin.json |
| 107 | + env: |
| 108 | + NEW_VERSION: ${{ steps.version.outputs.new }} |
| 109 | + run: | |
| 110 | + PLUGIN_JSON=".claude-plugin/plugin.json" |
| 111 | + jq --arg v "$NEW_VERSION" '.version = $v' "$PLUGIN_JSON" > tmp.json && mv tmp.json "$PLUGIN_JSON" |
| 112 | +
|
| 113 | + echo "Updated plugin.json:" |
| 114 | + cat "$PLUGIN_JSON" |
| 115 | +
|
| 116 | + - name: Commit changes |
| 117 | + env: |
| 118 | + NEW_VERSION: ${{ steps.version.outputs.new }} |
| 119 | + run: | |
| 120 | + git add CHANGELOG.md .claude-plugin/plugin.json |
| 121 | + git commit -m "chore: prepare release v${NEW_VERSION}" |
| 122 | +
|
| 123 | + - name: Create and push tag |
| 124 | + env: |
| 125 | + NEW_VERSION: ${{ steps.version.outputs.new }} |
| 126 | + run: | |
| 127 | + TAG="v${NEW_VERSION}" |
| 128 | + git tag -a "$TAG" -m "Release $TAG" |
| 129 | + git push origin main |
| 130 | + git push origin "$TAG" |
| 131 | +
|
| 132 | + - name: Create GitHub Release |
| 133 | + env: |
| 134 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 135 | + NEW_VERSION: ${{ steps.version.outputs.new }} |
| 136 | + CURRENT_VERSION: ${{ steps.version.outputs.current }} |
| 137 | + run: | |
| 138 | + TAG="v${NEW_VERSION}" |
| 139 | +
|
| 140 | + # Build release notes with header and footer |
| 141 | + { |
| 142 | + echo "## What's Changed" |
| 143 | + echo "" |
| 144 | + cat release_notes.md |
| 145 | + echo "" |
| 146 | + echo "## Full Changelog" |
| 147 | + echo "https://github.com/itk-dev/itkdev-claude-plugins/compare/v${CURRENT_VERSION}...v${NEW_VERSION}" |
| 148 | + } > full_release_notes.md |
| 149 | +
|
| 150 | + gh release create "$TAG" \ |
| 151 | + --title "Release $TAG" \ |
| 152 | + --notes-file full_release_notes.md |
| 153 | +
|
| 154 | + echo "Created release: $TAG" |
0 commit comments