@adobe/helix-rum-enhancer 2.52.0 → 2.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- de72a4e7c08710c96ce438adbb7f8427
1
+ 5f62ddfa2647a92537285bb1c720b14d
@@ -1 +1 @@
1
- a94090bf02d5ff1de6a2a9db59ccd856
1
+ 68f53ad99fa62d5d658dec89dfd74eb3
@@ -1 +1 @@
1
- ffe06266f271e876a25169b3b9aeb664
1
+ 3291aa601c680ea4861a85e80dc040fc
@@ -1 +1 @@
1
- 45ad84da9a52be26ad626cace1b57c9f
1
+ f647254ec5d96f56a80d692355d9be45
@@ -1 +1 @@
1
- 20d1f82b8a8c89e965f951484f200f35
1
+ b73d0b73e74eb654c0023e187d273701
@@ -1 +1 @@
1
- 472744eb0ece4d83f5df8812be5cee8d
1
+ ecbd640c744ed565255f2b9e212515fb
@@ -0,0 +1,2 @@
1
+ var webVitals=function(t){"use strict";let n=-1;const e=()=>n,i=t=>{addEventListener("pageshow",e=>{e.persisted&&(n=e.timeStamp,t(e))},!0)},o=(t,n,e,i)=>{let o,s;return a=>{n.value>=0&&(a||i)&&(s=n.value-(o??0),(s||void 0===o)&&(o=n.value,n.delta=s,n.rating=((t,n)=>t>n[1]?"poor":t>n[0]?"needs-improvement":"good")(n.value,e),t(n)))}},s=t=>{requestAnimationFrame(()=>requestAnimationFrame(()=>t()))},a=()=>{const t=performance.getEntriesByType("navigation")[0];if(t&&t.responseStart>0&&t.responseStart<performance.now())return t},r=()=>a()?.activationStart??0;let c=-1;const f=new Set,h=()=>"hidden"!==document.visibilityState||document.prerendering?1/0:0,d=t=>{if("hidden"===document.visibilityState){if("visibilitychange"===t.type)for(const t of f)t();isFinite(c)||(c="visibilitychange"===t.type?t.timeStamp:0,removeEventListener("prerenderingchange",d,!0))}},l=(t=!1)=>{if(t&&(c=1/0),c<0){const t=r(),n=document.prerendering?void 0:globalThis.performance.getEntriesByType("visibility-state").find(n=>"hidden"===n.name&&n.startTime>=t)?.startTime;c=n??h(),addEventListener("visibilitychange",d,!0),addEventListener("prerenderingchange",d,!0),i(()=>{setTimeout(()=>{c=h()})})}return{get firstHiddenTime(){return c},onHidden(t){f.add(t)}}},g=(t,n=-1,i,o=0,s,c,f)=>{const h=a(),d=h?.navigationId||0;let l="navigate";i?l=i:e()>=0?l="back-forward-cache":h&&(document.prerendering||r()>0?l="prerender":document.wasDiscarded?l="restore":h.type&&(l=h.type.replace(/_/g,"-")));return{name:t,value:n,rating:"good",delta:0,entries:[],id:`v6-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:l,navigationId:o||d,navigationInteractionId:s,navigationURL:c||h?.name,navigationStartTime:f||0}},u=new WeakMap;function v(t,n){let e=u.get(n);return e||(e=new WeakMap,u.set(n,e)),e.get(t)||e.set(t,new n),e.get(t)}class m{t;i=0;o=[];h(t){if(t.hadRecentInput)return;const n=this.o[0],e=this.o.at(-1);this.i&&n&&e&&t.startTime-e.startTime<1e3&&t.startTime-n.startTime<5e3?(this.i+=t.value,this.o.push(t)):(this.i=t.value,this.o=[t]),this.t?.(t)}}const p=(t,n,e={})=>{try{const i=t.filter(t=>PerformanceObserver.supportedEntryTypes.includes(t));if(i.length>0){const t=new PerformanceObserver(t=>{queueMicrotask(()=>{const e=t.getEntries();i.length>1&&e.sort((t,n)=>t.startTime+t.duration-(n.startTime+n.duration)),n(e)})});for(const n of i)t.observe({type:n,buffered:!0,...e});return t}}catch{}},b=t=>globalThis.PerformanceObserver?.supportedEntryTypes?.includes("soft-navigation")&&"function"==typeof globalThis.PerformanceSoftNavigation?.prototype?.getLargestInteractionContentfulPaint&&t&&t.reportSoftNavs,T=(t,n)=>{if(t.set(n.navigationId,n),t.size>2){const n=t.keys().next().value;void 0!==n&&t.delete(n)}},y=t=>{let n=!1;return()=>{n||(t(),n=!0)}};class _{l}const E=t=>{document.prerendering?addEventListener("prerenderingchange",t,!0):t()},M=[1800,3e3],L=(t,n={})=>{const a=b(n);E(()=>{const c=v(n,_),f=l();let h,d=g("FCP");const u=p(["paint"],t=>{for(const n of t)"first-contentful-paint"===n.name&&(u.disconnect(),n.startTime<f.firstHiddenTime&&(d.value=Math.max(n.startTime-r(),0),d.entries.push(n),d.navigationId=n.navigationId||d.navigationId,h(!0)))});if(u&&(h=o(t,d,M,n.reportAllChanges),i(i=>{d=g("FCP",-1,"back-forward-cache",d.navigationId,d.navigationInteractionId,d.navigationURL,e()),h=o(t,d,M,n.reportAllChanges),s(()=>{d.value=performance.now()-i.timeStamp,h(!0)})})),a){p(["soft-navigation"],e=>{e.forEach(e=>{c.l&&e.navigationId&&T(c.l,e);const i=Math.max((e.presentationTime||e.paintTime||0)-e.startTime,0);d=g("FCP",i,"soft-navigation",e.navigationId,e.interactionId,e.name,e.startTime),h=o(t,d,M,n.reportAllChanges),h(!0)})},n)}})},w=[.1,.25];let P=0,I=1/0,k=0;const C=t=>{for(const n of t)n.interactionId&&(I=Math.min(I,n.interactionId),k=Math.max(k,n.interactionId),P=k?(k-I)/7+1:0)};let F;const N=()=>F?P:performance.interactionCount??0,B=()=>{"interactionCount"in performance||F||(F=p(["event"],C,{durationThreshold:0}))};class S{u=0;v=[];m=new Map;p;T;_(){return N()-this.u}M(){this.u=N(),this.v.length=0,this.m.clear()}L(t){const n=this._(),e=Math.min(this.v.length-1,Math.floor(n/50));return!n||-1!==e||"soft-navigation"!==t&&"back-forward-cache"!==t?this.v[e]:{P:8,id:-1,entries:[]}}h(t){if(this.p?.(t),!t.interactionId)return;const n=this.v.at(-1);let e=this.m.get(t.interactionId);if(e||this.v.length<10||t.duration>n.P){if(e?t.duration>e.P?(e.entries=[t],e.P=t.duration):t.duration===e.P&&t.startTime===e.entries[0].startTime&&e.entries.push(t):(e={id:t.interactionId,entries:[t],P:t.duration},this.m.set(e.id,e),this.v.push(e)),this.v.sort((t,n)=>n.P-t.P),this.v.length>10){const t=this.v.splice(10);for(const n of t)this.m.delete(n.id)}this.T?.(e)}}}const q=t=>{const n="requestIdleCallback"in globalThis?1e3:0,e=globalThis.requestIdleCallback||setTimeout,i=globalThis.cancelIdleCallback||clearTimeout;if("hidden"===document.visibilityState)t();else{const o=y(t);let s=-1;const a=()=>{i(s),o()};addEventListener("visibilitychange",a,{once:!0,capture:!0}),s=e(()=>{removeEventListener("visibilitychange",a,{capture:!0}),o()},{timeout:n})}},A=[200,500];class H{p;l;h(t){this.p?.(t)}}const O=[2500,4e3],U=[800,1800],V=t=>{document.prerendering?E(()=>V(t)):"complete"!==document.readyState?addEventListener("load",()=>V(t),!0):setTimeout(t)};return t.CLSThresholds=w,t.FCPThresholds=M,t.INPThresholds=A,t.LCPThresholds=O,t.TTFBThresholds=U,t.onCLS=(t,n={})=>{const a=l();L(y(()=>{let r,c=g("CLS",0);const f=v(n,m),h=(e,i,s,a,h)=>{c=g("CLS",0,e,i,s,a,h),f.i=0,r=o(t,c,w,n.reportAllChanges)},d=(t=!1)=>{f.i>c.value&&(c.value=f.i,c.entries=f.o),r(t)},l=t=>{d(!0),h("soft-navigation",t.navigationId,t.interactionId,t.name,t.startTime)},u=t=>{for(const n of t)"soft-navigation"!==n.entryType?f.h(n):l(n);d()},T=["layout-shift"];b(n)&&T.push("soft-navigation");const y=p(T,u);y&&(r=o(t,c,w,n.reportAllChanges),a.onHidden(()=>{u(y.takeRecords()),r(!0)}),i(()=>{h("back-forward-cache",c.navigationId,c.navigationInteractionId,c.navigationURL,e()),s(r)}),setTimeout(r))}))},t.onFCP=L,t.onINP=(t,n={})=>{if(!globalThis.PerformanceEventTiming||!("interactionId"in PerformanceEventTiming.prototype))return;const s=l();E(()=>{B();let a,r=g("INP");const c=v(n,S),f=(e,i,s,f,h)=>{c.M(),r=g("INP",-1,e,i,s,f,h),a=o(t,r,A,n.reportAllChanges)},h=()=>{const t=c.L(r.navigationType);t&&t.P!==r.value&&(r.value=t.P,r.entries=t.entries,a())},d=t=>{h(),a(!0),f("soft-navigation",t.navigationId,t.interactionId,t.name,t.startTime)},l=(t,n=!1)=>{q(()=>{for(const n of t)"soft-navigation"!==n.entryType?c.h(n):d(n);h(),n&&a(!0)})},u=["event","first-input"];b(n)&&u.push("soft-navigation");const m=p(u,l,{...n,durationThreshold:n.durationThreshold??40});a=o(t,r,A,n.reportAllChanges),m&&(s.onHidden(()=>{l(m.takeRecords(),!0)}),i(()=>{f("back-forward-cache",r.navigationId,r.navigationInteractionId,r.navigationURL,e())}))})},t.onLCP=(t,n={})=>{let a=!1;const c=b(n);E(()=>{let f,h=l(),d=g("LCP");const u=v(n,H),m=(e,i,s,r,c)=>{d=g("LCP",-1,e,i,s,r,c),f=o(t,d,O,n.reportAllChanges),a=!1,"soft-navigation"===e&&(h=l(!0))},b=t=>{u.l&&t.navigationId&&T(u.l,t),a||f(!0),m("soft-navigation",t.navigationId,t.interactionId,t.name,t.startTime);const n=t.getLargestInteractionContentfulPaint?.();n&&y([n])},y=t=>{n.reportAllChanges||c||(t=t.slice(-1));for(const n of t){if(!n)continue;if("soft-navigation"===n.entryType){b(n);continue}let t=0,e=[],i=n.startTime;if("largest-contentful-paint"===n.entryType)t=Math.max(n.startTime-r(),0),u.h(n),e=[n];else if("interaction-contentful-paint"===n.entryType){const o=n;if(!d.navigationId)continue;if("interactionId"in o&&o.interactionId!=d.navigationInteractionId)continue;i=o.largestContentfulPaint?.renderTime||0,t=Math.max(i-n.startTime,0),o.largestContentfulPaint&&(u.h(o.largestContentfulPaint),e=[o.largestContentfulPaint])}i<h.firstHiddenTime&&(d.value=t,d.entries=e,f())}},_=["largest-contentful-paint"];c&&_.push("interaction-contentful-paint","soft-navigation");const E=p(_,y);if(E){f=o(t,d,O,n.reportAllChanges);const r=["keydown","click","visibilitychange"],h=t=>{if(t.isTrusted&&!a){const t=d.id;q(()=>{if(!a){if(!c){E.disconnect();for(const t of r)removeEventListener(t,h,{capture:!0})}t===d.id&&(a=!0,f(!0))}})}};for(const t of r)addEventListener(t,h,{capture:!0});i(i=>{m("back-forward-cache",d.navigationId,d.navigationInteractionId,d.navigationURL,e()),f=o(t,d,O,n.reportAllChanges),s(()=>{d.value=performance.now()-i.timeStamp,a=!0,f(!0)})})}})},t.onTTFB=(t,n={})=>{const s=b(n);let c=g("TTFB"),f=o(t,c,U,n.reportAllChanges);V(()=>{const h=a();if(h){const a=h.responseStart;if(c.value=Math.max(a-r(),0),c.entries=[h],f(!0),i(()=>{c=g("TTFB",0,"back-forward-cache",c.navigationId,c.navigationInteractionId,c.navigationURL,e()),f=o(t,c,U,n.reportAllChanges),f(!0)}),s){p(["soft-navigation"],e=>{e.forEach(e=>{e.navigationId&&(c=g("TTFB",0,"soft-navigation",e.navigationId,e.interactionId,e.name,e.startTime),c.entries=[e],f=o(t,c,U,n.reportAllChanges),f(!0))})},n)}}})},t}({});
2
+ //# sourceMappingURL=web-vitals.iife.js.map
package/tagger.sh CHANGED
@@ -1,173 +1,165 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
+ # Publish generated release branches without committing to or checking out source branches.
3
+ set -euo pipefail
2
4
 
3
- # Check if at least one argument is provided
4
- if [ $# -lt 1 ]; then
5
- echo "Usage: $0 <version> [paths...] [--push]"
6
- echo "Example: $0 2.3.4 path/to/dir1 path/to/file2 --push"
5
+ fail() {
6
+ printf 'tagger: %s\n' "$*" >&2
7
7
  exit 1
8
- fi
8
+ }
9
9
 
10
- # Extract version number (first argument)
10
+ if (( $# < 2 )); then
11
+ fail 'Usage: tagger.sh <version> --check | <version> [--manifest release-manifest.json] [files...] [--push]'
12
+ fi
11
13
  VERSION=$1
12
14
  shift
15
+ # Branch names replace every non-alphanumeric character with '-'. Allow only versions for
16
+ # which that is reversible: no build metadata ('+') and no '-' inside prerelease
17
+ # identifiers, so 2.4.0-rc.1 and 2.4.0-rc-1 cannot both claim release-2-4-0-rc-1.
18
+ [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z]+(\.[0-9A-Za-z]+)*)?$ ]] \
19
+ || fail "Unsupported version (semver without build metadata or '-' inside prerelease identifiers): $VERSION"
13
20
 
14
- # Initialize variables
15
21
  PUSH=false
16
- PATHS=()
17
-
18
- # Process remaining arguments
19
- while [ $# -gt 0 ]; do
22
+ CHECK=false
23
+ MANIFEST=''
24
+ FILES=()
25
+ while (( $# )); do
20
26
  case "$1" in
21
- --push)
22
- PUSH=true
23
- echo "Push flag enabled: branches will be force-pushed to origin"
24
- ;;
25
- *)
26
- PATHS+=("$1")
27
+ --push) PUSH=true ;;
28
+ --check) CHECK=true ;;
29
+ --manifest)
30
+ (( $# > 1 )) || fail '--manifest requires a path'
31
+ MANIFEST=$2
32
+ shift
27
33
  ;;
34
+ --*) fail "Unknown option: $1" ;;
35
+ *) FILES+=("$1") ;;
28
36
  esac
29
37
  shift
30
38
  done
31
39
 
32
- # Configure branch prefix
33
- PREFIX="release"
34
-
35
- # Convert version to branch name by replacing non-alphanumeric chars with dashes
36
- EXACT_BRANCH_NAME="${PREFIX}-$(echo $VERSION | sed 's/[^[:alnum:]]/-/g')"
37
-
38
- # Check if version is a pure semver without suffixes (like 2.3.4 without -rc1 etc.)
39
- if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
40
- # Extract major, minor, and patch components
41
- MAJOR=$(echo $VERSION | cut -d. -f1)
42
- MINOR=$(echo $VERSION | cut -d. -f2)
43
- PATCH=$(echo $VERSION | cut -d. -f3)
44
-
45
- # Create specialized branch names
46
- PATCH_BRANCH_NAME="${PREFIX}-${MAJOR}-${MINOR}-${PATCH}"
47
- MINOR_BRANCH_NAME="${PREFIX}-${MAJOR}-${MINOR}-x"
48
- MAJOR_BRANCH_NAME="${PREFIX}-${MAJOR}-x"
49
- else
50
- # For versions with suffixes, these specialized branches aren't created
51
- PATCH_BRANCH_NAME=""
52
- MINOR_BRANCH_NAME=""
53
- MAJOR_BRANCH_NAME=""
54
- fi
55
-
56
- # Output extracted parameters
57
- echo "Version: $VERSION"
58
- echo "Exact branch name: $EXACT_BRANCH_NAME"
59
- if [[ -n $PATCH_BRANCH_NAME ]]; then
60
- echo "Patch branch name: $PATCH_BRANCH_NAME"
61
- echo "Minor branch name: $MINOR_BRANCH_NAME"
62
- echo "Major branch name: $MAJOR_BRANCH_NAME"
40
+ NORMALIZED_VERSION=${VERSION//[^[:alnum:]]/-}
41
+ BRANCHES=("release-$NORMALIZED_VERSION")
42
+ if [[ "$VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
43
+ # The exact branch already is the patch branch: create it only once.
44
+ BRANCHES+=("release-${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-x" "release-${BASH_REMATCH[1]}-x")
63
45
  fi
64
- echo "Push flag: $PUSH"
65
- echo "Number of paths: ${#PATHS[@]}"
66
- if [ ${#PATHS[@]} -gt 0 ]; then
67
- echo "Paths:"
68
- for path in "${PATHS[@]}"; do
69
- echo " - $path"
70
- done
46
+ REFS=()
47
+ for branch in "${BRANCHES[@]}"; do
48
+ git check-ref-format "refs/heads/$branch"
49
+ REFS+=("refs/heads/$branch")
50
+ done
51
+ # Exact-version branches are write-once (also enforced by a repository ruleset).
52
+ # Aliases such as release-2-x move to the newest release.
53
+ EXACT_REF=${REFS[0]}
54
+
55
+ if [[ "$CHECK" == true ]]; then
56
+ # Pre-publish check (semantic-release verifyRelease, before npm and GitHub publish):
57
+ # fail early if this version's exact branch already exists on the remote.
58
+ (( ${#FILES[@]} == 0 )) && [[ "$PUSH" == false && -z "$MANIFEST" ]] \
59
+ || fail '--check takes no files, --manifest or --push'
60
+ set +e
61
+ git ls-remote --exit-code --heads origin "$EXACT_REF" > /dev/null
62
+ status=$?
63
+ set -e
64
+ case "$status" in
65
+ 0) fail "Exact release branch already exists and is write-once: $EXACT_REF" ;;
66
+ 2) printf 'Release %s can be published: %s is available\n' "$VERSION" "$EXACT_REF"; exit 0 ;;
67
+ *) fail "Cannot check $EXACT_REF on origin (git ls-remote exit $status)" ;;
68
+ esac
71
69
  fi
72
70
 
73
- # Store the current branch name
74
- CURRENT_BRANCH=$(git branch --show-current)
71
+ if [[ -n "$MANIFEST" ]]; then
72
+ # The manifest lists every built executable file. Verify it against the files on disk
73
+ # and this version, then publish exactly those files plus the manifest itself.
74
+ MANIFEST_TOOL="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/release-manifest.mjs"
75
+ node "$MANIFEST_TOOL" verify "$MANIFEST" "$VERSION" || fail "Release manifest verification failed: $MANIFEST"
76
+ MANIFEST_FILES=$(node "$MANIFEST_TOOL" files "$MANIFEST") || fail "Cannot read $MANIFEST"
77
+ while IFS= read -r file; do
78
+ if [[ -n "$file" ]]; then
79
+ FILES+=("$file")
80
+ fi
81
+ done <<< "$MANIFEST_FILES"
82
+ FILES+=("$MANIFEST")
83
+ fi
84
+ (( ${#FILES[@]} > 0 )) || fail 'At least one release file is required'
75
85
 
76
- # Create a temporary directory only if we have files to copy
77
- if [ ${#PATHS[@]} -gt 0 ]; then
78
- # Create a temporary directory to store copies of the files
79
- TEMP_DIR=$(mktemp -d)
80
- echo "Creating temporary copies of files at $TEMP_DIR"
86
+ ROOT=$(git rev-parse --show-toplevel)
87
+ [[ "$PWD" -ef "$ROOT" ]] || fail 'Run from the repository root; files must be repository-relative'
88
+ SOURCE_COMMIT=$(git rev-parse 'HEAD^{commit}')
81
89
 
82
- # Copy all specified files to the temporary directory
83
- for path in "${PATHS[@]}"; do
84
- # Create directory structure in temp dir
85
- mkdir -p "$TEMP_DIR/$(dirname "$path")"
86
- # Copy the file
87
- cp "$path" "$TEMP_DIR/$path"
88
- echo "Copied $path to $TEMP_DIR/$path"
90
+ # Validate every input before changing any ref. Do not follow artifact symlinks.
91
+ for file in "${FILES[@]}"; do
92
+ case "$file" in
93
+ /*|..|../*|*/../*|*/..|.git|.git/*) fail "Unsafe release path: $file" ;;
94
+ esac
95
+ [[ -f "$file" && ! -L "$file" ]] || fail "Missing or non-regular release file: $file"
96
+ parent=$(dirname "$file")
97
+ while [[ "$parent" != '.' ]]; do
98
+ [[ ! -L "$parent" ]] || fail "Symlinked release directory: $parent"
99
+ parent=$(dirname "$parent")
89
100
  done
90
- fi
101
+ done
91
102
 
92
- # Create commit message
93
- COMMIT_MSG="Update for version $VERSION"
94
103
 
95
- # Function to create or update a branch and commit changes
96
- create_or_update_branch() {
97
- local branch_name=$1
98
-
99
- echo "Processing branch: $branch_name"
100
-
101
- # Check if branch exists
102
- if git show-ref --verify --quiet refs/heads/$branch_name; then
103
- # Branch exists, reset it from main
104
- echo "Branch $branch_name exists, resetting from main..."
105
- git checkout main
106
- git branch -D $branch_name
107
- git checkout -b $branch_name
108
- else
109
- # Create new branch from main
110
- echo "Creating new branch $branch_name from main..."
111
- git checkout main
112
- git checkout -b $branch_name
113
- fi
114
-
115
- # Copy files from temp directory back to working directory if we have any
116
- if [ ${#PATHS[@]} -gt 0 ]; then
117
- for path in "${PATHS[@]}"; do
118
- # Create directory structure if needed
119
- mkdir -p "$(dirname "$path")"
120
- # Copy the file back from temp
121
- cp "$TEMP_DIR/$path" "$path"
122
- echo "Restored $path from $TEMP_DIR/$path"
123
- done
124
-
125
- # Add files to git, even if they're in .gitignore
126
- echo "Adding files to git staging area in branch $branch_name..."
127
- for path in "${PATHS[@]}"; do
128
- git add --force "$path"
129
- done
130
-
131
- # Commit changes
132
- git commit --no-verify --allow-empty -m "$COMMIT_MSG"
133
- else
134
- # Create an empty commit when no files are specified
135
- git commit --no-verify --allow-empty -m "$COMMIT_MSG"
104
+ if [[ "$PUSH" == false ]]; then
105
+ if git show-ref --verify --quiet "$EXACT_REF"; then
106
+ fail "Exact release branch already exists and is write-once: $EXACT_REF"
136
107
  fi
137
-
138
- # Push if requested
139
- if [ "$PUSH" = true ]; then
140
- echo "Force-pushing branch $branch_name to origin..."
141
- git push -f origin $branch_name
142
- echo "Successfully pushed $branch_name to origin."
143
- fi
144
- }
145
-
146
- # Process each branch
147
- echo "Creating/updating branches and committing changes..."
148
-
149
- # Always process the exact branch
150
- create_or_update_branch $EXACT_BRANCH_NAME
151
-
152
- # Process other branches if they exist
153
- if [[ -n $PATCH_BRANCH_NAME ]]; then
154
- create_or_update_branch $PATCH_BRANCH_NAME
155
- create_or_update_branch $MINOR_BRANCH_NAME
156
- create_or_update_branch $MAJOR_BRANCH_NAME
157
- fi
158
-
159
- # Clean up temporary directory if it was created
160
- if [ ${#PATHS[@]} -gt 0 ]; then
161
- echo "Cleaning up temporary files..."
162
- rm -rf "$TEMP_DIR"
108
+ # update-ref must not move a branch checked out in this or another worktree.
109
+ WORKTREES=$(git worktree list --porcelain)
110
+ for ref in "${REFS[@]}"; do
111
+ if grep -Fxq "branch $ref" <<< "$WORKTREES"; then
112
+ fail "Refusing to update a checked-out release branch: $ref"
113
+ fi
114
+ done
163
115
  fi
164
116
 
165
- # Return to the original branch
166
- echo "Returning to original branch: $CURRENT_BRANCH"
167
- git checkout $CURRENT_BRANCH
168
-
169
- if [ "$PUSH" = true ]; then
170
- echo "All branches have been force-pushed to origin."
117
+ TEMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}/rum-release.XXXXXX")
118
+ trap 'rm -rf "$TEMP_DIR"' EXIT
119
+
120
+ # semantic-release may have changed package.json/CHANGELOG.md in the working tree.
121
+ # Include only explicitly selected files; never borrow the caller's real index.
122
+ TREE=$(
123
+ export GIT_INDEX_FILE="$TEMP_DIR/index"
124
+ git read-tree "$SOURCE_COMMIT"
125
+ git --literal-pathspecs add --force -- "${FILES[@]}"
126
+ git write-tree
127
+ )
128
+ COMMIT=$(printf 'Release artifacts for version %s\n' "$VERSION" | \
129
+ git -c user.name='github-actions[bot]' \
130
+ -c user.email='41898282+github-actions[bot]@users.noreply.github.com' \
131
+ commit-tree "$TREE" -p "$SOURCE_COMMIT")
132
+
133
+ if [[ "$PUSH" == true ]]; then
134
+ # Snapshot remote refs and use explicit leases, including non-existence for new refs.
135
+ # GitHub supports atomic pushes: reject the whole release if any ref has changed.
136
+ REMOTE_STATE=$(git ls-remote --heads origin "${REFS[@]}")
137
+ LEASES=()
138
+ REFSPECS=()
139
+ for ref in "${REFS[@]}"; do
140
+ expected=''
141
+ while IFS=$'\t' read -r oid name; do
142
+ if [[ "$name" == "$ref" ]]; then
143
+ expected=$oid
144
+ fi
145
+ done <<< "$REMOTE_STATE"
146
+ if [[ "$ref" == "$EXACT_REF" && -n "$expected" ]]; then
147
+ fail "Exact release branch already exists and is write-once: $EXACT_REF"
148
+ fi
149
+ LEASES+=("--force-with-lease=$ref:$expected")
150
+ REFSPECS+=("$COMMIT:$ref")
151
+ done
152
+ git push --atomic "${LEASES[@]}" origin "${REFSPECS[@]}"
153
+ else
154
+ # Local inspection mode; still leave HEAD, source branches, index and files alone.
155
+ {
156
+ printf 'start\n'
157
+ for ref in "${REFS[@]}"; do
158
+ printf 'update %s %s\n' "$ref" "$COMMIT"
159
+ done
160
+ printf 'prepare\ncommit\n'
161
+ } | git update-ref --stdin
171
162
  fi
172
163
 
173
- echo "Done!"
164
+ printf 'Published artifact commit %s for %s (push=%s)\n' "$COMMIT" "$VERSION" "$PUSH"
165
+ printf ' %s\n' "${REFS[@]}"