Skip to content

Commit 73b616e

Browse files
committed
use scripts to update version
1 parent 8cf9d71 commit 73b616e

File tree

2 files changed

+255
-34
lines changed

2 files changed

+255
-34
lines changed

.github/skills/prepare-release/SKILL.md

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ This skill automates the release preparation workflow for the [Azure App Configu
1111

1212
Use this skill when you need to:
1313
- Bump the package version for a new stable or preview release
14-
- Create merge PRs to sync branches (main → preview, main → release/stable, preview → release)
14+
- Create merge PRs to sync branches (test-main → test-preview, test-main → test-release/stable, test-preview → test-release)
1515
- Prepare all the PRs needed before publishing a new release
16-
- Resolve merge conflicts between main and preview branches
16+
- Resolve merge conflicts between test-main and test-preview branches
1717

1818
## Background
1919

@@ -22,10 +22,10 @@ Use this skill when you need to:
2222
- **Package Name**: `@azure/app-configuration-provider`
2323

2424
### Branch Structure
25-
- `main` – primary development branch for stable releases
26-
- `preview` – development branch for preview releases
27-
- `release/stable/v{major}` – release branch for stable versions (e.g., `release/stable/v2`)
28-
- `release/v{major}` – release branch for preview versions (e.g., `release/v2`)
25+
- `test-main` – primary development branch for stable releases
26+
- `test-preview` – development branch for preview releases
27+
- `test-release/stable/v{major}` – release branch for stable versions (e.g., `test-release/stable/v2`)
28+
- `test-release/v{major}` – release branch for preview versions (e.g., `test-release/v2`)
2929

3030
### Version Files
3131
The version must be updated in **all four locations** simultaneously:
@@ -48,26 +48,31 @@ Ask the user whether this is a **stable** or **preview** release, and what the *
4848

4949
#### Step 1: Version Bump PR
5050

51-
Create a version bump PR targeting `main`.
51+
Create a version bump PR targeting `test-main` by running the version bump script:
5252

53+
```bash
54+
./scripts/version-bump.sh <new_version>
55+
```
56+
57+
For example: `./scripts/version-bump.sh 2.5.0`
58+
59+
The script will automatically:
5360
1. Read the current version from `src/version.ts`.
54-
2. Create a new branch from `main` named `<username>/version-<new_version>` (e.g., `linglingye/version-2.4.0`).
55-
3. Update the version in all four files:
56-
- `src/version.ts` (line 4)
57-
- `package.json` (line 3)
58-
- `package-lock.json` (line 3 and line 9)
59-
4. Commit the changes with message: `version bump <new_version>`.
60-
5. Push the branch and create a PR to `main` with title: `Version bump <new_version>`.
61+
2. Create a new branch from `test-main` named `<username>/version-<new_version>` (e.g., `linglingye/version-2.5.0`).
62+
3. Update the version in all four files (`src/version.ts`, `package.json`, `package-lock.json` lines 3 and 9).
63+
4. Commit, push, and create a PR to `test-main` with title: `Version bump <new_version>`.
64+
65+
When the script prompts `Proceed? [y/N]`, confirm by entering `y`.
6166

6267
**Sample PR**: https://github.com/Azure/AppConfiguration-JavaScriptProvider/pull/277
6368

6469
#### Step 2: Merge Main to Release Branch
6570

66-
After the version bump PR is merged, create a PR to merge `main` into the stable release branch.
71+
After the version bump PR is merged, create a PR to merge `test-main` into the stable release branch.
6772

6873
1. Determine the major version from the new version string (e.g., `2` from `2.4.0`).
69-
2. Create a PR from `main``release/stable/v{major}` (e.g., `release/stable/v2`).
70-
3. Title the PR: `Merge main to release/stable/v{major}`.
74+
2. Create a PR from `test-main``test-release/stable/v{major}` (e.g., `test-release/stable/v2`).
75+
3. Title the PR: `Merge test-main to test-release/stable/v{major}`.
7176

7277
> **Important**: Use "Merge commit" (not squash) when merging this PR to preserve commit history.
7378
@@ -79,37 +84,42 @@ After the version bump PR is merged, create a PR to merge `main` into the stable
7984

8085
#### Step 1: Merge Main to Preview (Conflict Resolution)
8186

82-
Create a PR to merge `main` into `preview`. This will likely have conflicts.
87+
Create a PR to merge `test-main` into `test-preview`. This will likely have conflicts.
8388

84-
1. Fetch the latest `main` and `preview` branches.
85-
2. Create a new branch from `preview` named `<username>/resolve-conflict` (or similar).
86-
3. Merge `main` into this branch. If there are conflicts, inform the user and let them resolve manually.
87-
4. Push the branch and create a PR targeting `preview` with title: `Merge main to preview`.
89+
1. Fetch the latest `test-main` and `test-preview` branches.
90+
2. Create a new branch from `test-preview` named `<username>/resolve-conflict` (or similar).
91+
3. Merge `test-main` into this branch. If there are conflicts, inform the user and let them resolve manually.
92+
4. Push the branch and create a PR targeting `test-preview` with title: `Merge test-main to test-preview`.
8893

8994
> **Important**: Use "Merge commit" (not squash) when merging this PR.
9095
9196
**Sample PR**: https://github.com/Azure/AppConfiguration-JavaScriptProvider/pull/272
9297

9398
#### Step 2: Version Bump PR
9499

95-
After the merge-to-preview PR is merged, create a version bump PR targeting `preview`.
100+
After the merge-to-preview PR is merged, create a version bump PR targeting `test-preview` by running the version bump script with the `--preview` flag:
101+
102+
```bash
103+
./scripts/version-bump.sh <new_version> --preview
104+
```
105+
106+
For example: `./scripts/version-bump.sh 2.5.1-preview --preview`
107+
108+
The script will automatically:
109+
1. Read the current version from `src/version.ts` on the `test-preview` branch.
110+
2. Create a new branch from `test-preview` named `<username>/version-<new_version>` (e.g., `linglingye/version-2.5.1-preview`).
111+
3. Update the version in all four files (`src/version.ts`, `package.json`, `package-lock.json` lines 3 and 9).
112+
4. Commit, push, and create a PR to `test-preview` with title: `Version bump <new_version>`.
96113

97-
1. Read the current version from `src/version.ts` on the `preview` branch.
98-
2. Create a new branch from `preview` named `<username>/version-<new_version>` (e.g., `linglingye/version-2.4.1-preview`).
99-
3. Update the version in all four files:
100-
- `src/version.ts` (line 4)
101-
- `package.json` (line 3)
102-
- `package-lock.json` (line 3 and line 9)
103-
4. Commit the changes with message: `version bump <new_version>`.
104-
5. Push the branch and create a PR to `preview` with title: `Version bump <new_version>`.
114+
When the script prompts `Proceed? [y/N]`, confirm by entering `y`.
105115

106116
#### Step 3: Merge Preview to Release Branch
107117

108-
After the version bump PR is merged, create a PR to merge `preview` into the preview release branch.
118+
After the version bump PR is merged, create a PR to merge `test-preview` into the preview release branch.
109119

110120
1. Determine the major version from the new version string (e.g., `2` from `2.4.1-preview`).
111-
2. Create a PR from `preview``release/v{major}` (e.g., `release/v2`).
112-
3. Title the PR: `Merge preview to release/v{major}`.
121+
2. Create a PR from `test-preview``test-release/v{major}` (e.g., `test-release/v2`).
122+
3. Title the PR: `Merge test-preview to test-release/v{major}`.
113123

114124
> **Important**: Use "Merge commit" (not squash) when merging this PR.
115125

scripts/version-bump.sh

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
#!/bin/bash
2+
3+
# ============================================================================
4+
# version-bump.sh
5+
#
6+
# Automates the version bump workflow for @azure/app-configuration-provider.
7+
# Updates version in all required files, creates a branch, commits, pushes,
8+
# and opens a PR via the GitHub CLI (gh).
9+
#
10+
# Usage:
11+
# ./scripts/version-bump.sh <new_version> [--preview]
12+
#
13+
# Examples:
14+
# ./scripts/version-bump.sh 2.5.0 # stable release → PR to test-main
15+
# ./scripts/version-bump.sh 2.5.1-preview --preview # preview release → PR to test-preview
16+
#
17+
# Prerequisites:
18+
# - git, sed, and gh (GitHub CLI) must be installed and authenticated
19+
# ============================================================================
20+
21+
set -euo pipefail
22+
23+
# ── Helpers ──────────────────────────────────────────────────────────────────
24+
25+
usage() {
26+
cat <<EOF
27+
Usage: $(basename "$0") <new_version> [--preview]
28+
29+
Arguments:
30+
new_version The version to bump to (e.g. 2.5.0 or 2.5.1-preview)
31+
--preview Target the test-preview branch instead of test-main
32+
33+
Examples:
34+
$(basename "$0") 2.5.0 # stable → PR to test-main
35+
$(basename "$0") 2.5.1-preview --preview # preview → PR to test-preview
36+
EOF
37+
exit 1
38+
}
39+
40+
error() {
41+
echo "ERROR: $1" >&2
42+
exit 1
43+
}
44+
45+
info() {
46+
echo "── $1"
47+
}
48+
49+
# ── Parse arguments ──────────────────────────────────────────────────────────
50+
51+
NEW_VERSION=""
52+
IS_PREVIEW=false
53+
54+
while [[ $# -gt 0 ]]; do
55+
case "$1" in
56+
--preview)
57+
IS_PREVIEW=true
58+
shift
59+
;;
60+
-h|--help)
61+
usage
62+
;;
63+
*)
64+
if [[ -z "$NEW_VERSION" ]]; then
65+
NEW_VERSION="$1"
66+
else
67+
error "Unexpected argument: $1"
68+
fi
69+
shift
70+
;;
71+
esac
72+
done
73+
74+
[[ -z "$NEW_VERSION" ]] && usage
75+
76+
# Validate version format: major.minor.patch or major.minor.patch-preview
77+
if ! echo "$NEW_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-preview)?$'; then
78+
error "Invalid version format '$NEW_VERSION'. Expected: X.Y.Z or X.Y.Z-preview"
79+
fi
80+
81+
# If version ends with -preview, ensure --preview flag is set
82+
if echo "$NEW_VERSION" | grep -qE '\-preview$'; then
83+
if [[ "$IS_PREVIEW" == false ]]; then
84+
error "Version '$NEW_VERSION' looks like a preview version. Did you forget --preview?"
85+
fi
86+
fi
87+
88+
# ── Resolve paths & context ─────────────────────────────────────────────────
89+
90+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
91+
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
92+
93+
VERSION_TS="$PROJECT_DIR/src/version.ts"
94+
PACKAGE_JSON="$PROJECT_DIR/package.json"
95+
PACKAGE_LOCK="$PROJECT_DIR/package-lock.json"
96+
97+
# Determine target branch and branch prefix
98+
if [[ "$IS_PREVIEW" == true ]]; then
99+
TARGET_BRANCH="test-preview"
100+
else
101+
TARGET_BRANCH="test-main"
102+
fi
103+
104+
# Get git username for branch naming (e.g. "linglingye" from "linglingye/version-2.4.0")
105+
GIT_USERNAME=$(git config user.name 2>/dev/null || echo "")
106+
if [[ -z "$GIT_USERNAME" ]]; then
107+
error "Could not determine git user.name. Please set it with: git config user.name <name>"
108+
fi
109+
# Use the first token (lowercase, no spaces) as the branch prefix
110+
BRANCH_PREFIX=$(echo "$GIT_USERNAME" | awk '{print $1}' | tr '[:upper:]' '[:lower:]')
111+
112+
BRANCH_NAME="${BRANCH_PREFIX}/version-${NEW_VERSION}"
113+
114+
# ── Read current version ─────────────────────────────────────────────────────
115+
116+
CURRENT_VERSION=$(grep -oP 'VERSION = "\K[^"]+' "$VERSION_TS")
117+
info "Current version : $CURRENT_VERSION"
118+
info "New version : $NEW_VERSION"
119+
info "Target branch : $TARGET_BRANCH"
120+
info "New branch : $BRANCH_NAME"
121+
echo ""
122+
123+
if [[ "$CURRENT_VERSION" == "$NEW_VERSION" ]]; then
124+
error "Current version is already $NEW_VERSION. Nothing to do."
125+
fi
126+
127+
# ── Confirm with user ────────────────────────────────────────────────────────
128+
129+
read -rp "Proceed? [y/N] " confirm
130+
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
131+
echo "Aborted."
132+
exit 0
133+
fi
134+
135+
echo ""
136+
137+
# ── Create branch from target ────────────────────────────────────────────────
138+
139+
cd "$PROJECT_DIR"
140+
141+
info "Fetching latest $TARGET_BRANCH..."
142+
git fetch origin "$TARGET_BRANCH"
143+
144+
info "Creating branch '$BRANCH_NAME' from origin/$TARGET_BRANCH..."
145+
git checkout -b "$BRANCH_NAME" "origin/$TARGET_BRANCH"
146+
147+
# ── Update version in all files ──────────────────────────────────────────────
148+
149+
info "Updating src/version.ts..."
150+
sed -i "s/export const VERSION = \"$CURRENT_VERSION\"/export const VERSION = \"$NEW_VERSION\"/" "$VERSION_TS"
151+
152+
info "Updating package.json..."
153+
sed -i "0,/\"version\": \"$CURRENT_VERSION\"/s//\"version\": \"$NEW_VERSION\"/" "$PACKAGE_JSON"
154+
155+
info "Updating package-lock.json (line 3)..."
156+
# package-lock.json has the version on line 3 and line 9 — update both
157+
sed -i "0,/\"version\": \"$CURRENT_VERSION\"/s//\"version\": \"$NEW_VERSION\"/" "$PACKAGE_LOCK"
158+
159+
info "Updating package-lock.json (line 9)..."
160+
sed -i "0,/\"version\": \"$CURRENT_VERSION\"/s//\"version\": \"$NEW_VERSION\"/" "$PACKAGE_LOCK"
161+
162+
# ── Verify changes ──────────────────────────────────────────────────────────
163+
164+
info "Verifying updates..."
165+
166+
verify_version() {
167+
local file="$1"
168+
local expected="$2"
169+
if ! grep -q "\"$expected\"" "$file" 2>/dev/null && ! grep -q "\"$expected\"" "$file" 2>/dev/null; then
170+
error "Version not found in $file after update. Please check manually."
171+
fi
172+
}
173+
174+
# Check src/version.ts specifically
175+
if ! grep -q "export const VERSION = \"$NEW_VERSION\"" "$VERSION_TS"; then
176+
error "Version not updated in src/version.ts"
177+
fi
178+
verify_version "$PACKAGE_JSON" "$NEW_VERSION"
179+
verify_version "$PACKAGE_LOCK" "$NEW_VERSION"
180+
181+
info "All version files updated ✓"
182+
echo ""
183+
184+
# ── Commit, push, and create PR ─────────────────────────────────────────────
185+
186+
COMMIT_MSG="version bump $NEW_VERSION"
187+
188+
info "Committing changes..."
189+
git add "$VERSION_TS" "$PACKAGE_JSON" "$PACKAGE_LOCK"
190+
git commit -m "$COMMIT_MSG"
191+
192+
info "Pushing branch '$BRANCH_NAME'..."
193+
git push origin "$BRANCH_NAME"
194+
195+
info "Creating pull request..."
196+
PR_URL=$(gh pr create \
197+
--base "$TARGET_BRANCH" \
198+
--head "$BRANCH_NAME" \
199+
--title "Version bump $NEW_VERSION" \
200+
--body "Bump version from \`$CURRENT_VERSION\` to \`$NEW_VERSION\`.
201+
202+
### Changes
203+
- \`src/version.ts\` – updated VERSION constant
204+
- \`package.json\` – updated version field
205+
- \`package-lock.json\` – updated version fields (lines 3 and 9)
206+
207+
---
208+
*This PR was created automatically by \`scripts/version-bump.sh\`.*")
209+
210+
echo ""
211+
info "Done! PR created: $PR_URL"

0 commit comments

Comments
 (0)