@@ -11,6 +11,8 @@ CHECK_COMMAND=${T3CODE_UPDATE_CHECK_COMMAND:-corepack pnpm exec vp check} |
11 | 11 | TYPECHECK_COMMAND=${T3CODE_UPDATE_TYPECHECK_COMMAND:-corepack pnpm exec vp run typecheck} |
12 | 12 | TEST_COMMAND=${T3CODE_UPDATE_TEST_COMMAND:-corepack pnpm exec vp test --maxWorkers=4} |
13 | 13 | BUILD_COMMAND=${T3CODE_UPDATE_BUILD_COMMAND:-corepack pnpm exec vp run dist:desktop:linux} |
| 14 | +VERSION_COMMAND=${T3CODE_UPDATE_VERSION_COMMAND:-node scripts/update-release-package-versions.ts} |
| 15 | +STABLE_PATCH_COMMIT=${T3CODE_STABLE_PATCH_COMMIT:-a03a0a0a5} |
14 | 16 |
|
15 | 17 | die() { |
16 | 18 | printf 'Fehler: %s\n' "$*" >&2 |
@@ -161,6 +163,121 @@ stage_update() { |
161 | 163 | printf 'Aktivieren mit: %s activate\n' "$0" |
162 | 164 | } |
163 | 165 |
|
| 166 | +latest_stable_tag() { |
| 167 | + git tag --merged upstream/main --list \ |
| 168 | + | awk '/^v[0-9]+\.[0-9]+\.[0-9]+$/' \ |
| 169 | + | sort -V \ |
| 170 | + | tail -n 1 |
| 171 | +} |
| 172 | + |
| 173 | +stage_stable_update() { |
| 174 | + cd -- "$REPO_DIR" |
| 175 | + [[ $(git branch --show-current) == main ]] || die "'stable-stage' muss auf der lokalen main laufen." |
| 176 | + [[ -z $(git status --porcelain=v1) ]] || die "Der Git-Arbeitsbaum ist nicht sauber." |
| 177 | + verify_remotes |
| 178 | + mkdir -p -- "$INSTALL_DIR" |
| 179 | + |
| 180 | + git fetch --prune origin |
| 181 | + git fetch --prune --tags upstream |
| 182 | + |
| 183 | + local stable_tag stable_version patch_commit stored_tag stored_patch stored_candidate |
| 184 | + stable_tag=$(latest_stable_tag) |
| 185 | + [[ -n "$stable_tag" ]] || die "Kein Stable-Release-Tag gefunden." |
| 186 | + stable_version=${stable_tag#v} |
| 187 | + patch_commit=$(git rev-parse --verify "$STABLE_PATCH_COMMIT^{commit}" 2>/dev/null) || \ |
| 188 | + die "Stable-Patch-Commit nicht gefunden: $STABLE_PATCH_COMMIT" |
| 189 | + |
| 190 | + stored_tag=$(read_status_value release_tag 2>/dev/null || true) |
| 191 | + stored_patch=$(read_status_value patch_commit 2>/dev/null || true) |
| 192 | + stored_candidate=$(read_status_value candidate 2>/dev/null || true) |
| 193 | + if [[ "$stored_tag" == "$stable_tag" && "$stored_patch" == "$patch_commit" && -f "$stored_candidate" ]]; then |
| 194 | + local stored_checksum actual_checksum |
| 195 | + stored_checksum=$(read_status_value sha256 2>/dev/null || true) |
| 196 | + actual_checksum=$(sha256sum -- "$stored_candidate" 2>/dev/null | cut -d' ' -f1 || true) |
| 197 | + if [[ -n "$stored_checksum" && "$stored_checksum" == "$actual_checksum" ]]; then |
| 198 | + printf 'Stable bereits aktuell: %s mit Patch %s\n' "$stable_tag" "$patch_commit" |
| 199 | + return 0 |
| 200 | + fi |
| 201 | + fi |
| 202 | + |
| 203 | + local worktree_dir output_dir worktree_active=0 staged_temp="" |
| 204 | + worktree_dir=$(mktemp -d "${TMPDIR:-/tmp}/t3code-stable-source.XXXXXX") |
| 205 | + output_dir=$(mktemp -d "${TMPDIR:-/tmp}/t3code-stable-build.XXXXXX") |
| 206 | + |
| 207 | + cleanup_stable_stage() { |
| 208 | + local exit_code=$? |
| 209 | + trap - EXIT INT TERM |
| 210 | + if [[ $worktree_active -eq 1 ]]; then |
| 211 | + git -C "$REPO_DIR" worktree remove --force "$worktree_dir" >/dev/null 2>&1 || true |
| 212 | + fi |
| 213 | + if [[ -n "$staged_temp" ]]; then |
| 214 | + rm -f -- "$staged_temp" |
| 215 | + fi |
| 216 | + rm -rf -- "$worktree_dir" "$output_dir" |
| 217 | + exit "$exit_code" |
| 218 | + } |
| 219 | + trap cleanup_stable_stage EXIT INT TERM |
| 220 | + |
| 221 | + git worktree add --detach "$worktree_dir" "$stable_tag" |
| 222 | + worktree_active=1 |
| 223 | + git -C "$worktree_dir" cherry-pick "$patch_commit" |
| 224 | + |
| 225 | + if [[ -n "$VERSION_COMMAND" ]]; then |
| 226 | + (cd -- "$worktree_dir" && bash -lc "$VERSION_COMMAND '$stable_version'") |
| 227 | + if [[ -n $(git -C "$worktree_dir" status --porcelain=v1) ]]; then |
| 228 | + git -C "$worktree_dir" add --all |
| 229 | + git -C "$worktree_dir" commit -m "build: align local stable package versions" |
| 230 | + fi |
| 231 | + fi |
| 232 | + |
| 233 | + (cd -- "$worktree_dir" && corepack pnpm install --frozen-lockfile) |
| 234 | + (cd -- "$worktree_dir" && bash -lc "$CHECK_COMMAND") |
| 235 | + (cd -- "$worktree_dir" && bash -lc "$TYPECHECK_COMMAND") |
| 236 | + (cd -- "$worktree_dir" && bash -lc "$TEST_COMMAND") |
| 237 | + (cd -- "$worktree_dir" && env -u GITHUB_REPOSITORY -u T3CODE_DESKTOP_UPDATE_REPOSITORY \ |
| 238 | + T3CODE_DESKTOP_OUTPUT_DIR="$output_dir" bash -lc "$BUILD_COMMAND") |
| 239 | + |
| 240 | + local artifact_count artifact build_commit destination checksum |
| 241 | + artifact_count=$(find "$output_dir" -maxdepth 1 -type f -name '*.AppImage' -printf '.' | wc -c) |
| 242 | + [[ "$artifact_count" -eq 1 ]] || die "Erwartete genau ein AppImage, gefunden: $artifact_count" |
| 243 | + artifact=$(find "$output_dir" -maxdepth 1 -type f -name '*.AppImage' -print -quit) |
| 244 | + build_commit=$(git -C "$worktree_dir" rev-parse HEAD) |
| 245 | + destination="$INSTALL_DIR/T3-Code-stable-local-$stable_version-$(printf '%.12s' "$patch_commit")-x86_64.AppImage" |
| 246 | + staged_temp="$destination.next.$$" |
| 247 | + install -m 0755 -- "$artifact" "$staged_temp" |
| 248 | + checksum=$(sha256sum -- "$staged_temp" | cut -d' ' -f1) |
| 249 | + if [[ -e "$destination" ]]; then |
| 250 | + local existing_checksum |
| 251 | + existing_checksum=$(sha256sum -- "$destination" 2>/dev/null | cut -d' ' -f1) || \ |
| 252 | + die "Bestehender Build ist nicht lesbar: $destination" |
| 253 | + [[ "$existing_checksum" == "$checksum" ]] || \ |
| 254 | + die "Build-Ziel existiert mit abweichendem Inhalt: $destination" |
| 255 | + rm -f -- "$staged_temp" |
| 256 | + else |
| 257 | + mv -T -- "$staged_temp" "$destination" |
| 258 | + fi |
| 259 | + staged_temp="" |
| 260 | + |
| 261 | + local temporary_status="$STATUS_PATH.next.$$" |
| 262 | + { |
| 263 | + printf 'candidate\t%s\n' "$destination" |
| 264 | + printf 'sha256\t%s\n' "$checksum" |
| 265 | + printf 'commit\t%s\n' "$build_commit" |
| 266 | + printf 'release_tag\t%s\n' "$stable_tag" |
| 267 | + printf 'patch_commit\t%s\n' "$patch_commit" |
| 268 | + } > "$temporary_status" |
| 269 | + mv -f -- "$temporary_status" "$STATUS_PATH" |
| 270 | + |
| 271 | + git -C "$REPO_DIR" worktree remove --force "$worktree_dir" |
| 272 | + worktree_active=0 |
| 273 | + trap - EXIT INT TERM |
| 274 | + rm -rf -- "$worktree_dir" "$output_dir" |
| 275 | + |
| 276 | + printf 'Geprüfter Stable-Build bereit: %s\n' "$destination" |
| 277 | + printf 'Launcher unverändert: %s\n' "$LAUNCHER_PATH" |
| 278 | + printf 'Aktivieren mit: %s activate\n' "$0" |
| 279 | +} |
| 280 | + |
164 | 281 | activate_update() { |
165 | 282 | local candidate expected actual current |
166 | 283 | candidate=$(read_status_value candidate) || die "Kein bereitgestellter Build in $STATUS_PATH" |
@@ -176,6 +293,7 @@ activate_update() { |
176 | 293 |
|
177 | 294 | case ${1:-} in |
178 | 295 | stage) stage_update ;; |
| 296 | + stable-stage) stage_stable_update ;; |
179 | 297 | activate) activate_update ;; |
180 | | - *) die "Aufruf: $0 {stage|activate}" ;; |
| 298 | + *) die "Aufruf: $0 {stage|stable-stage|activate}" ;; |
181 | 299 | esac |