|
| 1 | +name: Bump Version |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version_bump: |
| 7 | + description: "Version bump type" |
| 8 | + type: choice |
| 9 | + options: |
| 10 | + - patch |
| 11 | + - minor |
| 12 | + - major |
| 13 | + default: patch |
| 14 | + required: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + bump: |
| 18 | + name: "Bump version and tag" |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: write |
| 22 | + steps: |
| 23 | + - name: Checkout repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Compute new version |
| 29 | + id: compute |
| 30 | + shell: bash |
| 31 | + run: | |
| 32 | + set -euo pipefail |
| 33 | + BUMP="${{ inputs.version_bump }}" |
| 34 | + CURRENT_VERSION=$(jq -r '.version' "UnityMcpBridge/package.json") |
| 35 | + echo "Current version: $CURRENT_VERSION" |
| 36 | +
|
| 37 | + IFS='.' read -r MA MI PA <<< "$CURRENT_VERSION" |
| 38 | + case "$BUMP" in |
| 39 | + major) |
| 40 | + ((MA+=1)); MI=0; PA=0 |
| 41 | + ;; |
| 42 | + minor) |
| 43 | + ((MI+=1)); PA=0 |
| 44 | + ;; |
| 45 | + patch) |
| 46 | + ((PA+=1)) |
| 47 | + ;; |
| 48 | + *) |
| 49 | + echo "Unknown version_bump: $BUMP" >&2 |
| 50 | + exit 1 |
| 51 | + ;; |
| 52 | + esac |
| 53 | +
|
| 54 | + NEW_VERSION="$MA.$MI.$PA" |
| 55 | + echo "New version: $NEW_VERSION" |
| 56 | + echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 57 | + echo "current_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" |
| 58 | +
|
| 59 | + - name: Update files to new version |
| 60 | + env: |
| 61 | + NEW_VERSION: ${{ steps.compute.outputs.new_version }} |
| 62 | + shell: bash |
| 63 | + run: | |
| 64 | + set -euo pipefail |
| 65 | +
|
| 66 | + echo "Updating UnityMcpBridge/package.json to $NEW_VERSION" |
| 67 | + jq ".version = \"${NEW_VERSION}\"" UnityMcpBridge/package.json > UnityMcpBridge/package.json.tmp |
| 68 | + mv UnityMcpBridge/package.json.tmp UnityMcpBridge/package.json |
| 69 | +
|
| 70 | + echo "Updating UnityMcpBridge/UnityMcpServer~/src/pyproject.toml to $NEW_VERSION" |
| 71 | + sed -i '0,/^version = ".*"/s//version = "'"$NEW_VERSION"'"/' "UnityMcpBridge/UnityMcpServer~/src/pyproject.toml" |
| 72 | +
|
| 73 | + - name: Commit and push changes |
| 74 | + env: |
| 75 | + NEW_VERSION: ${{ steps.compute.outputs.new_version }} |
| 76 | + shell: bash |
| 77 | + run: | |
| 78 | + set -euo pipefail |
| 79 | + git config user.name "GitHub Actions" |
| 80 | + git config user.email "[email protected]" |
| 81 | + git add UnityMcpBridge/package.json "UnityMcpBridge/UnityMcpServer~/src/pyproject.toml" |
| 82 | + if git diff --cached --quiet; then |
| 83 | + echo "No version changes to commit." |
| 84 | + else |
| 85 | + git commit -m "chore: bump version to ${NEW_VERSION}" |
| 86 | + fi |
| 87 | +
|
| 88 | + BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" |
| 89 | + echo "Pushing to branch: $BRANCH" |
| 90 | + git push origin "$BRANCH" |
| 91 | +
|
| 92 | + - name: Create and push tag |
| 93 | + env: |
| 94 | + NEW_VERSION: ${{ steps.compute.outputs.new_version }} |
| 95 | + shell: bash |
| 96 | + run: | |
| 97 | + set -euo pipefail |
| 98 | + TAG="v${NEW_VERSION}" |
| 99 | + echo "Preparing to create tag $TAG" |
| 100 | +
|
| 101 | + if git ls-remote --tags origin | grep -q "refs/tags/$TAG$"; then |
| 102 | + echo "Tag $TAG already exists on remote. Skipping tag creation." |
| 103 | + exit 0 |
| 104 | + fi |
| 105 | +
|
| 106 | + git tag -a "$TAG" -m "Version ${NEW_VERSION}" |
| 107 | + git push origin "$TAG" |
0 commit comments