From dd3e2ab42514915a5e141058413363837ab8e622 Mon Sep 17 00:00:00 2001 From: Rongxin Liu Date: Wed, 6 Nov 2024 15:13:02 -0500 Subject: [PATCH] use gh cli to force codespace full rebuild --- Dockerfile | 1 + update50.sh | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5cf20ed8..d21d0eb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -139,6 +139,7 @@ RUN apt update && \ xvfb && \ apt clean + # Install GitHub CLI RUN (type -p wget >/dev/null || (sudo apt update && sudo apt-get install wget -y)) \ && sudo mkdir -p -m 755 /etc/apt/keyrings \ diff --git a/update50.sh b/update50.sh index be7841c7..132976ea 100644 --- a/update50.sh +++ b/update50.sh @@ -1,5 +1,16 @@ #!/bin/bash +# Check for gh and install it if not available (temporary) +if ! command -v gh &> /dev/null; then + (type -p wget >/dev/null || (sudo apt update && sudo apt-get install wget -y)) \ + && sudo mkdir -p -m 755 /etc/apt/keyrings \ + && wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \ + && sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ + && sudo apt update \ + && sudo apt install gh -y +fi + # Check for -t flag for develop mode if [ "$1" == "-t" ]; then # Use the specified tag to build the URL @@ -12,7 +23,19 @@ if [ "$1" == "-t" ]; then echo "Could not update codespace with tag $tag. Try again later." exit 1 fi - command50 github.codespaces.rebuildEnvironment + + # Trigger rebuild + if command -v gh &> /dev/null; then + + # Use gh cli to rebuild if available + gh cs rebuild --repo $GITHUB_REPOSITORY --full + echo "Your codespace is now being rebuilt, please keep the browser window open and wait for it to reload.\nDo not perform any actions until the rebuild is complete." + else + + # Fall back to command50 + command50 github.codespaces.rebuildEnvironment + fi + exit 0 fi @@ -46,7 +69,16 @@ if [ "$remote" != "$local" ] || [ "$tag" != "$issue" ] || [ "$1" == "-f" ] || [ echo "$remote" > "/workspaces/$RepositoryName/.devcontainer.json" # Trigger rebuild - command50 github.codespaces.rebuildEnvironment + if command -v gh &> /dev/null; then + + # Use gh cli to rebuild if available + gh cs rebuild --repo $GITHUB_REPOSITORY --full + echo "Your codespace is now being rebuilt, please keep the browser window open and wait for it to reload.\nDo not perform any actions until the rebuild is complete." + else + + # Fall back to command50 + command50 github.codespaces.rebuildEnvironment + fi else echo "Your codespace is already up-to-date!"