Skip to content

Commit 12e54fc

Browse files
committed
Use release tag names instead of commit SHAs for extension updates and specific version installs
- Refactor the update mechanism to pass the release tag name instead of the commit SHA from the extension down to `install.sh` and `install.ps1`, updating the `UpdateInfo` type, `update_extension` function, both install scripts to run `git checkout <tag_name>`, and all associated VS Code commands to supply the tag. ├── .github │ └── workflows │ └── github-release.yml ├── apps │ └── editor │ ├── package.json │ └── src │ ├── commands │ │ ├── check-for-updates-command.ts │ │ └── install-specific-version-command.ts │ ├── extension.ts │ ├── utils │ │ ├── check-for-updates.ts │ │ └── update-extension.ts │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ └── handle-update-extension.ts │ │ └── prompt-view-provider.ts │ ├── frontend │ │ └── Home │ │ └── Home.tsx │ └── types │ └── messages.ts ├── install.ps1 └── install.sh
1 parent 8a310b8 commit 12e54fc

8 files changed

Lines changed: 22 additions & 23 deletions

File tree

‎apps/editor/src/commands/check-for-updates-command.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export const check_for_updates_command = (
1717
)
1818

1919
if (action === t('command.check-for-updates-command.action.update')) {
20-
if (prompt_view_provider.update_info.latest_version_sha) {
20+
if (prompt_view_provider.update_info.latest_version_tag) {
2121
update_extension({
22-
commit_sha: prompt_view_provider.update_info.latest_version_sha
22+
tag_name: prompt_view_provider.update_info.latest_version_tag
2323
})
2424
}
2525
}

‎apps/editor/src/commands/install-specific-version-command.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ export const install_specific_version_command = () => {
113113
label: version,
114114
description,
115115
tag: tag.name,
116-
sha: tag.commit?.sha,
117116
buttons: [
118117
{
119118
iconPath: new vscode.ThemeIcon('globe'),
@@ -126,7 +125,7 @@ export const install_specific_version_command = () => {
126125
})
127126

128127
const quick_pick = vscode.window.createQuickPick<
129-
vscode.QuickPickItem & { tag: string; sha?: string }
128+
vscode.QuickPickItem & { tag: string }
130129
>()
131130
quick_pick.title = t('command.install-specific-version-command.title')
132131
quick_pick.placeholder = t(
@@ -159,9 +158,9 @@ export const install_specific_version_command = () => {
159158

160159
quick_pick.onDidAccept(() => {
161160
const selected = quick_pick.selectedItems[0]
162-
if (selected && selected.sha) {
161+
if (selected && selected.tag) {
163162
quick_pick.hide()
164-
update_extension({ commit_sha: selected.sha })
163+
update_extension({ tag_name: selected.tag })
165164
}
166165
})
167166

‎apps/editor/src/utils/check-for-updates.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const check_for_updates = async (
5656
return {
5757
is_available: true,
5858
latest_version,
59-
latest_version_sha: vscode_tag.commit?.sha,
59+
latest_version_tag: vscode_tag.name,
6060
current_version_age_days: age_days
6161
}
6262
} else {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from 'vscode'
22
import * as os from 'os'
33

4-
export const update_extension = (params: { commit_sha: string }) => {
4+
export const update_extension = (params: { tag_name: string }) => {
55
const terminal = vscode.window.createTerminal('CWC Updater')
66
terminal.show()
77

@@ -10,11 +10,11 @@ export const update_extension = (params: { commit_sha: string }) => {
1010

1111
if (os.platform() === 'win32') {
1212
terminal.sendText(
13-
`powershell -c "& ([scriptblock]::Create((irm https://raw.githubusercontent.com/CodeWebChat/CWC/main/install.ps1))) '${uri_scheme}' '${lang}' '${params.commit_sha}'"`
13+
`powershell -c "& ([scriptblock]::Create((irm https://raw.githubusercontent.com/CodeWebChat/CWC/main/install.ps1))) '${uri_scheme}' '${lang}' '${params.tag_name}'"`
1414
)
1515
} else {
1616
terminal.sendText(
17-
`curl -fsSL https://raw.githubusercontent.com/CodeWebChat/CWC/main/install.sh | bash -s -- "${uri_scheme}" "${lang}" "${params.commit_sha}"`
17+
`curl -fsSL https://raw.githubusercontent.com/CodeWebChat/CWC/main/install.sh | bash -s -- "${uri_scheme}" "${lang}" "${params.tag_name}"`
1818
)
1919
}
2020
}

‎apps/editor/src/views/prompt/backend/message-handlers/handle-update-extension.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { PromptViewProvider } from '../prompt-view-provider'
44
export const handle_update_extension = (
55
prompt_view_provider: PromptViewProvider
66
) => {
7-
if (prompt_view_provider.update_info.latest_version_sha) {
7+
if (prompt_view_provider.update_info.latest_version_tag) {
88
update_extension({
9-
commit_sha: prompt_view_provider.update_info.latest_version_sha
9+
tag_name: prompt_view_provider.update_info.latest_version_tag
1010
})
1111
}
1212
}

‎apps/editor/src/views/prompt/types/messages.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ export interface SaveTasksMessage extends BaseMessage {
458458
export type UpdateInfo = {
459459
is_available: boolean
460460
latest_version?: string
461-
latest_version_sha?: string
461+
latest_version_tag?: string
462462
current_version_age_days?: number
463463
}
464464

‎install.ps1‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ $ErrorActionPreference = "Stop"
22
$ProgressPreference = "SilentlyContinue"
33
$targetScheme = $args[0]
44
$lang = $args[1]
5-
$commitSha = $args[2]
5+
$tagName = $args[2]
66

77
$msg_error="Error:"
88
$msg_git_required="git is required but not installed."
@@ -486,8 +486,8 @@ foreach ($i in $indices) {
486486
$updated = Invoke-Step "$msg_step_cloning..." {
487487
git -C $repoDir fetch origin --quiet *>$null
488488
if ($LASTEXITCODE -ne 0) { throw "Failed to fetch" }
489-
if ($commitSha) {
490-
git -C $repoDir checkout $commitSha --quiet *>$null
489+
if ($tagName) {
490+
git -C $repoDir checkout $tagName --quiet *>$null
491491
if ($LASTEXITCODE -ne 0) { throw "Failed to checkout" }
492492
} else {
493493
git -C $repoDir reset --hard origin/main --quiet *>$null
@@ -505,8 +505,8 @@ foreach ($i in $indices) {
505505
$null = Invoke-Step "$msg_step_cloning..." {
506506
git clone -c core.longpaths=true --quiet https://github.com/CodeWebChat/CWC.git $repoDir *>$null
507507
if ($LASTEXITCODE -ne 0) { throw "Failed to clone" }
508-
if ($commitSha) {
509-
git -C $repoDir checkout $commitSha --quiet *>$null
508+
if ($tagName) {
509+
git -C $repoDir checkout $tagName --quiet *>$null
510510
if ($LASTEXITCODE -ne 0) { throw "Failed to checkout" }
511511
}
512512
} $msg_step_cloning

‎install.sh‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e
33

44
TARGET_SCHEME="$1"
55
LANGUAGE="${2:-en}"
6-
COMMIT_SHA="$3"
6+
TAG_NAME="$3"
77

88
msg_error="Error:"
99
msg_git_required="git is required but not installed."
@@ -489,8 +489,8 @@ chmod 700 "$CWC_DIR" 2>/dev/null || true
489489

490490
update_repo() {
491491
git -C "$REPO_DIR" fetch origin --quiet && \
492-
if [ -n "$COMMIT_SHA" ]; then
493-
git -C "$REPO_DIR" checkout "$COMMIT_SHA" --quiet
492+
if [ -n "$TAG_NAME" ]; then
493+
git -C "$REPO_DIR" checkout "$TAG_NAME" --quiet
494494
else
495495
git -C "$REPO_DIR" reset --hard origin/main --quiet
496496
fi && \
@@ -499,8 +499,8 @@ update_repo() {
499499

500500
clone_repo() {
501501
git clone -c core.longpaths=true --quiet https://github.com/CodeWebChat/CWC.git "$REPO_DIR" && \
502-
if [ -n "$COMMIT_SHA" ]; then
503-
git -C "$REPO_DIR" checkout "$COMMIT_SHA" --quiet
502+
if [ -n "$TAG_NAME" ]; then
503+
git -C "$REPO_DIR" checkout "$TAG_NAME" --quiet
504504
fi
505505
}
506506

0 commit comments

Comments
 (0)