Skip to content

Commit

Permalink
Merge pull request #84 from zuoyuanh/1.3
Browse files Browse the repository at this point in the history
Add warning message on auto update being turned off; Pull in latest changes on build script
  • Loading branch information
zuoyuanh authored Oct 22, 2024
2 parents b8c7f35 + ecfe4e1 commit f89a978
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 37 deletions.
10 changes: 8 additions & 2 deletions patched-vscode/extensions/sagemaker-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@
"contributes": {
"configuration": {
"type": "object",
"title": "Sagemaker Extension",
"properties": {}
"title": "SageMaker Extension",
"properties": {
"sagemaker-extension.notification.extensionAutoUpdateDisabled": {
"type": "boolean",
"default": true,
"markdownDescription": "Show notification if extension auto update is disabled"
}
}
},
"commands": [
]
Expand Down
35 changes: 35 additions & 0 deletions patched-vscode/extensions/sagemaker-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as console from "console";


const PARSE_SAGEMAKER_COOKIE_COMMAND = 'sagemaker.parseCookies';
const ENABLE_AUTO_UPDATE_COMMAND = 'workbench.extensions.action.enableAutoUpdate';

function showWarningDialog() {
vscode.commands.executeCommand(PARSE_SAGEMAKER_COOKIE_COMMAND).then(response => {
Expand Down Expand Up @@ -121,6 +122,37 @@ function updateStatusItemWithMetadata(context: vscode.ExtensionContext) {
});
}

// Render warning message regarding auto upgrade disabled
function renderExtensionAutoUpgradeDisabledNotification() {
// Get current extension auto disabled config
const autoUpdateEnabled = vscode.workspace.getConfiguration('extensions').get('autoUpdate');

// Check if customer has choose to disable this notification
const extensionConfig = vscode.workspace.getConfiguration('sagemaker-extension');
const showNotificationEnabled = extensionConfig.get('notification.extensionAutoUpdateDisabled', true);

// Only show notification, if auto update is disabled, and customer hasn't opt-out the notification
if (showNotificationEnabled && autoUpdateEnabled == false) {
const enableAutoUpdate = 'Enable Auto Update Extensions';
const doNotShowAgain = 'Do not show again';
vscode.window.showInformationMessage(
'Extension auto-update is disabled. This can be changed in Code Editor settings.',
enableAutoUpdate,
doNotShowAgain,
).then(response => {
if (response === enableAutoUpdate) {
vscode.commands.executeCommand(ENABLE_AUTO_UPDATE_COMMAND)
} else if (response == doNotShowAgain) {
extensionConfig.update(
'notification.extensionAutoUpdateDisabled',
false,
vscode.ConfigurationTarget.Global
);
}
})
}
}

export function activate(context: vscode.ExtensionContext) {

// TODO: log activation of extension
Expand All @@ -134,4 +166,7 @@ export function activate(context: vscode.ExtensionContext) {
initialize(sagemakerCookie);
updateStatusItemWithMetadata(context);
});

// render warning message regarding auto upgrade disabled
renderExtensionAutoUpgradeDisabledNotification();
}
49 changes: 45 additions & 4 deletions patches/sagemaker-extension.diff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/extension
===================================================================
--- /dev/null
+++ sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/extension.ts
@@ -0,0 +1,137 @@
@@ -0,0 +1,172 @@
+import * as vscode from 'vscode';
+import * as fs from 'fs';
+import { SessionWarning } from "./sessionWarning";
Expand All @@ -22,6 +22,7 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/extension
+
+
+const PARSE_SAGEMAKER_COOKIE_COMMAND = 'sagemaker.parseCookies';
+const ENABLE_AUTO_UPDATE_COMMAND = 'workbench.extensions.action.enableAutoUpdate';
+
+function showWarningDialog() {
+ vscode.commands.executeCommand(PARSE_SAGEMAKER_COOKIE_COMMAND).then(response => {
Expand Down Expand Up @@ -126,6 +127,37 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/extension
+ });
+}
+
+// Render warning message regarding auto upgrade disabled
+function renderExtensionAutoUpgradeDisabledNotification() {
+ // Get current extension auto disabled config
+ const autoUpdateEnabled = vscode.workspace.getConfiguration('extensions').get('autoUpdate');
+
+ // Check if customer has choose to disable this notification
+ const extensionConfig = vscode.workspace.getConfiguration('sagemaker-extension');
+ const showNotificationEnabled = extensionConfig.get('notification.extensionAutoUpdateDisabled', true);
+
+ // Only show notification, if auto update is disabled, and customer hasn't opt-out the notification
+ if (showNotificationEnabled && autoUpdateEnabled == false) {
+ const enableAutoUpdate = 'Enable Auto Update Extensions';
+ const doNotShowAgain = 'Do not show again';
+ vscode.window.showInformationMessage(
+ 'Extension auto-update is disabled. This can be changed in Code Editor settings.',
+ enableAutoUpdate,
+ doNotShowAgain,
+ ).then(response => {
+ if (response === enableAutoUpdate) {
+ vscode.commands.executeCommand(ENABLE_AUTO_UPDATE_COMMAND)
+ } else if (response == doNotShowAgain) {
+ extensionConfig.update(
+ 'notification.extensionAutoUpdateDisabled',
+ false,
+ vscode.ConfigurationTarget.Global
+ );
+ }
+ })
+ }
+}
+
+export function activate(context: vscode.ExtensionContext) {
+
+ // TODO: log activation of extension
Expand All @@ -139,6 +171,9 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/extension
+ initialize(sagemakerCookie);
+ updateStatusItemWithMetadata(context);
+ });
+
+ // render warning message regarding auto upgrade disabled
+ renderExtensionAutoUpgradeDisabledNotification();
+}
Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/sessionWarning.ts
===================================================================
Expand Down Expand Up @@ -211,7 +246,7 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/package.json
===================================================================
--- /dev/null
+++ sagemaker-code-editor/vscode/extensions/sagemaker-extension/package.json
@@ -0,0 +1,46 @@
@@ -0,0 +1,52 @@
+{
+ "name": "sagemaker-extension",
+ "displayName": "Sagemaker Extension",
Expand Down Expand Up @@ -241,8 +276,14 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/package.json
+ "contributes": {
+ "configuration": {
+ "type": "object",
+ "title": "Sagemaker Extension",
+ "properties": {}
+ "title": "SageMaker Extension",
+ "properties": {
+ "sagemaker-extension.notification.extensionAutoUpdateDisabled": {
+ "type": "boolean",
+ "default": true,
+ "markdownDescription": "Show notification if extension auto update is disabled"
+ }
+ }
+ },
+ "commands": [
+ ]
Expand Down
65 changes: 36 additions & 29 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
#!/bin/bash

while getopts "v:" opt; do
case $opt in
v) version="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
exit 1
;;
esac
usage() {
printf """
Usage: $0 [-t <VERSION>] [-v] [-h]
Otions:
-t <VERSION> Create a tarball with the specified version
-v Enable verbose output
-h Show this help message
"""
}

case $OPTARG in
-*) echo "Option $opt needs a valid argument"
exit 1
;;
while getopts "t:hv" opt; do
case $opt in
t) version="$OPTARG"
CREATE_TARBALL=true ;;
v) VERBOSE_ARG="--verbose" ;;
h) usage; exit 0 ;;
:) printf "Error: -${OPTARG} requires an argument.\n" >&2; exit 1 ;;
?) usage; exit 1 ;;
esac
done

if [[ -z $version ]]; then
echo "Please provide version using '-v'";
exit 1
fi

VERSION=$version

# set +e to prevent quilt from exiting when no patches popped
Expand Down Expand Up @@ -48,11 +49,11 @@ git submodule update --init
# Apply patches
printf "\n======== Applying patches ========\n"
{
quilt push -a --leave-rejects --color=auto
quilt push -a --leave-rejects --color=auto
} || {
printf "\nPatching error, review logs!\n"
find ./vscode -name "*.rej"
exit 1
printf "\nPatching error, review logs!\n"
find ./vscode -name "*.rej"
exit 1
}


Expand All @@ -68,19 +69,25 @@ cd ${PROJ_ROOT}
printf "\n======== Comment out breaking git config lines in postinstall.js ========\n"
sh ${PROJ_ROOT}/scripts/postinstall.sh

# Build tarball for conda feedstock from vscode dir
printf "\n======== Build Tarball for Conda Feedstock ========\n"
bash ${PROJ_ROOT}/scripts/create_code_editor_tarball.sh -v ${VERSION}
# Delete node_modules to prevent node-gyp build error and reduce tarball size
printf "\n======== Deleting vscode/node_modules ========\n"
find "${PROJ_ROOT}/vscode" -name "node_modules" -type d -prune -exec rm -rf '{}' +

# Create tarball
if [ "$CREATE_TARBALL" = true ]; then
# Build tarball for conda feedstock from vscode dir
printf "\n======== Build Tarball for Conda Feedstock ========\n"
bash ${PROJ_ROOT}/scripts/create_code_editor_tarball.sh -v ${VERSION}
fi

# Copy resources
printf "\n======== Copy resources ========\n"
sh ${PROJ_ROOT}/scripts/copy-resources.sh
${PROJ_ROOT}/scripts/copy-resources.sh

# Delete node_modules to prevent node-gyp build error
printf "\n======== Deleting vscode/node_modules ========\n"
rm -rf "${PROJ_ROOT}/vscode/node_modules"
# Copy patched files to patches-vscode
cp -R vscode/* patched-vscode/

# Build the project
printf "\n======== Building project in ${PROJ_ROOT}/vscode ========\n"
yarn --cwd "${PROJ_ROOT}/vscode" install --pure-lockfile --verbose
yarn --cwd "${PROJ_ROOT}/vscode" install --pure-lockfile ${VERBOSE_ARG}
yarn --cwd "${PROJ_ROOT}/vscode" download-builtin-extensions
16 changes: 14 additions & 2 deletions scripts/postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ if [ ! -f "$POSTINSTALL_JS_PATH" ]; then
exit 1
fi

# Use sed to comment out the specific lines
sed -i '' '/cp\.execSync('"'"'git config .*);/s/^/\/\/ /' "$POSTINSTALL_JS_PATH"
# set +e to prevent script from exiting when not on macOS
set +e

# Check if on macOS
system_profiler SPSoftwareDataType

# Run with different arguments depending on the OS
if [ $? -eq 0 ]; then
# Use sed to comment out the specific lines
sed -i '' '/cp\.execSync('"'"'git config .*);/s/^/\/\/ /' "$POSTINSTALL_JS_PATH"
else
# Use sed to comment out the specific lines
sed -i '/cp\.execSync('"'"'git config .*);/s/^/\/\/ /' "$POSTINSTALL_JS_PATH"
fi

echo "Specified git config lines have been commented out in $POSTINSTALL_JS_PATH."

0 comments on commit f89a978

Please sign in to comment.