Skip to content

Commit 258718e

Browse files
committed
Use Git tags for version pinning with clean URLs
1 parent 93c0829 commit 258718e

File tree

5 files changed

+203
-116
lines changed

5 files changed

+203
-116
lines changed

.github/scripts/pin-version.sh

Lines changed: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,25 @@ Pin wire-server and all related charts to a specific version.
1717
OPTIONS:
1818
-v, --version VERSION Wire-server version to pin to (required)
1919
-f, --file FILE Path to build.json (default: build.json)
20-
-b, --branch BRANCH Git branch to push to (default: current branch)
20+
-b, --base-branch BRANCH Base branch to branch from (default: current branch)
2121
-h, --help Show this help message
2222
23+
DESCRIPTION:
24+
Creates a temporary branch with pinned build.json, tags it, and pushes the tag.
25+
The root build.json on the base branch remains unchanged.
26+
27+
Pins wire-server and related charts to the specified version.
28+
Creates a Git tag: pinned-<base-branch>-<version>
29+
30+
The tag name is output to stdout for use in workflows.
31+
2332
EXAMPLE:
2433
$0 --version 5.23.0
25-
$0 --version 5.23.0 --file path/to/build.json --branch offline
34+
# Creates tag: pinned-offline-5.23.0
35+
# URL: https://raw.githubusercontent.com/.../pinned-offline-5.23.0/build.json
36+
37+
$0 --version 5.23.0 --base-branch offline
38+
# Creates tag: pinned-offline-5.23.0
2639
2740
EOF
2841
exit 1
@@ -32,7 +45,7 @@ EOF
3245
parse_args() {
3346
PINNED_VERSION=""
3447
BUILD_FILE="build.json"
35-
GIT_BRANCH=""
48+
BASE_BRANCH=""
3649

3750
while [[ $# -gt 0 ]]; do
3851
case $1 in
@@ -44,8 +57,8 @@ parse_args() {
4457
BUILD_FILE="$2"
4558
shift 2
4659
;;
47-
-b|--branch)
48-
GIT_BRANCH="$2"
60+
-b|--base-branch)
61+
BASE_BRANCH="$2"
4962
shift 2
5063
;;
5164
-h|--help)
@@ -69,8 +82,8 @@ parse_args() {
6982
fi
7083

7184
# Get current branch if not specified
72-
if [ -z "$GIT_BRANCH" ]; then
73-
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
85+
if [ -z "$BASE_BRANCH" ]; then
86+
BASE_BRANCH=$(git rev-parse --abbrev-ref HEAD)
7487
fi
7588
}
7689

@@ -131,33 +144,72 @@ update_chart() {
131144
fi
132145
}
133146

134-
# Commit and push changes
147+
# Create temporary branch, commit pinned build.json, tag it, and push tag
135148
commit_and_push() {
136149
local current_version="$1"
137150
local pinned_version="$2"
138151
local charts="$3"
139-
local branch="$4"
152+
local base_branch="$4"
153+
local source_build_file="$5"
154+
155+
local temp_branch="temp-pin-${pinned_version}"
156+
local tag_name="pinned-${base_branch}-${pinned_version}"
140157

141-
log_info "Committing changes..."
158+
log_info "Creating temporary branch: $temp_branch"
142159

160+
# Ensure we're on base branch
161+
git checkout "$base_branch"
162+
163+
# Create temp branch
164+
git checkout -b "$temp_branch"
165+
166+
# Replace root build.json with pinned version
167+
cp "$source_build_file" build.json
168+
169+
log_info "Committing pinned build.json..."
143170
git_config_bot
144-
git add "$BUILD_FILE"
171+
git add build.json
145172

146173
# Build commit message
147174
cat > /tmp/pin-commit-msg.txt <<EOF
148175
Pin wire-server and related charts to $pinned_version
149176
150177
Charts updated from $current_version to $pinned_version:
151178
$charts
179+
180+
Base branch: $base_branch
181+
Tag: $tag_name
152182
EOF
153183

154184
git commit -F /tmp/pin-commit-msg.txt
155185
rm -f /tmp/pin-commit-msg.txt
156186

157-
log_info "Pushing to branch: $branch"
158-
git push origin "HEAD:refs/heads/$branch"
187+
local commit_sha
188+
commit_sha=$(git rev-parse HEAD)
189+
190+
log_info "Creating and pushing tag: $tag_name"
191+
192+
# Delete tag if it exists (for re-pinning same version)
193+
if git ls-remote --tags origin | grep -q "refs/tags/$tag_name"; then
194+
log_warning "Tag $tag_name already exists, deleting..."
195+
git push origin --delete "$tag_name" || true
196+
fi
197+
198+
# Create and push tag
199+
git tag "$tag_name" "$commit_sha"
200+
git push origin "$tag_name"
201+
202+
# Switch back to base branch and delete temp branch
203+
log_info "Cleaning up temporary branch"
204+
git checkout "$base_branch"
205+
git branch -D "$temp_branch"
159206

160207
log_success "Version pinning complete!"
208+
log_success "Tag: $tag_name"
209+
log_success "Commit SHA: $commit_sha"
210+
211+
# Output tag name (not commit SHA|path anymore)
212+
echo "$tag_name"
161213
}
162214

163215
# Main function
@@ -168,6 +220,12 @@ main() {
168220
log_info "Pinning wire-server and related charts to version $PINNED_VERSION"
169221
echo ""
170222

223+
# Create a temporary working file
224+
local temp_build_file="/tmp/build-pinned-$PINNED_VERSION.json"
225+
cp "$BUILD_FILE" "$temp_build_file"
226+
local original_build_file="$BUILD_FILE"
227+
BUILD_FILE="$temp_build_file"
228+
171229
# Get current wire-server version
172230
local current_version
173231
current_version=$(get_current_version)
@@ -205,8 +263,11 @@ main() {
205263
done
206264
echo ""
207265

208-
# Commit and push
209-
commit_and_push "$current_version" "$PINNED_VERSION" "$charts" "$GIT_BRANCH"
266+
# Commit and push (returns commit SHA and file path)
267+
commit_and_push "$current_version" "$PINNED_VERSION" "$charts" "$BASE_BRANCH" "$temp_build_file"
268+
269+
# Cleanup
270+
rm -f "$temp_build_file"
210271
}
211272

212273
# Run main function

.github/scripts/update-deploy-pr.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Usage: $0 [OPTIONS]
1919
Update wire-server-deploy repository with new wire-builds reference.
2020
2121
OPTIONS:
22-
-s, --sha SHA Wire-builds commit SHA (required)
22+
-r, --ref REF Git reference (commit SHA or tag name) (required)
2323
-d, --deploy-dir DIR Path to wire-server-deploy directory (required)
2424
-t, --token TOKEN GitHub token for creating PRs (required)
2525
-h, --help Show this help message
@@ -30,22 +30,23 @@ ENVIRONMENT:
3030
GITHUB_RUN_ID Workflow run ID (for PR body link)
3131
3232
EXAMPLE:
33-
$0 --sha abc123 --deploy-dir ./wire-server-deploy --token \$ZEBOT_TOKEN
33+
$0 --ref abc123 --deploy-dir ./wire-server-deploy --token \$ZEBOT_TOKEN
34+
$0 --ref pinned-offline-5.23.0 --deploy-dir ./wire-server-deploy --token \$ZEBOT_TOKEN
3435
3536
EOF
3637
exit 1
3738
}
3839

3940
# Parse command line arguments
4041
parse_args() {
41-
COMMIT_SHA=""
42+
BUILD_REF=""
4243
DEPLOY_DIR=""
4344
GITHUB_TOKEN=""
4445

4546
while [[ $# -gt 0 ]]; do
4647
case $1 in
47-
-s|--sha)
48-
COMMIT_SHA="$2"
48+
-r|--ref)
49+
BUILD_REF="$2"
4950
shift 2
5051
;;
5152
-d|--deploy-dir)
@@ -67,8 +68,8 @@ parse_args() {
6768
done
6869

6970
# Validate required arguments
70-
if [ -z "$COMMIT_SHA" ]; then
71-
log_error "Commit SHA is required"
71+
if [ -z "$BUILD_REF" ]; then
72+
log_error "Git reference is required"
7273
usage
7374
fi
7475

@@ -302,9 +303,9 @@ main() {
302303

303304
cd "$DEPLOY_DIR" || die "Failed to change to deploy directory"
304305

305-
local new_url="https://raw.githubusercontent.com/wireapp/wire-builds/$COMMIT_SHA/build.json"
306+
local new_url="https://raw.githubusercontent.com/wireapp/wire-builds/$BUILD_REF/build.json"
306307

307-
log_info "Updating wire-server-deploy with commit: $COMMIT_SHA"
308+
log_info "Updating wire-server-deploy with ref: $BUILD_REF"
308309
echo ""
309310

310311
# Check if update is needed

.github/workflows/create-deploy-pr.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,28 @@ jobs:
5353
fetch-depth: 0
5454

5555
- name: Pin wire-server version if specified
56+
id: pin-version
5657
if: ${{ inputs.wire_server_version != 'none' && inputs.wire_server_version != '' }}
5758
run: |
58-
.github/scripts/pin-version.sh \
59+
TAG_NAME=$(.github/scripts/pin-version.sh \
5960
--version "${{ inputs.wire_server_version }}" \
6061
--file build.json \
61-
--branch "${{ github.ref_name }}"
62+
--base-branch "${{ github.ref_name }}" | tail -1)
63+
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
64+
echo "Pinned tag: $TAG_NAME"
6265
63-
- name: Get current commit SHA
64-
id: get-sha
66+
- name: Get reference for build.json
67+
id: get-ref
6568
run: |
66-
COMMIT_SHA=$(git rev-parse HEAD)
67-
echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT
68-
echo "Current commit SHA: $COMMIT_SHA"
69+
# Use pinned tag if pinning was performed, otherwise use current HEAD
70+
if [ -n "${{ steps.pin-version.outputs.tag_name }}" ]; then
71+
BUILD_REF="${{ steps.pin-version.outputs.tag_name }}"
72+
echo "Using pinned tag: $BUILD_REF"
73+
else
74+
BUILD_REF=$(git rev-parse HEAD)
75+
echo "Using commit SHA: $BUILD_REF"
76+
fi
77+
echo "build_ref=$BUILD_REF" >> $GITHUB_OUTPUT
6978
7079
- name: Checkout wire-server-deploy
7180
uses: actions/checkout@v4
@@ -82,11 +91,11 @@ jobs:
8291
GITHUB_RUN_ID: ${{ github.run_id }}
8392
run: |
8493
.github/scripts/update-deploy-pr.sh \
85-
--sha "${{ steps.get-sha.outputs.commit_sha }}" \
94+
--ref "${{ steps.get-ref.outputs.build_ref }}" \
8695
--deploy-dir wire-server-deploy \
8796
--token "${{ secrets.ZEBOT_TOKEN || secrets.GITHUB_TOKEN }}"
8897
8998
- name: Summary
9099
run: |
91100
echo "✅ Workflow completed successfully"
92-
echo " Commit SHA: ${{ steps.get-sha.outputs.commit_sha }}"
101+
echo " Build reference: ${{ steps.get-ref.outputs.build_ref }}"

README.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,27 @@ gh run watch
3939
```
4040

4141
**How it works:**
42-
1. Workflow fetches the correct commit SHA from wire-server releases
43-
2. Updates all charts that match the current wire-server version to the pinned version
44-
3. Updates both version numbers and commit metadata
45-
4. Creates a new commit and pushes to the branch
46-
5. Triggers PR creation to wire-server-deploy
42+
1. Workflow creates a temporary branch from the base branch (e.g., `offline`)
43+
2. Fetches the correct commit SHA from wire-server releases
44+
3. Updates all charts that match the current wire-server version to the pinned version
45+
4. Modifies root `build.json` with pinned versions
46+
5. Commits the changes and creates a Git tag: `pinned-<branch>-<version>`
47+
6. Pushes the tag to remote and deletes the temporary branch
48+
7. Creates a PR to wire-server-deploy using the tag name
49+
50+
**Important:** The root `build.json` on the base branch (e.g., `offline`) remains unchanged at the latest version. Pinned versions are accessible via Git tags (e.g., `pinned-offline-5.23.0`) and referenced by clean URLs.
51+
52+
**Example after pinning to 5.23.0:**
53+
```
54+
offline branch: build.json at 5.24.0 (unchanged)
55+
Git tag: pinned-offline-5.23.0 → points to commit with build.json at 5.23.0
56+
URL: https://raw.githubusercontent.com/wireapp/wire-builds/pinned-offline-5.23.0/build.json
57+
58+
List all pinned versions:
59+
$ git tag -l 'pinned-offline-*'
60+
pinned-offline-5.23.0
61+
pinned-offline-5.22.0
62+
```
4763

4864
**Available versions:** 5.24.0 down to 5.5.0
4965

0 commit comments

Comments
 (0)