|
| 1 | +name: Manual Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_type: |
| 7 | + description: "Select the semantic version bump type" |
| 8 | + required: true |
| 9 | + default: patch |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - patch |
| 13 | + - minor |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + release: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Configure Git |
| 28 | + run: | |
| 29 | + git config user.name "github-actions[bot]" |
| 30 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 31 | +
|
| 32 | + - name: Determine next version |
| 33 | + id: bump |
| 34 | + run: | |
| 35 | + set -euo pipefail |
| 36 | +
|
| 37 | + RELEASE_TYPE="${{ github.event.inputs.release_type }}" |
| 38 | +
|
| 39 | + LATEST_TAG=$(git tag --sort=-v:refname | head -n 1) |
| 40 | + if [ -z "$LATEST_TAG" ]; then |
| 41 | + PREVIOUS_TAG="" |
| 42 | + BASE_VERSION=$(python - <<'PY' |
| 43 | +import re |
| 44 | +from pathlib import Path |
| 45 | +match = re.search(r"'version'\s*=>\s*'([^']+)'", Path("config/mcp-server.php").read_text()) |
| 46 | +print(match.group(1) if match else "") |
| 47 | +PY |
| 48 | +) |
| 49 | + if [ -z "$BASE_VERSION" ]; then |
| 50 | + BASE_VERSION="0.1.0" |
| 51 | + fi |
| 52 | + VERSION="$BASE_VERSION" |
| 53 | + else |
| 54 | + PREVIOUS_TAG="$LATEST_TAG" |
| 55 | + VERSION="${LATEST_TAG#v}" |
| 56 | + fi |
| 57 | + |
| 58 | + IFS='.' read -r MAJOR MINOR PATCH <<<"$VERSION" |
| 59 | + |
| 60 | + case "$RELEASE_TYPE" in |
| 61 | + minor) |
| 62 | + MINOR=$((MINOR + 1)) |
| 63 | + PATCH=0 |
| 64 | + ;; |
| 65 | + patch|*) |
| 66 | + PATCH=$((PATCH + 1)) |
| 67 | + ;; |
| 68 | + esac |
| 69 | + |
| 70 | + NEW_VERSION="$MAJOR.$MINOR.$PATCH" |
| 71 | + NEW_TAG="v$NEW_VERSION" |
| 72 | + |
| 73 | + { |
| 74 | + echo "version=$NEW_VERSION" |
| 75 | + echo "tag=$NEW_TAG" |
| 76 | + echo "previous_tag=$PREVIOUS_TAG" |
| 77 | + } >> "$GITHUB_OUTPUT" |
| 78 | + shell: bash |
| 79 | + |
| 80 | + - name: Update configuration version |
| 81 | + run: | |
| 82 | + python - <<'PY' |
| 83 | +import os |
| 84 | +import re |
| 85 | +from pathlib import Path |
| 86 | + |
| 87 | +version = os.environ["NEW_VERSION"] |
| 88 | +path = Path("config/mcp-server.php") |
| 89 | +content = path.read_text() |
| 90 | +updated, count = re.subn(r"'version'\s*=>\s*'[^']*'", f"'version' => '{version}'", content, count=1) |
| 91 | +if count == 0: |
| 92 | + raise SystemExit("Failed to update version in config/mcp-server.php") |
| 93 | +path.write_text(updated) |
| 94 | +PY |
| 95 | + env: |
| 96 | + NEW_VERSION: ${{ steps.bump.outputs.version }} |
| 97 | + |
| 98 | + - name: Commit version update |
| 99 | + run: | |
| 100 | + git add config/mcp-server.php |
| 101 | + if git diff --cached --quiet; then |
| 102 | + echo "No changes to commit." |
| 103 | + else |
| 104 | + git commit -m "chore: release ${{ steps.bump.outputs.tag }}" |
| 105 | + fi |
| 106 | +
|
| 107 | + - name: Push changes and tag |
| 108 | + env: |
| 109 | + NEW_TAG: ${{ steps.bump.outputs.tag }} |
| 110 | + run: | |
| 111 | + BRANCH="${GITHUB_REF_NAME}" |
| 112 | + git push origin "$BRANCH" |
| 113 | + if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then |
| 114 | + git tag -d "$NEW_TAG" |
| 115 | + fi |
| 116 | + git tag "$NEW_TAG" |
| 117 | + git push origin "$NEW_TAG" |
| 118 | +
|
| 119 | + - name: Generate release notes |
| 120 | + id: notes |
| 121 | + env: |
| 122 | + PREVIOUS_TAG: ${{ steps.bump.outputs.previous_tag }} |
| 123 | + NEW_TAG: ${{ steps.bump.outputs.tag }} |
| 124 | + run: | |
| 125 | + if [ -z "$PREVIOUS_TAG" ]; then |
| 126 | + NOTES=$(git log --pretty=format:"- %s") |
| 127 | + else |
| 128 | + NOTES=$(git log "$PREVIOUS_TAG"..HEAD --pretty=format:"- %s") |
| 129 | + fi |
| 130 | +
|
| 131 | + if [ -z "$NOTES" ]; then |
| 132 | + NOTES="- Release $NEW_TAG" |
| 133 | + fi |
| 134 | +
|
| 135 | + { |
| 136 | + echo "notes<<EOF" |
| 137 | + echo "$NOTES" |
| 138 | + echo "EOF" |
| 139 | + } >> "$GITHUB_OUTPUT" |
| 140 | +
|
| 141 | + - name: Create GitHub release |
| 142 | + uses: actions/create-release@v1 |
| 143 | + env: |
| 144 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 145 | + with: |
| 146 | + tag_name: ${{ steps.bump.outputs.tag }} |
| 147 | + release_name: ${{ steps.bump.outputs.tag }} |
| 148 | + body: ${{ steps.notes.outputs.notes }} |
| 149 | + draft: false |
| 150 | + prerelease: false |
0 commit comments